function p4maintain-clients {param([switch]$doCleanUp,[switch]$force) $taskConfig = $null $clientsToRemove = $null $taskConfig = p4get-maintenanceTasks if (!$taskConfig) { throw "No task configuration found for this task" } $now = get-date write-progress -id 5 -activity ("Perforce Clientspec maintenance script.") -status ("Retrieving clientspecs from server.") $tombstonedClients = p4get-client | ?{$_.access -le $now.adddays(-$taskConfig.clientSpecTombstoneDays)} | %{$_.client} $untouchableClients = (p4get-maintenanceTasks).immortalClientSpecs.client if ($tombstonedClients) { $clientsToRemove = compare-object $tombstonedClients $untouchableClients | %{$_.inputobject} | ?{$_ -ne ""} } if ($clientsToRemove) { if ($doCleanUp) { $i=0 foreach ($client in $clientsToRemove) { if ($client) { try { write-progress -id 5 -activity ("Removing clients older than " + $taskConfig.clientSpecTombstoneDays.tostring() + " days.") -status ("Removing client " + $client) -percentcomplete ($i/$clientsToRemove.count*100) $i++ if ($force) { p4remove-client $client -unshelve -revert } else { p4remove-client } } catch { if ($error[0].Exception.Message -match "because it has open files") { write-warning ("Clientspec " + $client + " has open files. Not reverting because -force was not specified.") } } } } } else { $clientsToRemove ColorConsole -FGColor yellow -message ($clientsToRemove.count.tostring() + " clients are older than " + $taskConfig.clientSpecTombstoneDays.tostring() + " days old.`r`nInvoke with -doCleanUp to remove clientspecs.`r`nAddionally, invoke -force to revert clients and delete shelves.") } } else { ColorConsole -FGColor yellow -message ("No clients with an access date older than " + $taskConfig.clientSpecTombstoneDays.tostring() + " were found to remove.") } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 8410 | Aaron Bockelie |
Root checkin, Perforce Powershell wrapper. Still lots of work to be done, namely documentation and deployment tools, for instance, get-help needs work on the majority of these tools. Additionally, the /lib structure needs a little bit of condensation, probably into major groups (depot, userspec, clientspec, group management, and so on) that way function family can exist under each resource. |