服务器 Features/Role 将使用 Powershell 编写脚本的服务设置

Server Features/Role Services Settings to be scripted with Powershell

我想开发一个 powershell 脚本来 select 这些服务器功能和角色的一堆是可重复的,因为我使用的许多服务器需要相同的设置 selected pre-设置。我很难在 RegEdit 中找到这些。有人可以指出这些角色所在的正确方向吗?我在想我可能没有找对地方。

这可以通过 powershell 使用命令 Get-WindowsFeature

轻松完成
PS C:\> Get-WindowsFeature | where installed

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
    [X] Storage Services                                Storage-Services               Installed
[X] Web Server (IIS)                                    Web-Server                     Installed
    [X] Web Server                                      Web-WebServer                  Installed
        [X] Common HTTP Features                        Web-Common-Http                Installed
            [X] Default Document                        Web-Default-Doc                Installed
            [X] Directory Browsing                      Web-Dir-Browsing               Installed
            [X] HTTP Errors                             Web-Http-Errors                Installed
            [X] Static Content                          Web-Static-Content             Installed
            [X] HTTP Redirection                        Web-Http-Redirect              Installed
            [X] WebDAV Publishing                       Web-DAV-Publishing             Installed
        [X] Health and Diagnostics                      Web-Health                     Installed
            [X] HTTP Logging                            Web-Http-Logging               Installed
            [X] Custom Logging                          Web-Custom-Logging             Installed
            [X] Logging Tools                           Web-Log-Libraries              Installed
            [X] Tracing                                 Web-Http-Tracing               Installed
        [X] Performance                                 Web-Performance                Installed
            [X] Static Content Compression              Web-Stat-Compression           Installed
            [X] Dynamic Content Compression             Web-Dyn-Compression            Installed
        [X] Security                                    Web-Security                   Installed
            [X] Request Filtering                       Web-Filtering                  Installed
            [X] Basic Authentication                    Web-Basic-Auth                 Installed
            [X] Centralized SSL Certificate Support     Web-CertProvider               Installed
            [X] Client Certificate Mapping Authentic... Web-Client-Auth                Installed
            [X] Digest Authentication                   Web-Digest-Auth                Installed
            [X] IIS Client Certificate Mapping Authe... Web-Cert-Auth                  Installed
            [X] IP and Domain Restrictions              Web-IP-Security                Installed
            [X] URL Authorization                       Web-Url-Auth                   Installed
            [X] Windows Authentication                  Web-Windows-Auth               Installed
        [X] Application Development                     Web-App-Dev                    Installed
            [X] .NET Extensibility 3.5                  Web-Net-Ext                    Installed
            [X] .NET Extensibility 4.6                  Web-Net-Ext45                  Installed
            [X] Application Initialization              Web-AppInit                    Installed
            [X] ASP                                     Web-ASP                        Installed
            [X] ASP.NET 3.5                             Web-Asp-Net                    Installed
            [X] ASP.NET 4.6                             Web-Asp-Net45                  Installed
            [X] CGI                                     Web-CGI                        Installed
            [X] ISAPI Extensions                        Web-ISAPI-Ext                  Installed
            [X] ISAPI Filters                           Web-ISAPI-Filter               Installed
            [X] Server Side Includes                    Web-Includes                   Installed
            [X] WebSocket Protocol                      Web-WebSockets                 Installed
    [X] Management Tools                                Web-Mgmt-Tools                 Installed
        [X] IIS Management Console                      Web-Mgmt-Console               Installed
[X] .NET Framework 3.5 Features                         NET-Framework-Features         Installed
    [X] .NET Framework 3.5 (includes .NET 2.0 and 3.0)  NET-Framework-Core             Installed
[X] .NET Framework 4.6 Features                         NET-Framework-45-Fea...        Installed
    [X] .NET Framework 4.6                              NET-Framework-45-Core          Installed
    [X] ASP.NET 4.6                                     NET-Framework-45-ASPNET        Installed
    [X] WCF Services                                    NET-WCF-Services45             Installed
        [X] HTTP Activation                             NET-WCF-HTTP-Activat...        Installed
        [X] Message Queuing (MSMQ) Activation           NET-WCF-MSMQ-Activat...        Installed
        [X] Named Pipe Activation                       NET-WCF-Pipe-Activat...        Installed
        [X] TCP Activation                              NET-WCF-TCP-Activati...        Installed
        [X] TCP Port Sharing                            NET-WCF-TCP-PortShar...        Installed
[X] Message Queuing                                     MSMQ                           Installed
    [X] Message Queuing Services                        MSMQ-Services                  Installed
        [X] Message Queuing Server                      MSMQ-Server                    Installed
[X] Remote Differential Compression                     RDC                            Installed
[X] SMB 1.0/CIFS File Sharing Support                   FS-SMB1                        Installed
[X] Windows Defender Features                           Windows-Defender-Fea...        Installed
    [X] Windows Defender                                Windows-Defender               Installed
    [X] GUI for Windows Defender                        Windows-Defender-Gui           Installed
[X] Windows PowerShell                                  PowerShellRoot                 Installed
    [X] Windows PowerShell 5.1                          PowerShell                     Installed
    [X] Windows PowerShell 2.0 Engine                   PowerShell-V2                  Installed
    [X] Windows PowerShell ISE                          PowerShell-ISE                 Installed
[X] Windows Process Activation Service                  WAS                            Installed
    [X] Process Model                                   WAS-Process-Model              Installed
    [X] .NET Environment 3.5                            WAS-NET-Environment            Installed
    [X] Configuration APIs                              WAS-Config-APIs                Installed
[X] WoW64 Support                                       WoW64-Support                  Installed

并将其安装到另一台机器上,您只需要使用 属性 ComputerName

将结果通过管道传输到 Install-WindowsFeature
Get-WindowsFeature | where installed | Install-WindowsFeature -ComputerName $computername

另一种选择是使用 ConfigurationFilePath

安装 windows 功能
PS> $servers = ('server1', 'server2')
PS> foreach ($server in $servers) {Install-WindowsFeature -ConfigurationFilePath D:\ConfigurationFiles\ADCSConfigFile.xml -ComputerName $server}

The configuration file was created by clicking Export configuration settings on the Confirm installation selections page of the Add Roles and Feature Wizard in Server Manager. On the first line, the value of the $servers variable is set; on the second line, the installation instructions in the ADCSConfigFile.xml configuration file are applied to each of the servers that has been named in $servers.

参考:https://docs.microsoft.com/en-us/powershell/module/servermanager/install-windowsfeature?view=windowsserver2022-ps