## p4loginhash ## aaron bockelie <# .SYNOPSIS Logs user into depot, setting special flags that other functions can use to determine perforce server state. Uses special Perforce authentication hash for user verification. .DESCRIPTION Logs user into a given Perforce depot after supplying required credential information. This script also sets a number of session environment variables, and returns an array object of the login results. In order to create a login hash, issue the perforce command "p4 login -p" after setting up your login environment, or issue the command "p4 tickets" to return a list of tickets you may be able to use. This command is useful when there is a need to store credentials to a user accout with depot access. See http://kb.perforce.com/article/618/avoiding-the-perforce-prompt-for-password-in-windows for more details. .EXAMPLE This will interactively prompt you for every required parameter: [PS] p4login Supply values for the following parameters: server: infosys port: 1673 username: aaron.bockelie passwordhash: C94710C2A4E0FFF6DB68A1F5B96387ED .EXAMPLE p4login -server servername -port port -username user.name -passwordhash C94710C2A4E0FFF6DB68A1F5B96387ED This will immediately log you into the depot with out any prompting. .PARAMETER server Perforce server dns name .PARAMETER port Port that the Perforce server is listening on .PARAMETER username Valid username for depot logon. This user should have super rights in the depot. .PARAMETER passwordhash Password MD5 hash for depot authentication. This is a required parameter. .FUNCTIONALITY This function should be used at the start of any session that will use ANY of the other p4 cmdlets. The following environment variables are also set: p4logincall perforceport p4server p4password You may call these variables from the current session with the $env: function. p4password only stores the MD5 hash that was supplied. For example: $env:p4server Returns the server that the function logged into. #> Function p4loginhash #logs user into perforce depot. Needs $server, $port, $username and password, which is piped to the function. {param([Parameter(Mandatory=$true)]$server,[Parameter(Mandatory=$true)]$port,[Parameter(Mandatory=$true)]$username,[Parameter(Mandatory=$true)]$passwordhash,[bool]$silent) $serverport = $server + ":" + $port #combine server and port into a p4set option that perforce can understand. $env:p4logincall = $true $env:perforceport = $port $env:p4server = $server $env:p4passwd = $passwordhash $env:p4port=$serverport #set the server $env:p4user=$username #set the user #login perforce with hash $cmd = "p4 login -s" $command = iex $cmd if ($command -match "ticket expires in") { $loginstatus = @{"loginsucceed" = $true;"server" = $server;"port" = $port;"user" = $username;"p4passwdhash" = $passwordhash;"p4result" = $command} } else { $loginstatus = @{"loginsucceed" = $false;"server" = $server;"port" = $port;"user" = $username;"p4passwdhash" = $passwordhash;"p4result" = $command} write-error "Perforce login failed." -category OperationTimeout } if (!$silent) { return new-object psobject -property $loginstatus } }# end p4login