title: Lazy loading in powershell?
body: <p><em>Can we defer a variable initialization untill it is needed ?</em></p>
  
  <p>What I would like to do is <strong>predefine</strong> some variables in my profile that will contain a list of AD computer: </p>
  
  <p>let's say I want:</p>
  
  <p><em>$OU1_workstation</em> to be fill with computers found in OU=workstations,OU=OU1,dc=domain,dc=com </p>
  
  <p><em>$OU2_workstation</em> fill with computers found in<br>
  OU=workstations,OU=OU2,dc=domain,dc=com and so on...</p>
  
  <p>I use the following script to do it but it takes 30sec to compute, so currently I can't put that in my profile...</p>
  
  <pre><code>Get-ADOrganizationalUnit -SearchScope onelevel -Filter "*" -Properties "name","distinguishedname" |%{
      set-Variable -Name "$($_.name)_workstation" -value (Get-ADComputer -Searchbase "OU=workstations,$($_.Distinguishedname)" -Filter * )
  }    
  </code></pre>
  
  <p>What options are available in powershell ?</p>