PowerShell - 验证安全凭证

PowerShell - 验证安全凭证

不确定为什么这不起作用。我见过其他人做同样的事情,但我使用的是安全凭证,不确定这是否与此有关。$domain.name 返回为空

$global:username=read-host "Domain Admin User (domain\username)" 
read-host "Domain Admin Password" -assecurestring | convertfrom-securestring | out-file C:\windows\temp\ap.txt
$global:Password=cat c:\windows\temp\ap.txt | Convertto-SecureString 
$LDAPCON="LDAP://" + (Convert-ToDistinguishedName $domainfqdn)
$domain = New-Object System.DirectoryServices.DirectoryEntry($LDAPCON,$username,$password)
$domain.name
$global:Creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

答案1

您正在向 System.DirectoryServices.DirectoryEntry 发送 SecureString,但后者需要明文密码。此外,您混合使用了 $password 和 $global:Password,您确定使用的是正确的吗?

相关内容