I am trying to run the following Invoke-Command that will run rabbitmq-service.bat on a remote computer with "remove" parameter. The command is executing perfectly with removing the rabbmitmq-service but with the following error "The directory name is invalid."
$Cre = Get-Credential -Message "Enter credentials for $fo1"
$fo1Session = New-PSSession -ComputerName Dedicated-Test1 -Credential $Cre
$action = "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.10\sbin\rabbitmq-service.bat"
$remove = "remove"
PS C:\WINDOWS\system32> Invoke-Command -Session $fo1Session -ScriptBlock {& $using:action $using:remove -verb runAs}
The directory name is invalid.
+ CategoryInfo : NotSpecified: (The directory name is invalid.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : Dedicated-Test1
The filename, directory name, or volume label syntax is incorrect.
C:\Program Files\erl10.2\erts-10.2\bin\erlsrv: Service RabbitMQ removed from system.
You can use this code without $using:
Replace TheComputerName with the remote computer's name.