$user = "testuser" $pass = "testpassword" $baseUrl = "https://test.cloudapp.azure.com" function Get-RootWebStatus($baseUrl) { $KeepLooking = $true # Should we continue to retry? $counter = 1 # How many times we've tried $RetryLimit = 5 # Max number of retries $SleepInterval = 5 # How long to sleep between retries $StartTime = Get-Date # When we started while ($KeepLooking) { write-output "$(Get-Date -format 'g') - Querying $baseUrl to see if available." try { $response = Invoke-WebRequest $baseUrl write-output "$(Get-Date -format 'g') - Web request status: $($Response.Statuscode)" if ($Response.Statuscode -eq 200) { write-output "$(Get-Date -format 'g') - Web site is alive!" $KeepLooking = $false continue } } catch { write-output "$(Get-Date -format 'g') - Error! $($_.Exception.Message)" } - $counter++ | Out-Null if ($counter -gt $RetryLimit) { write-output "$(Get-Date -format 'g') - RetryLimit exceeded. Giving up.." $KeepLooking = $false continue } start-sleep $SleepInterval } write-output "$(Get-Date -format 'g') - Execution time was $((New-TimeSpan -start $StartTime -end (Get-Date)).seconds) seconds" } Get-RootWebStatus $baseUrl # Base Url status is completed, Once it is passed, it should check for the login credentials. $suburl = Get-Content -Raw -Path "C:\pipelinetask\suburl.json" | ConvertFrom-Json # calling the login url from Json file (/sitecore/login) $Loginpage = $baseUrl+$suburl.Login.url $credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $user, $pass Write-Host "Login page Url is $Loginpage" $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass))) $reply = Invoke-RestMethod -Method Get -Uri $Loginpage -Headers @{Authorization = "Basic $base64AuthInfo" } -Credential $credential -ContentType "application/json" $reply