Testing website in IIS

azure custom script extension powershell iis vm 5 years, 9 months ago
$Url = $args[0] $UseDefaultCredentials = $args[1] $Proxy = $args[2] $TimeOut = $args[3] $PSCred = $args[4] Try { ($WebRequest = [Net.WebRequest]::Create($Url) ) |Out-Null #Use Proxy address if specified If ($Proxy) { #Create Proxy Address for Web Request ($WebRequest.Proxy = New-Object -TypeName Net.WebProxy($Proxy,$True)) | out-null } #Set timeout If ($TimeOut) { #Setting the timeout on web request ($WebRequest.Timeout = $TimeOut)|Out-Null } #Determine if using Default Credentials If ($UseDefaultCredentials) { #Set to True, otherwise remains False ($WebRequest.UseDefaultCredentials = $True)|out-null } #Determine if using Alternate Credentials If ($PSCred) { #Prompt for alternate credentals ($WebRequest.Credential = $PSCred) | out-null } ($response = $WebRequest.GetResponse() )| out-null If ($response.StatusCode -eq 'OK') { Write-output "Given Url is working Fine;;StatusCode:$($response.StatusCode -as [int]);;StatusDescription:$($response.StatusDescription)" Exit 0 } else { write-output "Given Url is not Working correctly;;StatusCode:$($response.StatusCode -as [int]);;StatusDescription:$($response.StatusDescription).$($error[0].exception.Message)" Exit 1 } } catch { Write-Output "Unable to Initiate connection. $($error[0].exception.Message)" Exit 1 }
1116
Posted By