如何自定义Get-Windowsfeature路径的输出

How to customize the ouput of Get-Windowsfeature path

实际上,我想自定义 Get-Windowsfeature | select path 的输出,但我被卡住了。

这是简单命令的输出:

Path                                                                         
----                                                                         
Services de fichiers et de stockage                                                                                                          
Services de fichiers et de stockage\Services de fichiers et iSCSI                                                                            
Services de fichiers et de stockage\Services de fichiers et iSCSI\Serveur de fichiers                                                        
Services de fichiers et de stockage\Services de fichiers et iSCSI\BranchCache pour fichiers réseau                                           
.........

我希望得到这样的结果(在分隔符“;”之前添加路径的特征名称)。

Path Needed
---- 

File and Storage Services [FileAndStorage-Services];;;;;;;;",

File and Storage Services [FileAndStorage-Services];File and iSCSI Services [File-Services];;;;;;;",

File and Storage Services [FileAndStorage-Services];File and iSCSI Services [File-Services];File Server [FS-FileServer];;;;;;",

File and Storage Services [FileAndStorage-Services];File and iSCSI Services [File-Services];BranchCache for Network Files [FS-BranchCache];;;;;;"

有人有想法吗?

预先感谢您的帮助。

此致

这是 CalculatedProperties 或 foreach 循环的完美案例。我认为 foreach 循环更容易阅读,所以让我们采用这种方法。

$features = get-windowsFeature
forEach ($feature in $features){
    $joinedPath = $feature.Name, $feature.Path -join ";"
    Write-Output $joinedPath
}

你可以把它写得更短,但我认为每行一步,很容易理解。

输出如下所示:

Windows-TIFF-IFilter;Windows TIFF IFilter
WinRM-IIS-Ext;WinRM IIS Extension
WINS;WINS Server
Wireless-Networking;Wireless LAN Service
WoW64-Support;WoW64 Support
XPS-Viewer;XPS Viewer