【发布时间】:2016-06-16 19:50:14
【问题描述】:
为什么在我已经为我的$PW 变量输入密码并使用它创建了正确的 PSCredentials 之后,PowerShell 要求我提供凭据以访问远程计算机?我遇到的另一个问题是 Start-Process 找不到指定的 FilePath(Null 或空)。
我猜这两个错误是因为同一个错误,一定是因为我的变量值没有传递给 foreach 循环。如您所见,我试图通过尝试-argumentlist 参数来实现解决方案,但它不起作用。我做错了什么?
function Install-Exe {
param(
[string[]]$ComputerName,
[string]$UNCexepath,
[string[]]$exeargs
)
$Admin = "domain\admin"
$PW = Read-Host "Enter Password" -AsSecureString
$cred = New-Object System.Management.Automation.PSCredential -argumentlist $Admin, $PW
foreach ($c in $ComputerName) {
Invoke-Command -ComputerName $c -Credential $cred -ArgumentList $cred,$UNCexepath {
Start-Process -Filepath $UNCexepath -Credential $cred -Verb RunAs
}
}}
【问题讨论】:
标签: powershell