title: Get remote servers environment variables
body: <p><strong>The problem:</strong> We have Cobol applications that run from many servers (mostly server 2003) on our network. Many if not all of these applications use environment variables for there setting.</p>
  
  <p><strong>The Question:</strong> From one workstation can you gather the full list of environment variables from a list of known servers remote? Optimally i would like to do this in Batch, VBS, or the Powershell. </p>
  
  <p><strong>The Answer:</strong> In VBS</p>
  
  <pre><code>GetEnvironment("[RemoteServersName]")
  
  Function GetEnvironment(ServerName)
  
      strComputer = ServerName
      Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
      Set objSWbemServices = objSWbemLocator.ConnectServer _
          (strComputer, "root\cimv2", "[ValidLogonName]", "[PasswordForLogonName]")
      objSWbemServices.Security_.ImpersonationLevel = 3
      Set colVar = objSWbemServices.ExecQuery( _
          "Select * from Win32_Environment")
      For Each objVar in colVar
              WScript.StdOut.Write("Server Name: " &amp; ServerName &amp; VBNewLine)
              WScript.StdOut.Write("Description: " &amp; objVar.Description &amp; VBNewLine)
              WScript.StdOut.Write("Name: " &amp; objVar.Name &amp; VBNewLine)
              WScript.StdOut.Write("System Variable: " &amp; objVar.SystemVariable &amp; VBNewLine)
              WScript.StdOut.Write("User Name: " &amp; objVar.UserName &amp; VBNewLine)
              WScript.StdOut.Write("Variable Value: " &amp; objVar.VariableValue &amp; VBNewLine &amp; VBNewLine)
      Next
  
  End Function
  </code></pre>