Powershell 调用命令的语法是否正确?
我正在尝试运行此代码,但它在作为脚本运行时不起作用 当我在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
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仍不运行。