0

我正在尝试运行以下调用命令,该命令将在远程计算机上使用“remove”参数运行 rabbitmq-service.bat。该命令在删除 rabbmitmq-service 后完美执行,但出现以下错误“目录名称无效。”

$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.
4

1 回答 1

0

您可以在不使用 $using 的情况下使用此代码:

$batch = get-content $action -raw
invoke-command -computername TheRemoteComputer -session $fo1session -scriptblock "& {new-item -path 'C:\Batch.Bat' -type file -value $batch; cmd.exe /c 'C:\Batch.bat $remove'; remove-item 'C:\Batch.bat'}"

将 TheComputerName 替换为远程计算机的名称。

于 2019-12-19T17:08:10.093 回答