ADScripts/UpdateGroupbyCSV.ps1

22 lines
580 B
PowerShell
Raw Normal View History

2023-09-14 11:13:58 -06:00
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.