## p4get-server ## aaron bockelie <# .SYNOPSIS Checks the status of the currently logged in server, and returns the state. .DESCRIPTION p4get-server issues a p4 ping command against the current logged in Perforce depot. The result is returned in an array with the following characteristics: Port: TCP port that the Perforce server is responding on. server: dns name of the connected Perforce server. pingsuccess: boolean value of the ping test. This value can return false if a stray p4 logout command is issued, or an auth ticket expires. validationdate: the time at which the last validation check was performed. .EXAMPLE This example is the default operation, returning a powershell object with the status information. [PS] p4get-server port server pingsuccess validationdate ---- ------ ----------- -------------- 1673 infosys True 12/10/2010 3:57:38 PM .FUNCTIONALITY Call this function when you are going to issue other p4functions as an environment check. #> Function p4get-server {param() $result = @() #intialize result array. (errors, info, etc) $date = get-date $info = $null $info = p4get info #try to ping the server if ($env:p4logincall -eq $true) { if ($info) #if the ping does not match messages (a successful ping) send error, otherwise complete. { $serverstatus = @{"server" = $env:p4server;"port" = $env:perforceport;"pingsuccess" = $true;"validationdate" = $date} } else { $serverstatus = @{"server" = $env:p4server;"port" = $env:perforceport;"pingsuccess" = $false;"validationdate" = $date} $message = "Perforce server `'" + $env:p4server + "`' did not respond to a connection packet. Try re-authenticating." $recaction = "Try re-authenticating with Perforce server." write-error -message $message -RecommendedAction $recaction -category ResourceUnavailable } } else { $message = "Login method not correct." $recaction = "You must log in with the Powershell command `'p4login`'" write-error -message $message -RecommendedAction $recaction -category InvalidOperation $serverstatus = @{"server" = $env:p4server;"port" = $env:perforceport;"pingsuccess" = $false;"validationdate" = $date} } return new-object psobject -property $serverstatus } #end p4get-server