windows 获取远程服务器环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2071819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get remote servers environment variables
提问by Random Developer
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.
问题:我们有从网络上的许多服务器(主要是服务器 2003)运行的 Cobol 应用程序。许多(如果不是全部)这些应用程序都使用环境变量进行设置。
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.
问题:您能否从一台工作站收集来自远程已知服务器列表的完整环境变量列表?最理想的是,我想在 Batch、VBS 或 Powershell 中执行此操作。
The Answer:In VBS
答案:在 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
采纳答案by ghostdog74
回答by Miguel
Here is the powershell command:
这是powershell命令:
gwmi win32_environment -computername dc1.acme.com
And if you want a condensed version:
如果你想要一个精简版:
gwmi win32_environment -computername dc1.acme.com |select name,variablevalue |ft -auto