标签: dsc

Powershell DSC:无法加载模块xPSDesiredStateConfiguration

我正在使用powershell.org的DSC书籍,并尝试使用本书中指定的配置代码设置拉取服务器.

configuration CreatePullServer
{
    param
    (
        [string[]]$ComputerName = 'localhost'
    )

    Import-DSCResource -ModuleName xPSDesiredStateConfiguration

    Node $ComputerName
    {
        WindowsFeature DSCServiceFeature
        {
            Ensure = "Present"
            Name   = "DSC-Service"
        }

        xDscWebService PSDSCPullServer
        {
            Ensure                  = "Present"
            EndpointName            = "PSDSCPullServer"
            Port                    = 8080
            PhysicalPath            = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
            CertificateThumbPrint   = "AllowUnencryptedTraffic"
            ModulePath              = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
            ConfigurationPath       = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
            State                   = "Started"
            DependsOn               = "[WindowsFeature]DSCServiceFeature"
        }

        xDscWebService PSDSCComplianceServer
        {
            Ensure                  = "Present"
            EndpointName            = "PSDSCComplianceServer"
            Port                    = 9080
            PhysicalPath            = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer"
            CertificateThumbPrint   = "AllowUnencryptedTraffic"
            State                   = "Started"
            IsComplianceServer      = …
Run Code Online (Sandbox Code Playgroud)

powershell dsc

6
推荐指数
1
解决办法
8156
查看次数

如何围绕文件资源创建PowerShell DSC foreach循环,以复制配置中定义的多个文件?

我正在尝试使用PowerShell DSC执行多个文件副本.我的配置有一个需要复制的源/目标文件列表.但是,File资源需要具有唯一的名称,以便您可以对资源执行依赖项.

我是PowerShell的新手,我正在尝试找出DSC脚本(.ps1)的正确格式,以允许围绕File资源进行foreach.目前,我的代码给了我一个"重复资源标识符"错误,因为看起来文件资源没有获得唯一的名称.

配置(psd1文件):

{
AllNodes = @(
@{
  NodeName = '*'
  BuildOutputRoot = 'C:\_BuildDrop\'
  FilesToCopy = @(
    @{
      SourcePath = 'C:\_BuildDrop\SampleConfig.xml'
      TargetPath = 'C:\SampleCode\SampleConfig.xml'
    },
    @{
      SourcePath = 'C:\_BuildDrop\SampleConfig2.xml'
      TargetPath = 'C:\SampleCode\SampleConfig2.xml'
    },
Run Code Online (Sandbox Code Playgroud)

用于DSC(代码段)的Powershell ps1文件:

Configuration MachineToolsFilesAndDirectories
{
# Copy files on all machines
Node $AllNodes.NodeName
{
    foreach ($FileToCopy in $Node.FilesToCopy)
    {
        File $FileToCopy$Number
        {
            Ensure = "Present"
            Type = "File"
            Recurse = $false
            SourcePath = $FileToCopy.SourcePath
            DestinationPath = $FileToCopy.TargetPath
        }
    }
Run Code Online (Sandbox Code Playgroud)

powershell dsc

6
推荐指数
1
解决办法
4340
查看次数

DSC文件资源文件不复制PDB文件

我正在使用DSC文件资源更新具有最新版本的应用程序服务器.除了.PDB文件之外,这很有用.这些从未得到更新.我只用一个文件重现了这种行为.这是一个示例配置

Configuration FileTestConfiguration {
    param($HostName)

    Node $HostName {
        File AppDirectory {
        SourcePath = "c:\temp\dsc\source"
        DestinationPath = "c:\temp\dsc\target"
        Type = 'Directory'
        Checksum ='SHA-256'
        Recurse = $true
        MatchSource = $true
    }
    File PdbFile {
        SourcePath = "c:\temp\dsc\pdbSource\MyNetHelpers.pdb"
        DestinationPath = "c:\temp\dsc\pdbTarget\MyNetHelpers.pdb"
        Checksum ='SHA-256'
        Recurse = $true
        MatchSource = $true
    }
}
Run Code Online (Sandbox Code Playgroud)

}

运行上面的配置后,目录目标将反映目录源,但.pdb文件除外.与PdbFile块中的单个文件一样,表现出相同的行为

我已经运行了一些重命名文件的测试,但这没有任何影响.它似乎与.PDB格式有关.

有没有人看到过这种行为,知道是什么导致它或知道上面的配置是否不正确?

powershell dsc

6
推荐指数
1
解决办法
424
查看次数

配置DSC资源以重新启动

我有一个DSC资源,安装dotnet功能,然后安装更新到dotnet.

在我设置的本地配置管理器RebootNodeIfNeeded$true.

安装dotnet后,它不会请求重启(甚至使用xPendingReboot模块来确认).

Configuration WebServer
{
WindowsFeature NetFramework45Core
{
    Name = "Net-Framework-45-Core"
    Ensure = "Present"
}

xPendingReboot Reboot
{
    Name = "Prior to upgrading Dotnet4.5.2"
}

cChocoPackageInstaller InstallDotNet452
{
    name = "dotnet4.5.2"
}

}
Run Code Online (Sandbox Code Playgroud)

这是一个问题,因为dotnet无法正常使用我们的应用程序,除非服务器已重新启动,我们正在尝试使这些重新启动自动发生,无需用户输入.

是否有任何方法可以将资源推送到localdscmanager(LCM),以便在安装某些内容时需要重新启动?

我找到了以下命令

 $global:DSCMachineStatus = 1 
Run Code Online (Sandbox Code Playgroud)

哪个设置重启.但我不确定如何在安装4.5模块后立即重启它.

powershell dsc powershell-5.0

6
推荐指数
2
解决办法
7907
查看次数

如何在本地运行Powershell DSC脚本

我正试图在本地运行一个非常简单的Powershell DSC脚本.(我从不计划在此阶段提取或推送配置文件)

我收到以下错误消息.WS-Management服务正在运行,但没有保留防火墙漏洞或端口(服务器恰好是一个Web服务器)...反正我是否可以允许此服务器只接受本地请求?

客户端无法连接到请求中指定的目标.验证目标上的服务是否正在运行并且正在接受请求.查阅目标上运行的WS-Management服务的日志和文档,最常见的是IIS或WinRM.如果目标是WinRM服务,请在目标上运行以下命令以分析和配置WinRM服务:"winrm quickconfig".+ CategoryInfo:ConnectionError:(root/Microsoft/... gurationManager:String)[],CimException + FullyQualifiedErrorId:HRESULT 0x80338012 + PSComputerName:localhost

 configuration SampleIISInstall
    {
        Node 127.0.0.1
        {
          File FileDemo {
            Type = 'Directory'
            DestinationPath = 'C:\TestUser3'
            Ensure = "Present"
        }
        }
    }

    # Compile the configuration file to a MOF format
    SampleIISInstall

    # Run the configuration on localhost
    Start-DscConfiguration -Path .\SampleIISInstall -Wait -Force -Verbose
Run Code Online (Sandbox Code Playgroud)

powershell web-services dsc

6
推荐指数
1
解决办法
3956
查看次数

您如何应用多个DSC配置?

这是我的例子:

$Config = @{
    AllNodes = @(
        @{ NodeName = 'localhost'; PSDscAllowPlainTextPassword = $True }
    )
}

Configuration LocalAdmin
{
    Param([String[]]$Node='localhost',[PSCredential]$Cred)

    Import-DscResource -ModuleName 'PSDscResources'
    Node $Node
    {
        User 'LocalAdmin'
        {
            Username = 'Admin'
            Description = 'DSC configuration test'
            Ensure = 'Present'
            FullName = 'Administrator Extraordinaire'
            Password = $Cred
            PasswordChangeRequired = $False
            PasswordNeverExpires = $True
        }
        Group 'AddToAdmin'
        {
            GroupName = 'Administrators'
            DependsOn = '[User]LocalAdmin'
            Ensure = 'Present'
            MembersToInclude = 'Admin'
        }
    }
}
Configuration DisableLocalAccounts
{
    Param([String[]]$Node='localhost')

    Import-DscResource -ModuleName 'PSDscResources' …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-4.0 dsc powershell-5.0

6
推荐指数
2
解决办法
3414
查看次数

无法使用PowerShell cmdlet设置MSMQ ACL

我的MSMQ队列由PowerShell DSC引擎创建.我可以看到队列被创建了.由于DSC引擎从SYSTEM帐户运行,因此队列所有者也设置为SYSTEM.当我尝试从PowerShell控制台设置MSMQ ACL时,我不断收到以下错误:

PS C:\Users\Administrator.DOMAIN> whoami; Get-MsmqQueue queue1 | Set-MsmqQueueACL -UserName "Everyone" -Allow FullControl
DOMAIN\administrator
Set-MsmqQueueACL : Failed to set security descriptor. Error code: 3222143013
At line:1 char:50
+ whoami; Get-MsmqQueue incredipay_atm_processor | Set-MsmqQueueACL -UserName "Eve ...
+                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (FullControl:MessageQueueAccessRights) [Set-MsmqQueueACL], Win32Exception
    + FullyQualifiedErrorId : Failed to set security descriptor. Error code: 3222143013,Microsoft.Msmq.PowerShell.Commands.SetMSMQQueueACLCommand
Run Code Online (Sandbox Code Playgroud)

我也无法使用自定义DSC资源设置MSMQ ACL,这基本上只从SYSTEM帐户执行相同的操作.所以问题是有没有办法使用Set-MSMQQueueACL cmdlet在PowerShell DSC引擎中设置MSMQ权限.或者至少如果我能够解决前面提到的错误,那么也许我也能解决DSC问题.我正在运行Windows 2012和WMF 4.0.

提前致谢.

powershell acl msmq dsc

5
推荐指数
1
解决办法
1937
查看次数

Azure PowerShell DSC 安装额外模块

作为 Azure 资源组模板的一部分,我为我的 VM 设置了 PowerShell DSC 扩展,该扩展设置了各种 Windows 功能。

作为此自动化设置的一部分,我希望能够在防火墙中打开一些端口,经过一番研究后我发现有一个可用的 xFirewall DSC 模块。我的问题是如何在 DSC 执行之前自动将此模块安装到 Azure VM 上?

我的配置如下:

Configuration Main
{

Param ( [string] $nodeName )

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xFirewall

Node $nodeName
Run Code Online (Sandbox Code Playgroud)

由于未安装模块,xFirewall 导入失败。

我曾考虑过创建另一个可以在此脚本之前运行的 DSC 脚本,但这证明很困难,因为一次只能将一个 DSC 扩展附加到虚拟机。

powershell azure azure-powershell dsc

5
推荐指数
1
解决办法
2102
查看次数

DSC - PowerShell 模块路径中不存在模块

这是我遇到的错误:“PowerShell 提供程序 <module> 在 PowerShell 模块路径中不存在,也未注册为 WMI 提供程序”

我并不是 PowerShell 和 DSC 的新手,但我很难弄清楚这一点。我已按照此处的指南进行故障排除。我还发现了这个几乎相同的问题......唯一的解决方案似乎是重新启动(我尝试过)。

所以我做了一个配置,导入一个模块,OctopusDSC。在对模块导入进行故障排除期间,我遗漏了很多参数,但这是我所拥有的:

Configuration OctopusServer
{
    Import-DscResource -Module OctopusDSC

    Node "WIN-ABC123" 
    {
        cTentacleAgent OctopusTentacle 
        { 
            Ensure = "Present"
            State = "Started"
            Name = "Tentacle"
            ApiKey = ""
            OctopusServerUrl = ""
            DefaultApplicationDirectory = "C:\Utility"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

该模块存在于C:\Program Files\WindowsPowerShell\Modules本地和服务器上:

C:\>tree "C:\Program Files\WindowsPowerShell\Modules" /f
Folder PATH listing
Volume serial number is 9EC4-62C1
C:\PROGRAM FILES\WINDOWSPOWERSHELL\MODULES
????OctopusDSC
    ?   OctopusDSC.psd1
    ?
    ????DSCResources
        ????cTentacleAgent
                cTentacleAgent.psm1
                cTentacleAgent.schema.mof
Run Code Online (Sandbox Code Playgroud)

模块路径看起来不错(为了便于阅读,我在每个分号处都加了回车):

PS C:\> …
Run Code Online (Sandbox Code Playgroud)

powershell dsc

5
推荐指数
1
解决办法
6846
查看次数

在 DSC 脚本中添加入站重写规则不起作用

正如标题所示,我正在使用以下命令配置反向代理功能的重写规则:

  • IIS 8.5
  • Windows Server 2012R2
  • URL重写2.1
  • 应用程序请求路由3.0
  • Powershell 5.1

为此,我使用 Powershell DSC,在脚本资源中设置配置。这对于出站规则非常有效,但不会创建入站规则,也不会给出错误/警告。当尝试在其上设置属性时(在后面的 3 行),确实会显示一条警告,指出它找不到入站规则,顺便说一句,还显示了正确使用的变量名称)。在 IIS 管理控制台中它也是不可见的(是的,我已经使用了 F5)。

我使用的是 IIS 本身生成的命令,它与我在网上看到的所有命令相同,包括 StackOverflow。这个特殊问题不容易找到,所以我一定错过了一些非常微不足道的东西。我已经尝试过:

  • 在不同的凭据下运行脚本
  • 使用硬编码名称而不是变量
  • 使用 URL 重写 2.0
  • 重新启动 IIS
  • 重新启动服务器

我让命令工作的唯一方法是在(提升的)Powershell(下面用 >>>> 标记)中将其作为单个命令执行。

然后是脚本本身。(作为参考,还添加了一条出站规则):

SetScript = {
            Write-Verbose "Checking if inbound rewrite rule is present..."

            $inbound = (Get-WebConfiguration -Filter "//System.webServer/rewrite/rules" -PSPath "IIS:\Sites\$using:frontendSiteName").Collection | Where-Object {$_.Name -eq "$using:inboundRuleName"}

            if($inbound -eq $null) {
                Write-Verbose "Inbound rewrite rule not present, configuring..."

        >>>>    Add-WebConfigurationProperty -Filter "//System.webServer/rewrite/rules" -Name "." -Value @{name=$using:inboundRuleName;stopProcessing="True"} -PSPath "IIS:\Sites\$using:frontendSiteName"
                Set-WebConfigurationProperty …
Run Code Online (Sandbox Code Playgroud)

iis powershell url-rewrite-module dsc

5
推荐指数
1
解决办法
1448
查看次数