## p4remove-group ## aaron bockelie <# .SYNOPSIS Deletes a group from perforce and active directory. .DESCRIPTION This function assists with deleting a group from the Perforce server and from Active Directory. CAUTION: It will actually DELETE a group in Active Directory. .EXAMPLE This will delete a group. [PS] p4remove-group p4infosys.examplegroup WARNING: Perforce group 'p4infosys.examplegroup' will be removed from the depot and Active Directory. Confirm Continue with this operation? [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): Y During execution, the function will request confirmation of the action. Selecting [H]alt or [S]uspend will prevent the function from making any changes. .PARAMETER group The group you wish to permanently delete. #> Function p4remove-group {param([Parameter(Mandatory = $true)]$group,[switch]$force)#begin function p4remove-object $servercheck = p4get-server if ($servercheck.pingsuccess.equals($true)) { $p4group = p4get-group $group if ($p4group.group -ne $group) #check to make sure the perforce group we returned is what we want. This will probably be empty if it is not what we want. { throw "Error: Perforce group `'" + $group + "`' can not be found in Perforce depot." } else { if (p4get-authgroups | ?{$_.name -eq $group}) #if the group we are working on is considered an authentication group, perform special checking. { $message = "Error: The requested group `'" + $group + "`' cannot be deleted. It is considered an authentication group and must be removed from the parent authentication group." throw $message } else { $message = "Perforce group `'" + $p4group.group + "`' will be removed from the depot and Active Directory." if ($force -eq $true) { write-warning $message } else { write-warning $message -warningaction Inquire } $p4status = p4 group -d $p4group.group if ($p4status -eq ("Group " + $p4group.group + " deleted.")) { if (get-qadobject $p4group.group) { try { remove-qadobject $adgroup -force > $null } catch { throw "An error occured deleting Active Directory group " + $adgroup.samaccountname } } else { $message = "Perforce group `'" + $group + "`' did not have a corresponding Active Directory group." write-warning $message } } else { if ($p4status -match "doesn't exist.") { write-warning ("Perforce reports group `'"+ $group +"`' doesn't exist in depot.") } } } } return $status } }#end function p4remove-group