Power Shell调用命令未指定:(目录名称无效。:String)[],RemoteException错误

问题描述 投票:0回答:1

我正在尝试运行以下Invoke-Command,该命令将在远程计算机上使用“ 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.
powershell invoke-command remoteexception
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。

© www.soinside.com 2019 - 2024. All rights reserved.