AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1805678
Accepted
leanne
leanne
Asked: 2023-08-25 05:40:07 +0800 CST2023-08-25 05:40:07 +0800 CST 2023-08-25 05:40:07 +0800 CST

使用 Get-WindowsFeature 显示功能列表和子功能

  • 772

我正在使用 Hyper-V Server 2019。(这是一个安装了 Hyper-V 角色的免费Windows Server 2019 Core软件包。默认情况下它完全基于文本 - 与常规 Windows Server 软件包一样,没有 GUI 桌面,除了 3rd派对解决方案不属于该问题。)

许多在服务器上设置各种内容的说明都假设图形工具可用。例如,文章为 Windows Admin Center 准备环境展示了如何使用其他版本的 Windows Server 中通常提供的图形工具执行步骤 2:启用文件服务器角色。很少有说明包含 Powershell 执行操作的方法。

我已经学会了使用 Powershell“cmdlet”来做各种事情,但我停留在上面的步骤 2 上。我想,我可以弄清楚如何安装我需要的功能;但是,为了将来的参考,我希望能够显示我感兴趣的项目。所以......

要显示所有功能的列表,我可以输入Get-WindowsFeature。当然,这会带来一个长长的滚动列表!

我可以通过说明中的图表看到,我需要查看“文件和存储服务”下安装的内容。所以,我这样做:

Get-WindowsFeature | where {$_.InstallState -eq "Installed"}

(或者,或者Get-WindowsFeature | where Installed:)

在 Powershell 5.1 中,返回:

Get-WindowsFeature:已安装项目列表

我可以添加一个带有属性SubFeatures的Select-Object管道并得到:

Get-WindowsFeature:带有子功能的已安装项目列表

但是,我真正想要的是第一个图像,但仅限于“文件和存储服务”部分及其所有子功能,无论InstallState值如何。

我已经看到-ExpandProperty与数组类型结果一起使用的参数,但在 cmdlet 中的任何位置添加该参数只会给我一个关于该参数不可用或 SubFeatures 属性不可用的错误。但...

Get-WindowsFeature | Get-Member显示属性如下:

SubFeatures Property string[] SubFeatures {get;}

我已尝试使用以下参数-ExpandProperty:

Get-WindowsFeature | where {$_.InstallState -eq "Installed"} | Select-Object -ExpandProperty DisplayName, Name, InstallState, SubFeatures

Get-WindowsFeature | where {$_.InstallState -eq "Installed"} | Select-Object DisplayName, Name, InstallState, -ExpandProperty SubFeatures

Get-WindowsFeature | where {$_.InstallState -eq "Installed"} | Select-Object DisplayName, Name, InstallState | Select-Object -ExpandProperty SubFeatures

注意:我在这些上使用InstallState 的唯一原因是这样我没有得到巨大的滚动结果。在深入研究如何获取一个“文件和存储服务”部分之前,我正在尝试获取SubFeatures属性,因为我认为这需要我首先弄清楚SubFeatures ... 嗯...

另外,顺便说一句:Powershell 7在输出中有一个“显示名称”字段;然而,它是空白的。只有“名称”和“安装状态”字段有内容。有趣的是,我可以通过指定它来获取信息:Get-WindowsFeature | where Installed | Select-Object DisplayName, Name, InstallState,但它没有漂亮的小[X]标记;)

无论哪种方式,我正在寻找的是如何获取特定部分(此处为文件和存储服务)及其扩展SubFeatures属性,以便我可以使用 Powershell 轻松查看该部分已安装或可用的内容。

哦,需要明确的是,我确实尝试过Get-WindowsFeature -Name FileAndStorage-Services,它只返回一项(没有其子功能):

Get-WindowsFeature 仅显示一项服务


如果我使用 simple ,这是我输出的前几行Get-WindowsFeature,包括以下File and Storage Services部分:

Get-WindowsFeature 输出的前几行

powershell
  • 1 1 个回答
  • 29 Views

1 个回答

  • Voted
  1. Best Answer
    Vomit IT - Chunky Mess Style
    2023-08-25T07:14:04+08:002023-08-25T07:14:04+08:00

    SubFeatures要在查询时获取as 输出FileAndStorage-Services,您可以利用父要素的Name属性。通过动态生成其关联的列表SubFeatures,您可以确保它们也包含在列表中。

    电源外壳

    $FeatureName = "FileAndStorage-Services";
    $subFeatures = (Get-WindowsFeature -Name $FeatureName | Select-Object SubFeatures).SubFeatures;
    $subFeatures = $subFeatures+(Get-WindowsFeature -Name $subFeatures | Select-Object SubFeatures).SubFeatures;
    $combineFeatures = "$($FeatureName)|$($subFeatures -join "|")";
    Get-WindowsFeature | Where-Object {$_.Name -match $combineFeatures};
    

    输出

    Display Name                                            Name                       Install State
    ------------                                            ----                       -------------
    [X] File and Storage Services                           FileAndStorage-Services        Installed
        [X] File and iSCSI Services                         File-Services                  Installed
            [X] File Server                                 FS-FileServer                  Installed
            [ ] BranchCache for Network Files               FS-BranchCache                 Available
            [ ] Data Deduplication                          FS-Data-Deduplication          Available
            [X] DFS Namespaces                              FS-DFS-Namespace               Installed
            [X] DFS Replication                             FS-DFS-Replication             Installed
            [ ] File Server Resource Manager                FS-Resource-Manager            Available
            [ ] File Server VSS Agent Service               FS-VSS-Agent                   Available
            [ ] iSCSI Target Server                         FS-iSCSITarget-Server          Available
            [ ] iSCSI Target Storage Provider (VDS and V... iSCSITarget-VSS-VDS            Available
            [ ] Server for NFS                              FS-NFS-Service                 Available
            [ ] Work Folders                                FS-SyncShareService            Available
        [X] Storage Services                                Storage-Services               Installed
            [X] File Services Tools                         RSAT-File-Services             Installed
    

    更多详情

    执行此操作将揭示SubFeatures. 在某些情况下,采用该Select *方法可能特别有利,如下面的输出所示。

    Get-WindowsFeature -Name $FeatureName | Select-Object *;
    

    其余的组件都很简单,因此我提供了一个支持资源部分,如果您有兴趣或发现需要深入挖掘,您可以探索该部分以进一步学习。

    输出

    Name                      : FileAndStorage-Services
    DisplayName               : File and Storage Services
    Description               : File and Storage Services includes services that are always installed, as well as functionality that you can install to help manage file servers and 
                                storage.
    Installed                 : True
    InstallState              : Installed
    FeatureType               : Role
    Path                      : File and Storage Services
    Depth                     : 1
    DependsOn                 : {}
    Parent                    : 
    ServerComponentDescriptor : ServerComponent_FileAndStorage_Services
    SubFeatures               : {File-Services, Storage-Services}
    SystemService             : {}
    Notification              : {}
    BestPracticesModelId      : Microsoft/Windows/FileServices
    EventQuery                : FileServer.Events.xml
    PostConfigurationNeeded   : False
    AdditionalInfo            : {MajorVersion, MinorVersion, NumericId, InstallName}
    

    支持资源

    • Operators $( ) @( ) :: &
    • -Join
    • 比较运算符
    • 3

相关问题

  • 如何将变量字符串放入powershell中的数组?

  • Powershell 和正则表达式:Notepad++“保存时备份”文件列表。编辑名称,按上次写入时间排序

  • 将前景颜色添加到 Powershell 配置文件?

  • 禁用后无法启用 Microsoft Print to PDF

  • 我可以让这个 PowerShell 脚本接受逗号吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve