## p4remove-client ## aaron bockelie <# .SYNOPSIS Removes a specific client from the depot, given a client name. .DESCRIPTION This function enhances the perforce remove client function by returning an error if the client has open files and a list of the outstanding files. .EXAMPLE Attempting to remove a client with files that are checked out. [PS] p4remove-client abockelie p4remove-client : Cannot delete client 'abockelie' because it has open files. At line:1 char:16 + p4remove-client <<<< abockelie + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,p4remove-client //depot/tools/p4powershell/p4ps1.ps1 .EXAMPLE [PS] p4remove-client abockelie2 A successful deletion will not return any feedback. .PARAMETER clientname The client you wish to delete. #> Function p4remove-client {param([Parameter(Mandatory = $true)]$clientname,[switch]$unshelve,[switch]$revert)#begin function p4remove-object $servercheck = p4get-server if ($servercheck.pingsuccess.equals($true)) { $client = p4get-client $clientname if ($client -ne $null) { $clientopenfiles = p4get "opened -C" $client.client if ($clientopenfiles -eq $null) { $result = p4 client -d -f $client.client 2>&1 foreach ($line in $result) { if ($line.GetType().FullName -eq "System.Management.Automation.ErrorRecord") { if ($line.Exception.Message -match "shelve -df") { if ($unshelve) { write-warning ("Shelved files exist on " + $client.client + ". Deleting shelved files associated with clientspec.") p4remove-clientshelves -client $client.client $result = p4 client -d -f $client.client 2>&1 } else { write-warning ("Client " + $client.client + " has files shelved. Use -unshelve to delete shelved files.") } } } } } else { if ($revert) { try { p4revert-client $client.client p4remove-client $client.client #don't ever add -revert to this command here, or you can make an infinite loop. } catch { write-error $error[0] -erroraction stop } } else { $message = "Cannot delete client `'" + $client.client + "`' because it has open files." write-error $message -erroraction stop #send a stop signal to the calling function, not just write the message. $clientopenfiles | %{$_.depotfile} } } } } }