Powershell ISE vs console (DSC executing)

Welcome Forums DSC (Desired State Configuration) Powershell ISE vs console (DSC executing)

This topic contains 2 replies, has 2 voices, and was last updated by

Prz
 
Participant
1 year, 12 months ago.

  • Author
    Posts
  • #64711
    Prz

    Participant
    Points: 1
    Rank: Member

    Hello,

    Can anybody tell me what is the difference between running DSC script by Powershell ISE vs standard console? 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 , : 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]
    }
    )
    }

    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?

  • #64761

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    The ISE maintains a more persistent environment than the console. At a guess, based on the error, $_ is a null expression when you're running it, which makes me suspect E: doesn't exist in that context.

  • #64807
    Prz

    Participant
    Points: 1
    Rank: Member

    I don't know what to say 🙂 I'm sure E: drive as well as "MyFolderName" exist on the Server 2, I see it now. I tested it by execute command get-item "$((Get-ChildItem "E:\" | ? {$_.Name -like "MyFolderName"}).fullname)\Server2.cer" on the Server2 with success.
    Anyway if E: drive would not exist on the Server2 I guess PS ISE should also return an error.

    Maybe there is some authentication/permissions difference when running DSC by ISE or standard console?

The topic ‘Powershell ISE vs console (DSC executing)’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort