2015-02-05 70 views
0

我是新來的Powershell,我試圖通過電子郵件發送輸出的下面的一段代碼,如果我把它發送到控制檯,它的格式很好,但是當我管道它到電子郵件,檢索到的對象不排隊。在電子郵件排序和格式

$bios = Get-WmiObject Win32_BIOS -ComputerName localhost 
$os = Get-WmiObject `Win32_OperatingSystem -ComputerName localhost 
$Proc = Get-WmiObject Win32_processor -ComputerName localhost | Select-Object -First 1 
$memory = Get-WmiObject Win32_physicalmemory -ComputerName localhost 
$system = Get-WmiObject Win32_ComputerSystem -ComputerName localhost 

$Systeminfo = New-Object PSObject -Property @{ 
'ComputerName' = $proc.SystemName; 
'Manufacturer' = $bios.Manufacturer; 
'Model' = $system.Model; 
'BIOS Version' = $bios.Version; 
'Serial Number' = $bios.SerialNumber; 
'Number of Processors ' = $system.NumberOfProcessors; 
'Processor Name' = $proc.name; 
'Logical Processor' = $system.NumberOfLogicalProcessors; 
'Speed (MHZ)' = $proc.CurrentClockSpeed; 
'RAM (GB)' = $system.TotalPhysicalMemory/1GB -as [int]; 
'Used RAM slots' = $memory.count; 
'OSVersion' = $os.Caption 
} 
$Systeminfo = $Systeminfo | Out-String 

此外,有沒有辦法重新安排它們的出現順序,比如,我想計算機名是第一個數組中,但它出現在中間?

回答

0

如果您有PowerShell的3.0,你可以創建一個使用[ordered]

$Systeminfo = [pscustomobject][ordered] @{ 
'ComputerName' = $proc.SystemName; 
'Manufacturer' = $bios.Manufacturer; 
'Model' = $system.Model; 
'BIOS Version' = $bios.Version; 
'Serial Number' = $bios.SerialNumber; 
'Number of Processors ' = $system.NumberOfProcessors; 
'Processor Name' = $proc.name; 
'Logical Processor' = $system.NumberOfLogicalProcessors; 
'Speed (MHZ)' = $proc.CurrentClockSpeed; 
'RAM (GB)' = $system.TotalPhysicalMemory/1GB -as [int]; 
'Used RAM slots' = $memory.count; 
'OSVersion' = $os.Caption 
} 
這應該輸出的順序屬性定義它們

的對象。否則,您將需要使用select語句來訂購所需的屬性。

$Systeminfo | Select-Object ComputerName,Manufacturer,Model,"BIOS Version","Serial Number","Number of Processors","Processor Name","Logical Processor","Speed (MHZ)","RAM (GB)","Used RAM slots",OSVersion