I have modified a script I found on the internet and everything works great except getting the DNS Server search order. It outputs to an excel file using the Export-Excel module and under the DNSServerSearchOrder Heading in the spreadsheet it shows System.String. If I run the command from the command prompt it outputs the DNS servers correctly. Below is the code, any help would be appreciated.
#This Script will find the System Info for local and remote computers.
# The output displays Computername,IPAddress,NetworkAdapter,MACAddress,DHCPServer,OS,ServicePack, ComputerModel,Username,Domain,Uptime, TotalMem, FreePhysicalMem, RegisteredUser,NoOfProcessors, ProcessorName,ProcessorType
#create an Empty Array
$array= @()
$computer=Get-Content .\computers.txt
foreach ($server in $computer)
{
$IP=[System.net.dns]::GetHostEntry($server).AddressList | %{$_.IPAddressToString}
$wmi=Get-WmiObject win32_ComputerSystem -ComputerName $server
$obj=New-Object PSObject
$obj |Add-Member -MemberType NoteProperty -Name "ComputerName" $wmi.Name
$obj |Add-Member -MemberType NoteProperty -Name "ComputerModel" $wmi.Model
$obj |Add-Member -MemberType NoteProperty -Name "Username" $wmi.UserName
$obj |Add-Member -MemberType NoteProperty -Name "Domain" $wmi.domain
$obj |Add-Member -MemberType NoteProperty -Name "IPAddress" $IP
$obj |Add-Member -MemberType NoteProperty -Name "NoOfProcessors" $wmi.Numberofprocessors
#$array +=$obj
$wmi=Get-WmiObject win32_Processor -ComputerName $server
$obj |Add-Member -MemberType NoteProperty -Name "ProcessorName" $wmi.Name
$obj |Add-Member -MemberType NoteProperty -Name "ProcessorType" $wmi.Caption
# $array +=$obj
$wmi=Get-WmiObject win32_OperatingSystem -ComputerName $server
$freeMB = [math]::Round(($wmi.FreePhysicalMemory / 1024) , 0)
$totalMB = [math]::Round(($wmi.TotalVisibleMemorySize / 1024) , 0)
$UDays = ((Get-Date) - ($wmi.ConvertToDateTime($wmi.LastBootUpTime))).Days
$UHours = ((Get-Date) - ($wmi.ConvertToDateTime($wmi.LastBootUpTime))).Hours
$UMins = ((Get-Date) - ($wmi.ConvertToDateTime($wmi.LastBootUpTime))).Minutes
$Uptime = "Days " + $UDays + " Hours " + $UHours + " Minutes " + $UMins
$obj |Add-Member -MemberType NoteProperty -Name "OS" $wmi.caption
$obj |Add-Member -MemberType NoteProperty -Name "Uptime" $Uptime
$obj |Add-Member -MemberType NoteProperty -Name "RegisteredUser" $wmi.RegisteredUser
$obj |Add-Member -MemberType NoteProperty -Name "ServicePack" $wmi.csdversion
$obj |Add-Member -MemberType NoteProperty -Name "FreePhysicalMem" $freeMB
$obj |Add-Member -MemberType NoteProperty -Name "TotalMem" $totalMB
# Finding the Network Adapter and MAC Address, DHCP Server
$wmi=Get-WmiObject win32_networkadapterconfiguration -ComputerName $server | where {$_.Ipenabled -Match "True"}
$obj |Add-Member -MemberType NoteProperty -Name "NetworkAdapter" $wmi.description
$obj |Add-Member -MemberType NoteProperty -Name "MACAddress" $wmi.macaddress
$obj |Add-Member -MemberType NoteProperty -Name "DHCPServer" $wmi.DHCPServer
$obj |Add-Member -MemberType NoteProperty -Name "DNSServerSearchOrder" $wmi.DNSServerSearchOrder
$wmi=get-WmiObject win32_logicaldisk -ComputerName $server -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
$obj | Add-Member -MemberType NoteProperty -Name "SystemDiskSize/GB" ($wmi.size /1Gb)
$obj | Add-Member -MemberType NoteProperty -Name "SystemFreeDiskSpace/GB" ($wmi.FreeSpace / 1GB)
$array +=$obj
}
$array | select Computername,Domain,IPAddress,OS,ServicePack,Uptime,ComputerModel,NetworkAdapter,DNSServerSearchOrder,DHCPServer,MACAddress,SystemDiskSize/GB,SystemFreeDiskSpace/GB,TotalMem, FreePhysicalMem, RegisteredUser,Username,NoOfProcessors, ProcessorName,ProcessorType | Export-excel .\systeminfo.xlsx