我有一个PowerShell脚本,该脚本使用SQL Server数据库的用户名和密码创建一个XML文件。
脚本:
Get-Credential –Credential (Get-Credential) |
Export-CliXml "$FileLocation\DatabaseCredentials-$SQLServer.xml"
此脚本有效的文件,但是当我尝试从XML文件读取用户名和密码时,出现以下错误:
Method invocation failed because [System.String] does not contain a method named 'GetNetworkCredential'. At line:18 char:1 + $DatabasePassword = $Credentials.GetNetworkCredential().Password + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
脚本:
$Credentials = Import-CliXml '$FileLocation\DatabaseCredentials-$SQLServer.xml'
$DatabaseUserName = $Credentials.UserName
$DatabasePassword = $Credentials.GetNetworkCredential().Password