powershell - 如何自定义 Get-Windowsfeature 路径的输出
问题描述
实际上,我正在寻找自定义我的输出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];;;;;;"
有人有想法吗?
在此先感谢您的帮助。
此致
解决方案
这是 forCalculatedProperties
或 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
推荐阅读
- c# - NullReferenceException 与 Nullable DateTime 尽管进行了空检查
- azure - LUIS 通话限制
- javascript - 如何在不接触 index.html 的情况下将外部 javascript 标签添加到 Ember JS 应用程序?
- python - 将一列合并并与 (2,N) 数组的另一列相加
- javascript - 如何在 HTML 中引用当前 URL?
- netlogo - 如何以相同(非随机)的顺序从 NetLogo 代理集中检索多个变量?
- c++ - 与 QMainWindow 的 GUI 命令交互时,QDockWidget 无法正确调整大小
- python - TypeError:列表索引必须是整数或切片,而不是元组,我很新并且很困惑为什么我的列表列表不起作用
- java - 值更新不是 scala.collection.immutable.Map 的成员
- reactjs - 在 React 组件中使用常量