简体   繁体   中英

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)?

When I run my script by PS ISE everything works fine, DSC applies to 2 servers incl. encryption. But when I run exactly the same script by 'Run with Powershell' I'm getting such error messages:

System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression. 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).

line 1021 at ScriptBlock, No file: line 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). 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?

You can do pretty much everything you would do with DSC, with straight powershell code. 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.

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.

Go through the Following Links:

Powershell DSC

Configuration Management Theory - Idempotence & Immutability

Configuration Management

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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