I need some assistance with a PowerShell script in SAM.
The intent of the script is to query a server and get its DNS servers so I can eventually run a report on them.
The script I have cobbled together works but not correctly. It shows status as Unknown.
Here is the current script and results:
# Declare variables
$ThingWeAreCheckingToExist = @(Get-WmiObject -computername $args[0] -credential ${credential} -Namespace root\cimv2 -Query "Select dnsserversearchorder from win32_networkadapterconfiguration" | where {$_.DNSServerSEarchOrder -ne $null} | select -ExpandProperty DNSServerSearchOrder)
if($ThingWeAreCheckingToExist.Length -ge 0){
# this will return true if $ThingWeAreCheckingToExist contains a system (IP)
for($index = 0; $index -lt $ThingWeAreCheckingToExist.length; $index++){
# this will iterate through the different systems found in the array
# generate your output now including $index
Write-Host "Statistic $($index)"
Write-Host "Message $($index): $($ThingWeAreCheckingToExist[$index])"
}
}
# Close out the script
Exit 0;
-------------------------------------
Results:
Output Result:
ND Get Output Failed:Output: ==============================================
Statistic 0
Message 0: 1xx.xx.x.xx
Statistic 1
Message 1: 1xx.xx.x.xx
Statistic 2
Message 2: 1xx.xx.x.xx
Statistic 3
Message 3: 1xx.xx.x.xx
Can anyone get me straightened out?