我試圖在PowerShell腳本中使用憑據連接。我想:憑據連接不起作用
$credential = Get-Credential
和
$credential = $host.ui.PromptForCredential("Need credentials", "Please enter your user name and password.", "", "Domain")
但是,當我執行查詢時,我得到以下信息:
Invoke-SqlQuery -Query $Query -Server $SERVER -database $DataBase -credential $credential
Exception calling "Open" with "0" argument(s): "Login failed for user '\sa'."
\Modules\InvokeSqlQuery\InvokeSqlQuery.psm1:155 char:14
+ $cnn.Open <<<<();
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
即使我用正確的憑據,它失敗。有沒有人有同樣的問題? 調用,調用類SqlQuery
$cnn = New-SqlConnection $Server $Database $Credential $ConnectionTimeout
其產生的誤差。
順便說一句,我想知道如何加載該組件:
new-object [System.Management.Automation.PSCredential]
New-Object : Cannot find type [[System.Management.Automation.PSCredential]]: make sure the assembly containing this type is loaded.
感謝。
一個絕妙的技巧,看看集加載是什麼'[應用程序域] :: CurrentDomain.GetAssemblies()|選擇ManifestModule | Sort ManifestModule' – 2012-03-23 19:36:46
另一招是'[appdomain] :: CurrentDomain.GetAssemblies()|哪裏位置| Foreach {$ _。GetExportedTypes()} |名稱 - 匹配PSCredential |格式 - 表名稱,程序集-AutoSize' – 2012-03-23 20:41:25
確實,非常好:-) – 2012-03-23 21:00:32