2013-10-30 11 views
1

다음 도전 과제에 대한 해결책을 찾고있는 임 :글 머리 기호를 추가하십시오 powershell

나는 powershell에서 다음 명령을 실행합니다.

Import-Module servermanager 
Get-WindowsFeature | where {$_.Installed -eq "True"} | ft DisplayName, Installed > output.txt 

이제 각 행의 끝에 문자를 추가하고 싶습니다. 누군가 나를 도울 수 있습니까? 배열에 내용을 추가해야하지만 코드를 완료하는 방법을 모르는 것 같습니다.

결국 나는 이벤트 뷰어에 내용을로드해야합니다. 지시문을 보내면 이벤트 설명이 잘 포맷되지 않습니다.

foreach { echo ($_.DisplayName + " " + $_.Installed + " extra_stuff") } > output.txt 

비록 당신에게 잘 형식의 테이블을 제공하지 않습니다 :

답변

0

당신이 뭔가를 원하는 대신 ft > output.txt를 사용하는 것 같네요.

2

당신은 다음과 같이 기록에 다른 필드를 추가 할 수 있습니다

Get-WindowsFeature | ? { $_.Installed } | 
    select DisplayName, Installed, @{n='Other',e={'c'}} | ft 
0

그것의 직접 무엇을 요구의 범위에 작은, 그러나 나는 '텍스트 파일에 쓰기'무대와 패스를 건너 뛰는 게 좋을 것 직접 목적지에.

모든 윈도우 기능을 통해 반복하면
Import-Module servermanager 
$installedFeatures = @() #creates a blank array for the features 
$output = @() #creates blank array for formatted results 

$yourChar #the character/ string you want to add at the end of each row 

$installedFeatures = Get-WindowsFeature | Where-Object {$_.Installed -eq "True"} 
foreach($feature in $installedFeatures) 
{ 
    $output += "$($feature.displayName) $($feature.installed) $yourChar" 
} 

, 당신의 $output 변수는 displayName installed $yourChar의 형식으로 문자열 배열을해야합니다. 그런 다음 디스크에 기록하거나 다른 곳에 개체를 보낼 수 있습니다 (PowerShell 개체의 아름다움입니다).

관련 문제