Search code examples
powershelldsc

Write to a variable from DSC script resource


Is it possible to write to external variable from DSC "script" resource? To pass it through different script resources? Example:

Configuration SomeConfiguration 
{
   $list = @()

   Script SomeScript 
   {
      TestScript = {
         $using:list += "1"
         $using:list += "2"

         return $false
      }  
      SetScript = {
         $using:list | Foreach-Object {
            ...
         }
      }
      GetScript = { }
   }
}

Solution

  • This is not possible. Before executing every Test/Set function the LCM resets the state of the Runspace - i.e all variables are cleared. Therefore if you want to pass information, the best way is to write to a file and read from it