**我尝试了n " n“'`n'



**

GC D:\code\ServerList.txt | % {
$Comp = $_
#write-output "server Information"
If (Test-Connection $Comp -Quiet){
$Luser = (Get-WmiObject -class win32_process -Filter
"Name='Explorer.exe'" -ComputerName $Comp | % {$_.GetOwner().User} |
Sort-Object -Unique) -join ","
$Mem = GWMI -Class win32_operatingsystem -computername $COMP
  New-Object PSObject -Property @{
            "ServerInfo" = ""
            Server = $Comp
            "CPU usage" = "$((GWMI -ComputerName $COMP win32_processor
| Measure-Object -property LoadPercentage -Average).Average) %"
            "Memory usage" = "$("{0:N2}" -f
((($Mem.TotalVisibleMemorySize - $Mem.FreePhysicalMemory)*100)/
$Mem.TotalVisibleMemorySize)) %"
            "Total FreeSpace" = "$("{0:N2}" -f ((Get-WmiObject -Class
win32_logicaldisk -ComputerName $COMP -Filter "DriveType = '3'" |
              Measure-Object -property FreeSpace -Sum).Sum /1GB)) GB"
            "DiskSpace" = "$("{0:N2}" -f ((Get-WmiObject -Class
win32_logicaldisk -ComputerName $COMP -Filter "DriveType = '3'" |
              Measure-Object -property Size -Sum).Sum /1GB)) GB"
        "Comment" =  ""
  "logged Users" = $Luser
  }
}
Else{
"" | Select @{N="Server";E={$Comp}},"CPU usage","Memory usage","Total
FreeSpace","logged Users","DiskSpace"
}
}| Select "ServerInfo",Server,"logged Users","CPU usage","Memory
usage","Total FreeSpace" ,"DiskSpace", "Comment" |
Export-Csv "D:\code\Diskncpu.csv" -nti –Append

输出

期望的输出

最佳答案

"`r`n"

我相信需要用双引号引起来。

08-06 00:14