0

**私はn " N」 '` n' のPowerShellの改行文字は、私が '`N'` n "は` n" を試した動作していない

BLOCKQUOTE

**

を試してみました
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 

出力
enter image description here

希望する出力
enter image description here

答えて

0

新しい行に `r`nを使ってみてください。新しいラインとキャリッジリターンが必要です。

+0

こんにちはJason これも試しましたが動作しませんでした。ありがとう –

+0

'[System.Environment] :: NewLine'の.NET形式を使ってみましたか? –

+0

この使い方[System.Environment] :: NewLine –

0
"`r`n" 

二重引用符で囲む必要があります。

+0

私もこれを試しましたが運はありません –

0

[System.Environment]::NewLineを使用して、必要な場所に新しい行を追加します。

は、私はcsvファイルは、私は、レコードセットの変換に期待するものです。この

"ServerInfo","Server","logged Users","CPU usage","Memory usage","Total FreeSpace","DiskSpace","Comment" 
"","MECDEVAPP01","","7 %","70,24 %","203,97 GB","278,36 GB","" 
"","MECDEVAPP01","","0 %","70,25 %","203,97 GB","278,36 GB","" 

のようなものである配列

@("MECDEVAPP01","MECDEVAPP01")| % { 
    $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 "C:\Users\asarafian\Downloads\Diskncpu.csv" -nti –Append 

に対して明確にするためにコードをフォーマットして実行されたことを言いました(それはあなたがこれらすべてのパイプで構築しているものです)をcsvに変換します。

私はフォーマットされたテキストをプロダクトしたいと思っていますが、csvを使うことはできません。あるいは、その要素を組み合わせる必要があります。

関連する問題