Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 调用命令的语法是否正确?_Powershell - Fatal编程技术网

Powershell 调用命令的语法是否正确?

Powershell 调用命令的语法是否正确?,powershell,Powershell,我正在尝试运行此代码,但它在作为脚本运行时不起作用 当我在powershell中手动运行这些命令时,它可以正常工作 无法工作的脚本: Invoke-Command -ScriptBlock { Enter-PSSession $Computer; Start-Process cmd -Argument "/c C:\Transfer\SETUP2007.EXE /uninstall ProPlus /config UninstallConfig.xml" } -ComputerName $Com

我正在尝试运行此代码,但它在作为脚本运行时不起作用

当我在powershell中手动运行这些命令时,它可以正常工作

无法工作的脚本:

Invoke-Command -ScriptBlock { Enter-PSSession $Computer; Start-Process cmd -Argument "/c C:\Transfer\SETUP2007.EXE /uninstall ProPlus /config UninstallConfig.xml" } -ComputerName $Computer -AsJob
}
手动键入时,此选项有效:

Enter-PSSession pcX
Start-Process cmd -Argument "/c C:\Transfer\SETUP2007.EXE /uninstall ProPlus /config UninstallConfig.xml"

我可以确认
$computer
返回了正确的名称。

如果在两台计算机上使用相同的用户,则在使用-computername运行时,不需要增加PS会话。这应该起作用:

Invoke-Command -ScriptBlock { Start-Process cmd -Argument "/c C:\Transfer\SETUP2007.EXE /uninstall ProPlus /config UninstallConfig.xml" } -ComputerName $Computer -AsJob
}
获取帮助调用命令-full

要运行一系列共享数据的相关命令,请使用 新建PSSession cmdlet以创建PSSession(持久连接) 在远程计算机上,然后使用的会话参数 调用命令以在PSSession中运行该命令。运行命令 在断开连接的会话中,使用InConnectedSession参数。到 在后台作业中运行命令,使用AsJob参数

例如:

PS C:\>$s = New-PSSession -ComputerName Server02 -Credential Domain01\User01
PS C:\> Invoke-Command -Session $s -ScriptBlock {Get-Culture}

如果在两台计算机上使用相同的用户,则在使用-computername运行时不需要增加PS会话。这应该起作用:

Invoke-Command -ScriptBlock { Start-Process cmd -Argument "/c C:\Transfer\SETUP2007.EXE /uninstall ProPlus /config UninstallConfig.xml" } -ComputerName $Computer -AsJob
}
获取帮助调用命令-full

要运行一系列共享数据的相关命令,请使用 新建PSSession cmdlet以创建PSSession(持久连接) 在远程计算机上,然后使用的会话参数 调用命令以在PSSession中运行该命令。运行命令 在断开连接的会话中,使用InConnectedSession参数。到 在后台作业中运行命令,使用AsJob参数

例如:

PS C:\>$s = New-PSSession -ComputerName Server02 -Credential Domain01\User01
PS C:\> Invoke-Command -Session $s -ScriptBlock {Get-Culture}
设法把它修好了

解决方案是在
启动过程之后添加
-Wait
参数

Invoke-Command -ScriptBlock { Start-Process -Wait cmd -Argument "/c C:\Transfer\SETUP2007 /uninstall ProPlus /config UninstallConfig.xml" } -ComputerName $Computer -AsJob    
设法把它修好了

解决方案是在
启动过程之后添加
-Wait
参数

Invoke-Command -ScriptBlock { Start-Process -Wait cmd -Argument "/c C:\Transfer\SETUP2007 /uninstall ProPlus /config UninstallConfig.xml" } -ComputerName $Computer -AsJob    

尝试此操作后,无法解决问题,因为.exe仍不运行。尝试此操作后,无法解决问题,因为.exe仍不运行。