Powershell script for warming up of urls after authentication using base64authentication

Swathi Reddy 186 Reputation points
2021-10-05T17:48:01.463+00:00

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).

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,179 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,449 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,506 Reputation points
    2021-10-07T17:36:19.983+00:00

    Hello @Swathi Reddy

    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--