<# .SYNOPSIS Synchronize all groups for a perforce server with Active Directory. #> Function p4sync-allgroups { $servercheck = p4get-server if ($servercheck.pingsuccess.equals($true)) { #this function will force sync all groups in the perforce depot. It collects a list of group names that exist on the perforce and active directory side of the fence. $result = @() #collection of reporting data for the status of syncing all the groups. $groups = New-Object System.Collections.ArrayList #list of all groups potentially available for sync on a server. $uniquegroups = $null $ou = $null #ou that the perforce depot parent auth group is located $container = "p4" + $servercheck.server #build the root container name. There should only be one OU in the entire enterprise named this. if not, sucks to be you. try { $ou = get-qadobject -type 'organizationalUnit' $container } catch { $message = "Cannot find primary auth group for current server" write-error $message } if ($ou) #if the ou is valid, construct an array of all possible groups to sync. { p4get-authgroups | %{[void]$groups.add($_.name)} #add all the authentication groups to the group list. get-qadgroup -searchroot $ou | %{[void]$groups.add($_.name)} #add all the groups from the primary OU for the depot. p4get-group | %{[void]$groups.add($_.group)} #add all the groups from the perforce server. $uniquegroups = $groups | sort | gu #sort the groups uniquely $i=0 foreach ($group in $uniquegroups) { write-progress -id 101 -parentid 100 -activity "Group Sync in Progress" -status "Working on group $group" -percentcomplete (($i/$uniquegroups.count)*100) $result += p4sync-group $group $i++ } write-progress -id 101 -completed -activity "Complete." -status "Complete." } } return $result }