我刚刚开始编写 Powershell 脚本来执行重复性任务。我想编写一个脚本,提示输入 AD 组和 AD 用户 ID,然后将该用户添加到安全组。
它是这样开始的:
$SecurityGroup = Read-Host -Prompt 'Input the SecurityGroup name'
$User = Read-Host -Prompt 'Input the userID'
Get-ADGroup '$SecurityGroup' | Add-ADGroupMember -Members '$User'
(GET-ADUSER –Identity '$user' –Properties MemberOf | Select-Object MemberOf).MemberOf
Write-Host 'The user with userID '$user' has been added to the SecurityGroup '$SecurityGroup'