実行時に資格情報を要求するスクリプトを作成しました。こんなふうになります;
$cred = Get-Credential #Read credentials
$username = $cred.username
$password = $cred.GetNetworkCredential().password
$CurrentDomain = "LDAP://" + ([ADSI] "" ).distinguishedName
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain, $UserName, $Password)
if ($domain.name -eq $null)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.MessageBox]::Show("Authentication failed - please verify your username and password.")
exit
}
else
{
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.MessageBox]::Show("Authentication Success")
$Groups = [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups
->後で間違いを認識しました。最後の行には、Windowsマシンにログインしているユーザーのグループが収集されています。スクリプトを介して認証されたユーザーのグループが必要です。これを変更して、Windows認証を使用している人ではなくスクリプトに認証した人のグループを取得するにはどうすればよいですか?
ご不明な点やご不明な点がございましたら、お気軽にお問い合わせください。