尝试创建一个Powershell脚本,该脚本使用存储的凭据(Clixml(安装应用程序(.exe(。
使用时一切正常:
Start-Process -FilePath "C:Users$($env:USERNAME)DownloadsSoftwareSoftware.exe" -ArgumentList '/s' -Credential $credentials
但我想要一个更优雅的解决方案:
$startprocessParams = @{
FilePath = "C:Users$($env:USERNAME)DownloadsSoftwareSoftware.exe"
ArgumentList = '/s'
Credential = $credentials
Verb = 'RunAs'
PassThru = $true
Wait = $true
}
$proc = Start-Process @startprocessParams
if ($proc.ExitCode -eq 0) {
'Software installed!'
}
else {
"Fail! Exit code: $($Proc.ExitCode)"
}
这在没有Credential参数的情况下可以完美地工作;输入凭证/UAC";弹出窗口,我想避免。使用凭证参数,我得到这个错误:
Start-Process : Parameter set cannot be resolved using the specified name parameters.
我在这里错过了什么?感谢任何建议和/或指导。
编辑:
我使用以下行导入凭据:
$credentials = Import-Clixml "C:Users$Env:USERNAMEAppDataLocalAppsSOFTWAREcred.xml"
凭据是使用标准创建的:
Get-Credential | Export-Clixml "C:Users$Env:USERNAMEAppDataLocalAppsSOFTWAREcred.xml"
这是应该的。
您需要将凭据设置为PSCredential。看看这个解决方案:
$username = "username"
$password = "password"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process dnscrypt-proxy.exe -WorkingDirectory path_here -Credential ($credentials)
它首先存储在PSCredential中吗?
Start-Process : Parameter set cannot be resolved using the specified name parameters.
错误告诉我们使用的参数集不正确。检查MSDN文档或Get-Help
中的Start-Process
将显示-Credential
不能与-Verb
一起使用。