Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerShell中添加行尾字符_Powershell_Character - Fatal编程技术网

在PowerShell中添加行尾字符

在PowerShell中添加行尾字符,powershell,character,Powershell,Character,我正在寻找以下挑战的解决方案: 我在PowerShell中运行以下命令 Import-Module servermanager Get-WindowsFeature | where {$_.Installed -eq "True"} | ft DisplayName, Installed > output.txt 现在我想在每行的末尾添加一个字符。我该怎么做 我想我必须将内容添加到数组中,但我不知道如何完成代码 最后,我必须将内容加载到EventViewer中。如果我直接发送,则事件描述

我正在寻找以下挑战的解决方案:

我在PowerShell中运行以下命令

Import-Module servermanager
Get-WindowsFeature | where {$_.Installed -eq "True"} | ft DisplayName, Installed > output.txt
现在我想在每行的末尾添加一个字符。我该怎么做

我想我必须将内容添加到数组中,但我不知道如何完成代码


最后,我必须将内容加载到EventViewer中。如果我直接发送,则事件描述的格式不好。

听起来好像不是使用
ft>output.txt,而是需要如下内容:

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

但是,它并没有给您一个格式良好的表。

您可以向记录中添加另一个字段,如下所示:

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

这有点超出了您直接要求的范围,但我建议跳过“写入文本文件”阶段,直接传递到目标

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安装的$yourChar
。然后,您可以将对象写入磁盘,或将其发送到其他地方(这就是PowerShell对象的美妙之处!)