Running Configuration script actually ran scripts on authoring machine

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Matt Walker Matt Walker 1 month, 3 weeks ago.

  • Author
    Posts
  • #63343
    Profile photo of Matt Walker
    Matt Walker
    Participant

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
      Profile photo of Matt Walker
      Matt Walker
      Participant

      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.

You must be logged in to reply to this topic.