## p4get-user ## aaron bockelie <# .SYNOPSIS Returns user objects for all or a specific user in the depot. .DESCRIPTION Function returns an object or multiple objects for each user in the depot. If a specific user is not in the depot, a user object similar to a perforce user object will be returned, as long as a match is found in AD. This object is marked specially. .EXAMPLE This example returns all user objects in the depot: [PS] p4get-user FullName : Bockelie, Aaron Email : aaron.bockelie@example.com Access : 1292026648 User : aaron.bockelie Update : 1291862517 FullName : Du Pre, Adrian Email : adrian.dupre@example.com Access : 1282837172 User : adrian.dupre Update : 1289874484 .EXAMPLE This example returns only a single user in the depot: [PS] p4get-user aaron.bockelie FullName : Bockelie, Aaron Email : aaron.bockelie@example.com Access : 1292026648 User : aaron.bockelie Update : 1291862517 .EXAMPLE This example returns a single user object that is not in the perforce depot, so a proxy user object is returned. You can determine the difference between a real and proxy object by the parameters update and access, which are set to zero, and the warning. [PS] p4get-user benjamin.lile WARNING: User 'benjamin.lile' not found in Perforce depot 'p4infosys' FullName : Lile, Benjamin Update : 0 User : benjamin.lile Email : ben.lile@example.com Access : 0 .PARAMETER user Optional parameter to return a single user object. If the user does not exist in Active Directory or Perforce, an error is returned. However, if the user is in Active Directory, a proxy object is returned. .FUNCTIONALITY Use this function to return validated user objects from the depot. The term validated objects means an object tied to the current depot authentication trigger. #> Function p4get-user {param($user) $servercheck = p4get-server if ($servercheck.pingsuccess.equals($true)) { function unchunkUser #This is a nested function to unchunk client object from p4get. This function is not available outside of p4get-client. {param($chunkeduser) $userchunks = p4get "user -o `"$chunkeduser`"" #p4get returns properties from a single client as two chunks, due to the way perforce likes to stick random carraige return/linefeeds in the comments section. Thanks perforce! $intermediateprop = @() #create an intermediate array to store our properties that we will comb out from clientchunks. foreach ($chunk in $userchunks) #for each of the two chunks (or more), parse each property in the chunk. (chunk.psobject.properties) { foreach ($property in $chunk.psobject.properties){$intermediateprop += $property} #insert each property into an intermediate table. } $reviewobjects = @() $unchunkeduser = new-object pscustomobject #instantiate a new $client object for return from the base function. foreach ($property in $intermediateprop) #pull out the properties we care about and insert them with add-member into the new object. { if ($property.name -notmatch "Reviews") # skip the view, we will enumerate it in a moment. { add-member -inputobject $unchunkeduser -membertype $property.membertype -name $property.name -value $property.value -force } if ($property.name -match "Reviews") #now handle the line if it is a view. do not add as a member yet, we need to perform additional sorting to it. { $reviewobjects += @{$property.name = $property.value} } } #since the view is randomly sorted, and the numeral (viewxx) is a string not an int, it's hard to match. Let's comb it together into order. $i=-1 #set increment to -1 (we want to start at 0) $review = @() do { foreach ($object in $reviewobjects) { if ($object.keys -eq "Reviews"+$i) { $review += $object.values } } $i++ } while ($i -le $reviewobjects.count) add-member -inputobject $unchunkeduser -membertype NoteProperty -name Reviews -value $review $unchunkeduser } $p4authgroup = "p4" + $servercheck.server if ($user -ne $null) { $p4user = unchunkUser $user if ($p4user.access -eq $null) { $p4user = $null #if we request a user that doesn't exist, perforce (helpfully) tries to make a userspec and returns the object. We don't need that data so discard it. } } if ($user -eq $null) { $p4users = p4get users $usercount = $p4users.count $i=1 foreach ($user in $p4users) { write-progress -id 25 -activity "Attempting to retrieve $usercount userspec objects." -status "Returning object $i of $usercount" -percentcomplete (($i/$usercount)*100) unchunkUser $user.user $i++ } } return $p4user #return the AD object } #end p4get-user }