question

Ashwa avatar image
0 Votes"
Ashwa asked Ashwa commented

Powershell script for warming up of urls after authentication using base64authentication

Hello,

I need to authenticate with the username and password of the root Url and for the remaining urls before warmup is initiated. In the below script , It is not going to the second part of the script. It just closes without being notified anything . Can you please modify the PowerShell script for warming up of urls after authentication using base64authentication ( Azure KeyVault).

windows-server-powershellazure-key-vault
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Which document are you referencing for this?

0 Votes 0 ·
Ashwa avatar image Ashwa MarileeTurscak-MSFT ·

is the ps script is correct?

0 Votes 0 ·

1 Answer

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered Ashwa commented

Hello @Ashwa

See the script below for an example of how to do this correctly:

 $Uris = 'www.microsoft.com'
 $PathTxt = "C:\temp\Uri.txt"
 $PathCsv = "C:\temp\Uri.csv"
 $uriList = @()
 foreach ($uri in $Uris){
     $uriObject = New-Object PSObject
     Try{
         $Response = Invoke-WebRequest -Uri $uri -ErrorAction Stop
         $uriObject | Add-Member -MemberType NoteProperty -Name "URL" -Value $Response.BaseResponse.ResponseUri
         $uriObject | Add-Member -MemberType NoteProperty -Name "Status" -Value $Response.StatusCode
         $uriObject | Add-Member -MemberType NoteProperty -Name "Description" -Value $Response.StatusDescription
         Write-Host $Response.StatusCode $Response.StatusDescription $Response.BaseResponse.ResponseUri -ForegroundColor Green
         $uriList += $uriObject
      
     }
     Catch{
         Write-Host "Unable to reach $uri" -ForegroundColor Red
     }
 }
    
 $uriList | Out-File -FilePath $PathTxt -Append
 $uriList | Export-Csv -Path $PathCsv -NoTypeInformation -Append
    
 ################## Send Report As Email ########################### ###
    
 $username = "user-email-address"
 $password = "password"
 $sstr = ConvertTo-SecureString -string $password -AsPlainText -Force
 $cred = New-Object System.Management.Automation.PSCredential -argumentlist $username, $sstr
 $smtpServer = "smtp.office365.com" #if using Exchange Online, or put down the preferred smtp server address
 $sendTo = "user-email-address"
 $sentFrom = $username
 $messageSubject = "Test message"
    
 $body = $uriList | ConvertTo-Html | Out-String
    
 Send-MailMessage -To $sendTo `
                  -From $sentFrom `
                  -Subject $messageSubject `
                  -Body $body `
                  -BodyAsHtml `
                  -smtpserver $smtpServer `
                  -usessl `
                  -Credential $cred `
                  -Port 587


--If the reply is helpful, please Upvote and Accept as answer--

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, Thank you for your answer. the below script which we have used is just encrypting the credentials to base64authentication and not going to the warmup suburls. Based on the rooturl authentication, it has to pass through the suburls and display the status codes. We have used the below script. Can you help me in modifying the PowerShell script. Attached the text file of the PowerShell script.

138626-warmupscript-basicauth.txt


0 Votes 0 ·