このクイックスクリプトを使用して、多数のサーバーに関する情報を取得しました。私がWindows 7(ps v2)のホスト上で走ったとき、私はすべて正しい結果を得ました。しかし、Server 2008 r2(ps v2)を実行すると、以下のすべてのクエリに対してSystem.Object []が得られます。他にもたくさんの質問がありますが、これらの問題はすべて解決しています。どうしたの?PowerShellでSystem.Object []出力を取得する
$ArrComputers = "localhost"
$OutputLog = ".\output.csv"
$NotRespondingLog = ".\notresponding.txt"
$ErrorActionPreference = "Stop"
Clear-Host
$data = ForEach ($Computer in $ArrComputers) {
try{
$ipAdd = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .)| select ipaddress
$MacAdd = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .)| Select MacAddress
$DefGateway = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .)| Select DefaultIPGateway
$DNSServ = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .)| Select DNSServerSearchOrder
$CPUname = (Get-WmiObject –class Win32_processor -ComputerName .)| Select name
$processorinfo = (Get-WmiObject –class Win32_processor -ComputerName .)| Select NumberOfCores
$processorinfo2 = (Get-WmiObject –class Win32_processor -ComputerName .)| Select NumberOfLogicalProcessors
$memory = Get-WMIObject -class Win32_PhysicalMemory -ComputerName $Computer |
Measure-Object -Property capacity -Sum |
select @{N="r"; E={[math]::round(($_.Sum/1GB),2)}}
}catch{
$Computer | Out-File -FilePath $NotRespondingLog -Append -Encoding UTF8
continue
}
$props = @{
'IPAddress' = $ipAdd
'MacAddress' = $MacAdd
'DefaultIPGateway'= $DefGateway
'DNSServerSearchOrder' = $DNSServ
'cpuName' = $CPUname
'Cores' = $processorinfo
'logicalcores' = $processorinfo2
' Memory' = $memory
}
New-object -type PSCustomObject -Property $Props
}
$Data | export-csv -notypeinformation $outputlog
私は$小道具に以下の文字列を追加し、それはたIPAddress '=働い|コンピュータが1つの以上のインターフェースを持っている場合、あなたは空得るためである「」-join($ ipadd -ExpandProperty IPアドレスを選択します)文字列。私はここで答えを見つけたhttps://social.technet.microsoft.com/Forums/sharepoint/en-US/55734274-634d-465e-a655-03f7f404f349/systemstring-in-output-of-converttohtml-when-im-expecting -a-regular-string-data?forum = winserverpowershell –