I am trying to write a script that will execute a batch file on a remote Windows server.
This line below is basically what I'm trying to do and it works without error, however I would like to use a variable for the path\filename of the batch file.
--------------------------------------------------------------------------------------------------------------------------------
invoke-command -computername QSC-A-ICE01 -scriptblock {Start-Process "\\qsc-a-ice01\D$\Test\RunThis.bat" }
---------------------------------------------------------------------------------------------------------------------------------
If I try to use a variable as in this example below I receive the error below. The error seems to indicate it's it expecting a "FilePath" parameter. Is this true? How would I change this script to make it work when substituting a variable.
-----------------------------------------------------------------------------------------------------------
$MyProcess = "\\qsc-a-ice01\D$\Test\RunThis.bat"
Write-Host $MyProcess
invoke-command -computername QSC-A-ICE01 -scriptblock {Start-Process "$MyProcess"}
----------------------------------------------------------------------------------------------------------
This is the error text I receive when using a variable:
PS C:\Windows\system32> D:\Test\ThisWorks.ps1
\\qsc-a-ice01\D$\Test\RunThis.bat
Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Supply an argument that is not null or
empty and then try the command again.
+ CategoryInfo : InvalidData: (:) [Start-Process], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand
+ PSComputerName : QSC-A-ICE01
PS C:\Windows\system32>