Running Configuration script actually ran scripts on authoring machine

Welcome Forums DSC (Desired State Configuration) Running Configuration script actually ran scripts on authoring machine

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

 
Participant
1 year, 8 months ago.

  • Author
    Posts
  • #63343

    Participant
    Points: 0
    Rank: Member

    I just ran my test configuration by calling "TestConfig -ConfigurationData C:\Folder\ConfigData.psd1 -OutputPath C:\Folder\Output" and it actually ran the scripts in the script resource on my authoring workstation. Luckily it was just an example deleting files in the temp folder. Has anyone run into this before?

  • #63346

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

    Well, without seeing any of the code, it's super hard to guess what happened. But assuming "TestConfig" is the name of a Configuration block, then I would have expected C:\Folder\Output\TestConfig\ to contain one or more MOF files. I would not have expected the contents of Script resources to run, no.

    • #63349

      Participant
      Points: 0
      Rank: Member

      Thanks for the quick reply Don!

      I figured it out and it was a rookie mistake... Wasn't thinking that get/set/test had to be a script block, just went straight from "SetScript =" to the script without starting and ending with {}. So SetScript actually ran locally on my box. See below:

      Script CDriveCleanup
              {
                  GetScript = {@{Result = "WhateverResult"}}
                  SetScript = Remove-Item C:\Windows\Temp\* 
                  TestScript = 
                  {
                      $drive = Get-WmiObject win32_logicaldisk -Filter "Drivetype=3"
                      $drivePercentRemaining = ($drive.FreeSpace / $drive.Size)
                      If( $drivePercentRemaining -gt 0.1)
                      {
                          return $true
                      }Else
                      {
                          return $false
                      }
                  }#end TestScript                 
              }
      

      So for anyone else brand new to this, make sure your set/get/test are script blocks...

      Script CDriveCleanup
              {
                  GetScript = { @{Result = "WhateverResult"}}
                  SetScript = {Remove-Item C:\Windows\Temp\*}
                  TestScript = 
                  {
                      $drive = Get-WmiObject win32_logicaldisk -Filter "Drivetype=3"
                      $drivePercentRemaining = ($drive.FreeSpace / $drive.Size)
                      If( $drivePercentRemaining -gt 0.1)
                      {
                          return $true
                      }Else
                      {
                          return $false
                      }
                  }#end TestScript                 
              }
      

      Hopefully someone else will find this useful at least.

The topic ‘Running Configuration script actually ran scripts on authoring machine’ is closed to new replies.