是否可以使用PowerShell创建用于安装Windows功能的通用配置文件
我目前正在尝试自动构建运行 Windows Server 2012 R2的VM.目前,挑战是自动添加角色和功能.在角色和功能向导中,有一个选项可以导出可以在PowerShell中运行的XML配置文件. 但是,在查看XML文件后,我可以看到它特定于运行它的服务器 – 它包含诸如“ComputerName”之类的字段. 如果我想运行在许多VM上安装角色和功能的脚本,该怎么办?我需要一个通用的配置文件,而不是针对特定计算机的个性化. 有没有人对此问题有任何意见? 是的,对于 Linux和Windows,您可以构建所需的状态配置文件,它们可以:>启用或禁用服务器角色和功能 下面是一个示例配置文件,它将启用IIS,确保网站文件位于正确的文件夹中,如果没有安装或丢失任何这些内容,请根据需要安装或复制它们(请注意,$websitefilepath被认为是预定义为网站文件的来源): Configuration MyWebConfig { # A Configuration block can have zero or more Node blocks Node "Myservername" { # Next,specify one or more resource blocks # WindowsFeature is one of the built-in resources you can use in a Node block # This example ensures the Web Server (IIS) role is installed WindowsFeature MyRoleExample { Ensure = "Present" # To uninstall the role,set Ensure to "Absent" Name = "Web-Server" } # File is a built-in resource you can use to manage files and directories # This example ensures files from the source directory are present in the destination directory File MyFileExample { Ensure = "Present" # You can also set Ensure to "Absent" Type = "Directory“ # Default is “File” Recurse = $true # This is a path that has web files SourcePath = $WebsiteFilePath # The path where we want to ensure the web files are present DestinationPath = "C:inetpubwwwroot" # This ensures that MyRoleExample completes successfully before this block runs DependsOn = "[WindowsFeature]MyRoleExample" } } } 有关详细信息,请参阅Windows PowerShell Desired State Configuration Overview和Get Started with Windows PowerShell Desired State Configuration. 那么为什么要使用它而不仅仅是install-windowsfeature cmdlet呢?使用DSC而不是脚本的真正强大之处在于我可以定义一个位置,我可以存储要推送或拉出的配置(相对于目标机器),参见Push and Pull Configuration Modes.配置并不关心机器是否是物理的或虚拟的,但我相信至少需要2012年才能让服务器启动以提取DSC. (编辑:源码门户网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 如何在Windows上重启Apache? “Apache -k restart”给出错
- Windows 8.1为高像素密度显示屏引入视网膜显示支持
- 三步提速 - 提升Windows Server 2008的下载效率
- win10浏览器哪种好用
- 消息称微软Windows11 2022正式版重大更新将在明年夏天发布
- 微软Win11 10Edge Canary浏览器正测验同步PWA应用安装
- win10如何修改默认应用
- 如何使用Windows Server Task Scheduler在文件夹上的任何更
- 使用GNOME优化工具自定义Linux桌面的10种方法
- windows – 我应该使用登录横幅,如果是这样,它应该说什么?