# Authenticate to VSS REST service $user = Read-Host -Prompt 'User name' $pass = Read-Host -Prompt 'password' -AsSecureString # convert secureString to plain text $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) # $pair = "${user}:${$UnsecurePassword}" $pair = $user + ":" + $UnsecurePassword # Encode the string to the RFC2045-MIME variant of Base64, except not limited to 76 char/line. $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) $base64 = [System.Convert]::ToBase64String($bytes) # Create the Auth value as the method, a space, and then the encoded pair Method Base64String $basicAuthValue = "Basic $base64" # Create the header Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== $headers = @{ Authorization = $basicAuthValue } #Invoke-WebRequest -uri "https://vss-ws.eis.utoronto.ca:8001/auth/request-token" -Headers $headers -method POST # by using the following and calling the script as "$TK = .\auth.ps1, $TK is populed with a PS object containing the token Invoke-RestMethod -uri "https://vss-ws.eis.utoronto.ca:8001/auth/request-token" -Headers $headers -method POST