File path issue - Powershell RRS feed

  • Question

  • I am trying to connect remote machine with invoke command and the file path is same script. The same is working with ps1 and when I am converting to exe and getting below errors.

    //Cannot bind argument to parameter 'FilePath' because it is an empty string.

    $scriptPath = $MyInvocation.MyCommand.Name
    Invoke-Command -ComputerName $hostname -FilePath $scriptPath

    //Wildcard characters are not supported for the FilePath parameter. Specify a path without wildcard characters.
    Parameter name: filePath

    $l = get-location
    $p = $MyInvocation.MyCommand
    Invoke-Command -ComputerName $hostname -FilePath $l\$p

    • Moved by Bill_Stewart Monday, March 12, 2018 9:09 PM Unanswerable drive-by question
    Wednesday, January 31, 2018 5:48 AM

All replies

  • $MyInvocation  only works in script files. Turning a scrip file I nto an EXE moves the script inside the exe and it is no longer a called file.

    You can use the command line to get the path.

    Split-Path ([environment]::CommandLine)


    Wednesday, January 31, 2018 5:56 AM
  • Thanks jrv, it is working but i'm getting error like "The value of the FilePath parameter must be a Windows PowerShell script file. Enter the path to a file with a .ps1 file name extension and try the command again. Parameter name: filePath" 

    So pl let me know how to get the path with script block or any other option..?

    Wednesday, January 31, 2018 6:12 AM
  • The full exe path is:


    There is no script file in an exe so your command will never work.


    Wednesday, January 31, 2018 6:17 AM
  • What would be the alternate to overcome the issue..?
    Wednesday, January 31, 2018 7:03 AM
  • There is no alternate.  You cannot access the script inside of the exe.


    Wednesday, January 31, 2018 7:04 AM