Hi Team,
Can some one share Exchange 2010 OWA form login monitor script. Actually we have a script but that was not working as we expected.
.[string] $postUrl = $url + "auth.owa".
Getting error as 403 forbidden state but even if removed with auth.owa it's throwing Login Failure.
Function SecureStringToString($value)
{
[System.IntPtr] $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($value);
try
{
[System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr);
}
finally
{
[System.Runtime.InteropServices.Marshal]::FreeBSTR($bstr);
}
}
[string] $hostname = "${IP}"
$c = Get-Credential -credential ${CREDENTIAL}
[string] $username = $c.Username
[string] $password = SecureStringToString $c.Password
[string] $url = "https://remotemail.telerx.com/owa"
[string] $postUrl = $url + "auth.owa"
[int] $requestTimeout = 15000
[string] $successLoginText = "New Message"
[System.TimeSpan] $responseTime = New-Object System.TimeSpan
[System.Diagnostics.Stopwatch] $watch = New-Object System.Diagnostics.Stopwatch
$watch.Start()
[System.Net.CookieContainer] $cookieContainerGet = new-object System.Net.CookieContainer
#This command set the static property in .NET that causes the error in HTTPS probes.
#[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[System.Net.HttpWebRequest] $req = [System.Net.WebRequest]::Create($url)
$req.method = "GET"
$req.ContentType = "application/x-www-form-urlencoded"
$req.TimeOut = $requestTimeout
$req.UserAgent = "Mozilla/4.0 (compatible;);"
$req.CookieContainer = $cookieContainerGet
$req.ServicePoint.Expect100Continue = $FALSE;
$req.CachePolicy = new-object System.Net.Cache.HttpRequestCachePolicy([System.Net.Cache.HttpRequestCacheLevel]::NoCacheNoStore);
$req.KeepAlive = $FALSE;
$req.AllowAutoRedirect = $TRUE;
#echo "Connecting to $url"
try
{
[System.Net.HttpWebResponse] $res = $req.GetResponse()
}
catch [System.Exception]
{
[string] $message = [System.String]::Format("Message: Connection failed to url ({0}). {1}", $url, $_.Exception.Message)
echo "Statistic: 1"
echo $message
exit 1;
}
if ($res.StatusCode -ne [System.Net.HttpStatusCode]::OK)
{
[string] $message = [System.String]::Format("Message: Connection failed to url ({0}). Response status code: '{1}'.", $url, $res.StatusCode)
echo "Statistic: 1"
echo $message
exit 1;
}
$stream = $res.GetResponseStream()
$sr = new-object System.IO.StreamReader($stream)
$result = $sr.ReadToEnd()
$stream.Close()
$sr.Close()
$res.Close()
#echo "Got response from $url"
[System.Net.HttpWebRequest] $post = [System.Net.WebRequest]::Create($postUrl)
$post.method = "POST"
$post.ContentType = "application/x-www-form-urlencoded"
$post.TimeOut = $requestTimeout
$post.UserAgent = "Mozilla/4.0 (compatible;);"
$post.ServicePoint.Expect100Continue = $FALSE;
$post.CachePolicy = new-object System.Net.Cache.HttpRequestCachePolicy([System.Net.Cache.HttpRequestCacheLevel]::NoCacheNoStore);
$post.KeepAlive = $FALSE;
$post.AllowAutoRedirect = $TRUE;
[System.Uri] $uri = new-object System.Uri($url)
[System.Net.CookieContainer] $cookieContainerPost = new-object System.Net.CookieContainer
[System.Net.Cookie] $outlookJavascriptCookie = $null
if ($cookieContainerGet.Count -gt 0)
{
[System.Net.Cookie] $outlookSessionCookie = $cookieContainerGet.GetCookies($uri)[0]
$outlookJavascriptCookie = new-object System.Net.Cookie("PBack", "0", $outlookSessionCookie.Path, $outlookSessionCookie.Domain)
} else
{
$outlookJavascriptCookie = new-object System.Net.Cookie("PBack", "0", "/", $hostname)
}
$cookieContainerPost.Add($outlookJavascriptCookie)
$post.CookieContainer = $cookieContainerPost
[string] $postContent = [System.String]::Format("destination={0}&flags=0&forcedownlevel=0&trusted=0&username={1}&password={2}&isUtf8=1", $url, $username, $password)
[System.Text.uTF8Encoding] $encoding = new-object System.Text.uTF8Encoding
$postContentBytes = $encoding.getBytes($postContent)
$post.ContentLength = $postContentBytes.length
$postStream = $post.GetRequestStream()
$postStream.write($postContentBytes, 0, $postContentBytes.length)
$postStream.flush()
$postStream.close()
#echo "Sending POST request to $postUrl"
try
{
[System.Net.HttpWebResponse] $res = $post.GetResponse()
}
catch [System.Exception]
{
[string] $message = [System.String]::Format("Message: Connection failed to url ({0}). {1}", $postUrl, $_.Exception.Message)
echo "Statistic: 1"
echo $message
exit 1
}
if ($res.StatusCode -ne [System.Net.HttpStatusCode]::OK)
{
[string] $message = [System.String]::Format("Message: Connection failed to url ({0}). Response status code: '{1}'.", $url, $res.StatusCode)
echo "Statistic: 1"
echo $message
exit 1
}
$stream = $res.GetResponseStream()
$sr = new-object System.IO.StreamReader($stream)
$result = $sr.ReadToEnd()
$stream.Close()
$sr.Close()
$res.Close()
#echo "Got response from $postUrl"
#echo $result
if ($result.Contains($successLoginText))
{
$watch.Stop;
$responseTime = $watch.Elapsed
[string] $responseTimeStatisticData = [System.String]::Format("Statistic.ResponseTime: {0}", $responseTime.TotalMilliseconds)
[string] $responseTimeStatisticMessage = "Message.ResponseTime: This value shows response time for Form Login script measured in milliseconds"
echo "Statistic: 0"
echo "Message: Login succeeded"
echo $responseTimeStatisticData
echo $responseTimeStatisticMessage
exit 0
}
else
{
echo "Statistic: 1"
echo "Message: Login failed"
exit 1
}