## p4sync-alldepots ## aaron bockelie <# .SYNOPSIS Synchronises all groups and users on all depots defined in the depot xml file. .DESCRIPTION This function will synchronise all the users and groups on all depots defined in the depots.xml file with active directory groups. A status bar will show the progress for the current depot and overall progress. .EXAMPLE This will interactively prompt you for every required parameter: [PS] p4sync-alldepots .EXAMPLE p4sync-alldepots This will commence syncing of all depots as configured in the depots.xml file. .FUNCTIONALITY Use this function to manually trigger a sync of all depots. The function is called by p4sync-service which provides an email and status reporting layer on changes to depot objects. #> function p4sync-alldepots { try { $xml = [xml](gc $env:depotsxml) } catch { write-error "Could not load depot.xml file defined by system environment variable `'depotsxml`'" break } $status = $null $groupsyncresult = @() $usersyncresult = @() $result = $null if ($xml) { "Logging out any previous Perforce sessions." p4logout #logout just in case $i=1 #set counter foreach ($depot in $xml.perforce.depot) { if ((($xml.perforce.depot.count) -eq ($null)) -or (($xml.perforce.depot.count) -eq (0))) #if there is only one depot in the definition file, so we don't divide by zero. { $percentcomplete = 1 } else { $percentcomplete = (($i/$xml.perforce.depot.count)*100) } write-progress -id 100 -activity "Depot Group Sync in Progress" -status ("Working on depot " + $depot.name) -percentcomplete $percentcomplete try { $logresult = p4sudo $depot.name#try logging in with the auth hash. } catch { write-error $error[0] } $groupsyncresult += p4sync-allgroups #syncronize all groups in the depot. $usersyncresult += p4sync-allusers p4logout #log out of depot. $i++ #increment counter } write-progress -id 100 -completed -activity "Complete." -status "Complete." } else { write-error "XML defining depots could not be loaded due to (possibly) multiple failures." break } new-object psobject -property @{"groupsyncresult" = $groupsyncresult;"usersyncresult" = $usersyncresult} }