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 = “http://example.com”
$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”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>test</title>
<style type=“text/css”>
- {
p…
RawContent : HTTP/1.1 200
Transfer-Encoding: chunked
Content-Type: text/html
Date: Tue, 23 Feb 2021 16:04:03 GMT
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”…
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.