【发布时间】:2015-06-17 12:48:16
【问题描述】:
我正在尝试使用 PSCredential 作为参数运行 powershell 调用命令调用。
但是调用失败并出现错误:
Invoke-Command : 无法处理参数的参数转换 '凭据'。用户名”
这是我得到的详细输出:
error 17-Jun-2015 14:33:53 Invoke-Command : Cannot process argument transformation on parameter 'Credential'. userName
error 17-Jun-2015 14:33:53 At C:\Windows\system32\config\systemprofile\AppData\Local\Temp\PRISMA-AMR-JOB1-68-ScriptBuildTask-7900604773745573277.ps1:31 char:71
error 17-Jun-2015 14:33:53 + Invoke-Command "sqlcmd -E -S "$server" -Q `"$query`" " -Credential <<<<
error 17-Jun-2015 14:33:53 ($credential)
error 17-Jun-2015 14:33:53 + CategoryInfo : InvalidData: (:) [Invoke-Command], ParentContain
error 17-Jun-2015 14:33:53 sErrorRecordException
error 17-Jun-2015 14:33:53 + FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.P
error 17-Jun-2015 14:33:53 owerShell.Commands.InvokeCommandCommand
基本上,我只是想通过带有 PSCredential 的 Invoke-Command 调用来模拟运行 sqlcmd。
知道这里发生了什么吗?
编辑: 这是powershell代码:
function GetPSCredential($userId){
$userIdFileNameWoExt = $userId.Replace("\",".")
$password = (Get-Content "somefile.pwd" | ConvertTo-SecureString -Key (Get-Content "somefile.key"))
$psCredential = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList "$userId", $password
return $psCredential
}
function ImpersonateSql ($credential, $server, $query) {
Invoke-Command "sqlcmd -E -S "$server" -Q `"$query`" " -Credential ($credential)
}
...
ImpersonateSql($defaultCredential, $serverInstance, "SOME SQL QUERY HERE")
【问题讨论】:
-
你能粘贴你的实际代码吗?
标签: powershell arguments transformation credentials invoke-command