简体   繁体   English

DSC(所需状态配置)

[英]DSC (Desired State Configuration)

Can anybody tell me what is the difference between running DSC script by Powershell ISE vs standard console (both run as administrator)? 谁能告诉我Powershell ISE运行DSC脚本与标准控制台(均以管理员身份运行)有什么区别?

When I run my script by PS ISE everything works fine, DSC applies to 2 servers incl. 当我通过PS ISE运行脚本时,一切正常,DSC适用于2台服务器,包括。 encryption. 加密。 But when I run exactly the same script by 'Run with Powershell' I'm getting such error messages: 但是,当我通过“使用Powershell运行”运行完全相同的脚本时,我得到了这样的错误消息:

System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression. System.Management.Automation.RuntimeException:您不能在空值表达式上调用方法。 at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame). 在System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext,Exception exception)在System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)在System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) ),位于System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame框架)。

line 1021 at ScriptBlock, No file: line 1 ScriptBlock的第1021行,无文件:第1行

These errors point to the below line (in bold): 这些错误指向下面的行(粗体):

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

The problem is with the Server2 (I'm running script on Server1). 问题出在Server2上(我正在Server1上运行脚本)。 All paths are correct, can I use such syntax in the hashtable? 所有路径都是正确的,我可以在哈希表中使用这种语法吗?

The problem is with the standard powershell console, does anybody know why PS ISE does not return any errors? 问题出在标准的Powershell控制台上,有人知道为什么PS ISE不返回任何错误吗?

You can do pretty much everything you would do with DSC, with straight powershell code. 使用直接的Powershell代码,您几乎可以完成DSC的所有工作。 The code describing your system in the configuration management system will be checked and ran against your system periodically. 将检查配置管理系统中描述您系统的代码,并定期针对您的系统运行该代码。

DSC and many other configuration management systems is about making re-usable resources that actually do the work that can be shared. DSC和许多其他配置管理系统旨在使可重复使用的资源实际完成可以共享的工作。

This is one of the reasons why the general script is not able to pick the configurations. 这是常规脚本无法选择配置的原因之一。 In your case, you got one Runtime Exception which clearly depicts that some value which had been passed to a method in the script was NULL. 在您的情况下,您遇到一个运行时异常,该异常清楚地描述了已传递给脚本中方法的某些值是NULL。

Go through the Following Links: 通过以下链接:

Powershell DSC Powershell DSC

Configuration Management Theory - Idempotence & Immutability 配置管理理论-幂等与不变

Configuration Management 配置管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM