title: How to get an environment variable in a Powershell script when it is deployed by SCCM?
body: <p>I've made a script to automatically change and/or create the default Outlook signature of all the employees in my company.</p>
  
  <p>Technically, it gets the environment variable username where the script is deployed, access to the staff database to get some information regarding this user, then create the 3 different files for the signature by replacing values inside linked docx templates. Quite easy and logical.</p>
  
  <p>After different tests, it is working correctly when you launch the script directly on a computer, either by using Powershell ISE, directly by the CMD or in Visual Studio. But when we tried to deploy it, like it will be, by using SCCM, it can't get any environment variable.</p>
  
  <p>Do any of you have an idea about how to get environment variables in a script when it is deployed by SCCM ?</p>
  
  <p>Here is what I've already tried :</p>
  
  <pre><code>$Name = [Environment]::UserName
  
  $EnvVarUserName = Get-Item Env:\USERNAME
  </code></pre>
  
  <p>Even stuff like this :</p>
  
  <pre><code>$proc = gwmi win32_process -Filter "Name = 'explorer.exe'"
  $report = @()
  ForEach ($p in $proc)
  {
      $temp = "" | Select User
      $temp.user = ($p.GetOwner()).User
      $report += $temp
  }
  </code></pre>
  
  <p>Thanks in advance and have a nice day y'all !</p>
  
  <p>[EDIT]:</p>
  
  <p>I've found a way of doing this, not the best one, but it works. I get the name of the machine, check the DB where when a laptop is connected to our network it stores the user id and the machine, then get the info in the staff DB.</p>
  
  <p>I will still check for Matt's idea which is pretty interesting and, in a way, more accurate.</p>
  
  <p>Thank you all !</p>