1

次の課題の解決策を探しています。

PowerShell で次のコマンドを実行します。

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

次に、各行の最後に文字を追加したいと思います。どうやってやるの?

コンテンツを配列に追加する必要があると思いますが、コードを完成させる方法がわかりません。

最後に、コンテンツを EventViewer にロードする必要があります。直接送信すると、イベントの説明が適切にフォーマットされていません。

4

3 に答える 3

0

あなたが直接尋ねたことの範囲から少し外れていますが、「テキストファイルへの書き込み」段階をスキップして、宛先に直接渡すことをお勧めします。

Import-Module servermanager
$installedFeatures = @()    # Creates a blank array for the features
$output = @()    # Creates a 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"
}

すべての Windows 機能を反復処理すると、$output変数にはdisplayName installed $yourChar. その後、ディスクに書き込むか、オブジェクトを別の場所に送信できます (これが PowerShell オブジェクトの優れた点です!)。

于 2013-10-31T05:44:25.033 に答える