【问题标题】:DSC (Desired State Configuration)DSC(期望状态配置)
【发布时间】:2017-02-20 15:23:13
【问题描述】:

谁能告诉我通过 Powershell ISE 运行 DSC 脚本与标准控制台(均以管理员身份运行)有什么区别?

当我通过 PS ISE 运行我的脚本时,一切正常,DSC 适用于 2 个服务器,包括。加密。但是,当我通过“使用 Powershell 运行”运行完全相同的脚本时,我收到了这样的错误消息:

System.Management.Automation.RuntimeException:您不能在空值表达式上调用方法。在 System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext,异常异常)在 System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame 帧)在 System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 帧)在 System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 框架)。

ScriptBlock 的第 1021 行,无文件:第 1 行

这些错误指向下面一行(粗体):

Configuration Config1
{
...
...
...
}
$configdata = @{
        AllNodes = @(
            @{
                NodeName = "Server1"
                PSDscAllowDomainUser = $true
                CertificateFile = "$((Get-ChildItem 'E:\' | ? {$_.Name -like 'MyFolderName'}).fullname)\Server1.cer"
                Thumbprint = ($Thumbs | ? {$_ -like "Server1*"}).Split("=")[1]
            }
            @{
                NodeName = "Server2"
                PSDscAllowDomainUser = $true
                CertificateFile = "$((Get-ChildItem 'E:\' | ? {$_.Name -like MyFolderName'}).fullname)\Server2.cer"
                Thumbprint = ($Thumbs | ? {$_ -like "Server2*"}).Split("=")[1]
             }
        )
    }

Config1 -ConfigurationData $configdata

问题出在 Server2 上(我在 Server1 上运行脚本)。所有路径都正确,我可以在哈希表中使用这样的语法吗?

问题在于标准的 powershell 控制台,有人知道为什么 PS ISE 不返回任何错误吗?

【问题讨论】:

  • 如果您看到在标准 powershell 控制台和 powershell ISE 中运行的代码之间存在差异,我会检查您的 powershell 配置文件。与标准控制台相比,将在 ISE 中运行不同的配置文件 powershell。 About Profiles

标签: powershell dsc


【解决方案1】:

您几乎可以使用直接的 powershell 代码完成使用 DSC 可以完成的所有操作。配置管理系统中描述您系统的代码将定期检查并针对您的系统运行。

DSC 和许多其他配置管理系统都是为了让可重复使用的资源真正完成可共享的工作。

这是通用脚本无法选择配置的原因之一。 在您的情况下,您遇到了一个运行时异常,它清楚地描述了传递给脚本中方法的某个值是 NULL。

通过以下链接:

Powershell DSC

Configuration Management Theory - Idempotence & Immutability

Configuration Management

【讨论】:

  • 感谢您的回复,但我仍然不知道如何完成这种情况: 1. 使用将在 Server1 上执行 Start-DSCConfiguration 的所有必需信息运行脚本(Server1 的加密 MOF 文件和Server2) 2. 从 Server1 成功为两台服务器执行 Test-DSCConfiguration 我试图按照这篇文章 (msdn.microsoft.com/en-us/powershell/dsc/…) 但没有成功...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多