MS exchange mx entry check using powershell

Hi,

There's this website that will be able to check the mx entries of our MS exchange server, and we want to write an exchange management shell script that will be able to emulate in doing so, below is the script;

$ie = New-Object -com InternetExplorer.Application
$ie.navigate("http://mxtoolbox.com/")
$ie.visible = $true
$doc = $ie.document
$tb1 = $doc.getElementByID("ctl00_ContentPlaceHolder1_ucMxActionInput_txtToolInputOldSchool")
$tb1.value = mydomain.com

When executing the .ps1 and ""Run it as Administrator", we get this error;

$tb1 = $doc.getElementByID("ctl00_ContentPlaceHolder1_ucMxActionInput_txtToolInputOldSchool")

You cannot call a method on a null-valued expression.

Server Info: IE 9 / Exchange 2010 / Windows server 2008 R2

July 18th, 2013 5:13am

I think you're trying to get the element too quickly. Try inserting

Start-Sleep -s 10

before the $doc = $ie.document line.  It works here.

Free Windows Admin Tool Kit Click here and download it now
July 18th, 2013 10:07am

Hi Lee,

After adding the script i get this error:

Cannot find an overload for "GetElementById" and the argument count 1.

July 18th, 2013 10:41pm

Hi,

I know directly what you're asking for but you can just perform a nslookup, the following command would return the MX records of Microsoft.com using google's public DNS servers:

"nslookup -querytype=MX Microsoft.com 8.8.8.8"

Free Windows Admin Tool Kit Click here and download it now
July 19th, 2013 3:25am

That seems odd. What does the whole script look like now? This (below) works here. The IE windows pops up correctly navigated, with the input box populated. BTW, as already mentioned, you could just do this with NSLOOKUP.

$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("http://mxtoolbox.com/")
$ie.Visible = $true
Start-Sleep -s 10
$doc = $ie.document
$tb1 = $doc.getElementById("ctl00_ContentPlaceHolder1_ucMxActionInput_txtToolInputOldSchool")
$tb1.Value = "mydomain.com"

July 19th, 2013 5:25am

@Lee, I think it has an issue with IE9.

@Cameron, Thanks buddy yes that's what i'm looking for.

Free Windows Admin Tool Kit Click here and download it now
July 19th, 2013 10:57pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics