0

** 내가 n " N' ''n '을파워 쉘 줄 바꿈 문자는 내가 ''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 

출력
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을 사용하면 필요한 곳 ​​어디에서나 새로운 행을 추가 할 수 있습니다.

내가 명확성을 위해 코드를 포맷 및 배열에 대해 실행했다 가졌

@("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 파일 내가 레코드의 전환에서 기대하는 것이 무엇 인이

"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","" 

같다 (당신이 모든 파이프와 함께 건설하고있는 것입니다)을 CSV로 변환합니다.

형식화 된 텍스트를 제품화하려면 csv를 사용할 수 없거나 그 요소를 결합해야합니다.