나는/추가의 목록을 레지스트리에서 프로그램을 제거하기 위해 PowerShell을 사용하여 다음 코드를 실행 :PowerShell에서 명령 출력에 줄 바꿈을 어떻게 추가합니까?
Get-ChildItem -path hklm:\software\microsoft\windows\currentversion\uninstall `
| ForEach-Object -Process { Write-Output $_.GetValue("DisplayName") } `
| Out-File addrem.txt
내가 목록은 각 프로그램마다 줄 바꿈으로 구분하고 싶다. 내가 시도 :
Get-ChildItem -path hklm:\software\microsoft\windows\currentversion\uninstall `
| ForEach-Object -Process { Write-Output $_.GetValue("DisplayName") `n } `
| out-file test.txt
Get-ChildItem -path hklm:\software\microsoft\windows\currentversion\uninstall `
| ForEach-Object {$_.GetValue("DisplayName") } `
| Write-Host -Separator `n
Get-ChildItem -path hklm:\software\microsoft\windows\currentversion\uninstall `
| ForEach-Object -Process { $_.GetValue("DisplayName") } `
| foreach($_) { echo $_ `n }
그러나 콘솔에 출력 할 때 이상한 형식이되고 파일에 출력 할 때 각 줄 다음에 3 개의 정사각형 문자가 표시됩니다. 나는 Format-List
, Format-Table
및 Format-Wide
을 사용해 보았습니다. 원래 이런 식으로 생각했습니다 :
Get-ChildItem -path hklm:\software\microsoft\windows\currentversion\uninstall `
| ForEach-Object -Process { "$_.GetValue("DisplayName") `n" }
그러나 그것은 단지 저에게 오류를 줬습니다.
PS> $nl = [Environment]::NewLine
PS> gci hklm:\software\microsoft\windows\currentversion\uninstall |
ForEach { $_.GetValue("DisplayName") } | Where {$_} | Sort |
Foreach {"$_$nl"} | Out-File addrem.txt -Enc ascii
그것은 내 addrem.txt 파일에 다음 텍스트 산출 :
Adobe AIR
Adobe Flash Player 10 ActiveX
...
참고 :
이것은 실제로 효과가있었습니다. 그러나 다른 값, 즉 $ _. GetValue ('InstallDate')가 추가되면 엉망입니다. 도움을 주셔서 감사하지만 원래 질문을 수행합니다. – mike
제가 생각하기에 아마도 다음과 같은 대체 답변을 추가했습니다. – Jaykul
훌륭한 작품입니다. '와 '를 사용하지 않도록주의하십시오. 내 키보드 (US-English Qwerty 레이아웃)에서 1의 왼쪽에 있습니다. –