是否可以使用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. (编辑:海洋资讯信息网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


