-
-
Save vexx32/affbbf402f23720e0e4e8eb630003030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Process the groups | |
$OUs | ForEach-Object { | |
# Build the old group name | |
$OldGroup = "DtaG_Student_${_}_1Fa" | |
# Build the new group name | |
$NewGroup = "DtaG_Student_${_}_190901Fa-" | |
try { | |
# Get group members | |
$Members = Get-ADGroupMember $OldGroup | |
# Make sure last year's students aren't still in the old group | |
Remove-ADGroupMember $Oldgroup -Members $Members -whatif | |
# Add the new group to the old group | |
Add-ADGroupMember $OldGroup -Members $NewGroup -whatif | |
} | |
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { | |
$NoGroup += $OldGroup | |
Write-Error "$OldGroup NOT FOUND" | |
# if the old group was one of the TEP groups, change the Old Group format to DtaG_Student_TEP_$OU_1Fa, | |
# then remove existing members, add the new group before looping to the next OU | |
} | |
catch { | |
# Log additional errors, and either rethrow the error or pass it to Write-Error | |
# depending on whether you want execution to terminate or keep going through the | |
# rest of your OUs. | |
# Rethrow (terminate execution) options: | |
# 1. $PSCmdlet.ThrowTerminatingError($_) | |
# 2. throw $_ | |
# 3. $_ | Write-Error -ErrorAction Stop | |
# Otherwise just write-error: | |
# $_ | Write-Error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment