Remote endpoint configuration, custom resource

This topic contains 3 replies, has 2 voices, and was last updated by  Tore Groneng 3 years, 4 months ago.

  • Author
    Posts
  • #14537

    Tore Groneng
    Participant

    hi,

    Nice, our own DSC forum, very, very good idea 🙂

    From time to time I find my self needing to "run" an configuration that requires network access. I had this great idea to use register-pssessionconfiguration on the node and use the runascredential parameter for the cmdlet. Took me about 10 minutes to create the custom DSC resource, however that left me hanging in a catch 22 since the register command need to restart the winrm service (which I am using to push the configuration). I tried launching a new powershell session (with a new PID) to restart the winRM service from my custom DSC resource that (restart-service winrm -force), however that resulted in winrm service status Stop(pending). If i terminate the Svchost.exe process manually, the configuration is unable to continue (see error below).

    Two questions:
    1. Am I barking up the wrong tree since this will never ever work or
    2. Do anyone have an idea to solve the catch 22?

    The error:

    WARNING: [S002]: [[FPsessionProxy]sccmProxy] Changes made by Register-PSSessionConfiguration cannot take effect until the WinRM service is restarted.
    WARNING: [WSManNetworkFailureDetected] The network connection to s002 has been interrupted. Attempting to reconnect for up to 4 minutes...
    WARNING: [WSManConnectionRetryAttempt] Attempting to reconnect to s002 ...
    WARNING: [WSManConnectionRetryAttempt] Attempting to reconnect to s002 ...
    WARNING: [WSManConnectionRetryAttempt] Attempting to reconnect to s002 ...
    WARNING: [WSManConnectionRetryAttempt] Attempting to reconnect to s002 ...
    WARNING: [WSManConnectionRetryAttempt] Attempting to reconnect to s002 ...
    WARNING: [WSManConnectionRetrySucceeded] The network connection to s002 has been restored.
    The WS-Management service cannot process the operation. The operation is being attempted on a client session that is unusable. This may be related to a recent restart of the WS-Management service. Please create a new
    client session and retry the operation if re-executing the operation does not have undesired behavior.
    + CategoryInfo : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : HRESULT 0x803381fa
    + PSComputerName : s002

    VERBOSE: Operation 'Invoke CimMethod' complete.
    VERBOSE: Time taken for configuration job to complete is 126.693 seconds

    Please be gentle

    cheers

    Tore

  • #14538

    Don Jones
    Keymaster

    You're not necessarily barking up a wrong tree.

    There's probably a couple of ways to tackle this.

    One that comes to mind would be to create a Scheduled Task that, some time in the future, restarts the WinRM service. That way your session can be "done."

    But, have you looked at DSC Resource Kit Wave 3? There's a Microsoft resource that does this. See http://gallery.technet.microsoft.com/scriptcenter/DSC-Resource-Kit-All-c449312d – it's the xPSSessionConfiguration resource, in the xPSDesiredStateConfiguration resource module.

    BTW, hope you're planning to share that resource, if it does something unique! http://GitHub.com/powershellorg/DSC would be a good spot.

  • #14543

    Tore Groneng
    Participant

    hi Don,

    CURSES 🙂 completely missed that one from wave 3, thank you Don. Yes, I also thought about doing it with a scheduled task. Problem is that this is one of the first steps in the configuration. I could build an script on top that applies two DSC, however it is not very hot.

    The xPSSessionConfiguration uses the '$global:DscMachineStatus = 1' to solve the catch 22, which is just a "computer restart required" before the rest of the configuration can be applied.

    Regarding my resource. It is just something I wiped up in like 10 minutes, however it looks quite similar to the xPSSessionConfiguration resource. I used a different approach since my goal was to use PSSC files (we have the file resource you know). If you feel that is unique enough I can post it to GIT. I have attached the resource to this post.

    Cheers

    Tore

  • #14544

    Tore Groneng
    Participant

    Sorry, upload failed.

You must be logged in to reply to this topic.