Script to return Code 200

Hi everyone,

i need a script that return code 200 from site, that i must login with username and password. I write a script the accept credential, but script show me all content of site. For example:

$uri = “
$user = ‘user’
$pass = ‘password’ | ConvertTo-SecureString -AsPlainText -Force

$cred = New-Object Management.Automation.PSCredential ($user, $pass)

Invoke-WebRequest -Uri $uri -Credential $cred

$test = Invoke-WebRequest -Uri $uri -Credential $cred

If ($test.StatusCode-eq 200) {
Write-Host “site is Running”

When i started, the script show me following:

"StatusCode : 200
StatusDescription :
Content : <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN””>
<style type=“text/css”>

  • {
    RawContent : HTTP/1.1 200
    Transfer-Encoding: chunked
    Content-Type: text/html
    Date: Tue, 23 Feb 2021 16:04:03 GMT

Forms : {}
Headers : {[Transfer-Encoding, chunked], [Content-Type, text/html], [Date, Tue, 23 Feb 2021 16:04:03 GMT]}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 9120

site is Running"

The result must be only “site is Running” without any other information.

Thank you.


... when you post code, error messages, sample data or console output format it as code, please.
Here you can read how that works: Guide to Posting Code.
You can go back and edit your existing post. You don't have to create a new one. ; - )
Thanks in advance.
You run the command Invoke-WebRequest twice. Once just as it is and once with a variable assignment. I think the second time should be enough:
$uri = ''
$user = 'user'
$pass = 'password' | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($user, $pass)

$test = Invoke-WebRequest -Uri $uri -Credential $cred
If ($test.StatusCode -eq 200) {
    'site is Running'