【发布时间】:2016-01-30 03:04:58
【问题描述】:
我有这个 Powershell:
Try
{
#Start the installer remotely
$process = ([WMICLASS]"\\$comp\ROOT\CIMV2:Win32_Process").Create($InstallString)
if ( $process.ReturnValue -eq 0 )
{
$logstr = $comp + ": spawned process " + $process.ProcessId
Write-Host -ForegroundColor GREEN $logstr
}
else
{
Write-Host -ForegroundColor RED "${comp}: failed to create process ${InstallString}"
Continue
}
}
Catch
{
Write-Host -ForegroundColor RED "${comp}: error: $_.Exception.Message"
Continue
}
其中$comp 是有效的PC 名称,InstallString 是\\SERVERNAME\ShareFolder\setup.exe。
ShareFolder 中包含一个安装程序及其文件。我希望我可以运行这样的设置来远程安装,但它不起作用。它落入了else:
COMPUTERNAME: failed to create process \\SERVERNAME\ShareFolder\setup.exe
我错过了什么?我可以在 Powershell 之外访问此路径。
这适用于本地路径。我需要 Powershell 中的一些特殊语法来指向这个共享吗?
如果 exe(嗯,不同的安装程序)位于 COMPUTERNAME 上并且代码仍然远程执行,则此代码有效。
【问题讨论】:
-
$process.ReturnValue的值是多少? -
@PaulH。 2 作为返回值
-
OK,这就是“拒绝访问”。一定是某个地方的权限问题。我将不得不进一步研究一下。
-
一些可能有帮助的链接:(stackoverflow.com/q/7794206/5199222) (powershellserver.com/accessing-remote-network-resources)。我认为使用
credSSP可能是答案,但我还没有测试过。
标签: powershell