views:

247

answers:

1

The problem: 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.

The Question: 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.

The Answer: In VBS

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: " & ServerName & VBNewLine)
            WScript.StdOut.Write("Description: " & objVar.Description & VBNewLine)
            WScript.StdOut.Write("Name: " & objVar.Name & VBNewLine)
            WScript.StdOut.Write("System Variable: " & objVar.SystemVariable & VBNewLine)
            WScript.StdOut.Write("User Name: " & objVar.UserName & VBNewLine)
            WScript.StdOut.Write("Variable Value: " & objVar.VariableValue & VBNewLine & VBNewLine)
    Next

End Function
+3  A: 

Have not tried it, but you can check this out. the examples is vbscript, change strComputer to the IP address of your remote and see how it goes. For many remote hosts, use a for loop.

ghostdog74
Had to use this page as well http://msdn.microsoft.com/en-us/library/aa389290(VS.85).aspx but thanks!
Ioxp
good to know. :)
ghostdog74