22 lines
580 B
PowerShell
22 lines
580 B
PowerShell
|
if (!($cred)) {
|
||
|
$cred = Get-Credential -Message "Enter your Domain Admin credentials"
|
||
|
}
|
||
|
|
||
|
$CSVMembers = Import-Csv 'C:\users\eeckert\Downloads\GPO Manual.csv'
|
||
|
$GroupName = 'GPO_Radiation Manual'
|
||
|
|
||
|
|
||
|
foreach ($name in $csvmembers) {
|
||
|
$Filter = "Name -eq '" + $name.name +"'"
|
||
|
try {
|
||
|
$ADObject = Get-ADUser -Filter $Filter
|
||
|
Add-ADGroupMember $GroupName -Members $ADObject -Credential $cred
|
||
|
}
|
||
|
catch {
|
||
|
$message = $name.name + ' not found. Add to the group manually'
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# now get current group members, and remove them if not in the list.
|