# get-mxrecord # # get a domain as parameter or a list of domains via pipeline to quest MX-Record # uses NSLOOKUP to get data ans parse the STDOUT. # Results are sent to the pipeline # # 20121023 FC Initial Version param( [Parameter( Position=0, Mandatory=$true,HelpMessage="Specify Domain",ValueFromPipeline=$true)][string]$domain, [string]$dnsserver ) begin { Write-Host 'get-mxrecord: ============== started ============== ' $resultlist = @() } process { Write-Host "get-mxrecord: ------ Processing Data --------" Write-Host "Start NSLOOKUP für Domain $domain optional DNSServer:$dnsserver" $result =( nslookup.exe -q=MX $domain $dnsserver) [Boolean]$msfound = $false foreach ($line in $result) { Write-Host " parsing line$line" if ($line -match ".*MX\spreference\s=\s(\d*),\smail\sexchanger\s=\s(.*)") { write-host "Found MX-Record Prio:"$matches[1]" Host:"$Matches[2] $msfound = $true # send result to pipeline Write-Host " Adding Result to resultlist" $resultlist += New-Object PSObject -Property @{ domain = $domain prio = $matches[1] host = $matches[2] } } } if (!$msfound ) { $resultlist += New-Object PSObject -Property @{ domain = $domain prio = "" host = "--not found --" } } } end { Write-Host " Sending results to output" $resultlist Write-Host "get-mxrecord: ============== ended ============== " }