 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The VBScript Network and Systems Administrator&#039;s Cafe &#187; Remote management</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/remote-management/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Retrieve environment variable values from a remote system with WMI</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/retrieve-environment-variable-values-from-a-remote-system-with-wmi/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/retrieve-environment-variable-values-from-a-remote-system-with-wmi/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 02:03:55 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Environment Variables]]></category>
		<category><![CDATA[PATH variable]]></category>
		<category><![CDATA[Remote management]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Win32_Environment]]></category>
		<category><![CDATA[Windows Management Interface]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/?p=174</guid>
		<description><![CDATA[Back in October I shared with you a way to retrieve environment variables with a script titled Using Environment variables inside a VBScript script. The script worked like a champ and got me through several tight binds in gathering information, hopefully it has for you as well. However, it has one flaw&#8230; it doesn&#8217;t work [...]]]></description>
				<content:encoded><![CDATA[<p>Back in October I shared with you a way to retrieve environment variables with a script titled <a title="Permanent Link to Using Environment variables inside a VBScript script" rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-environment-variables-inside-a-vbscript-script/">Using Environment variables inside a VBScript script</a>. The script worked like a champ and got me through several tight binds in gathering information, hopefully it has for you as well. However, it has one flaw&#8230; it doesn&#8217;t work on a remote system! In fact, it only works on the system that the script is running on.</p>
<p>So, I had to recently go back to the drawing board and create a script and series of functions that would work remotely so that I could wrap it in a function to gather information from a bunch of servers. I also Learned a thing or two in the process!</p>
<p>First, The script uses the Win32_environment classes in WMI and this class returns ALL envirnment variables for ALL users. That threw me for a loop when I saw multiple PATH environment variables&#8211; some that were different. Second, The search is case sensitive without using the SQL % wildcards (I didn&#8217;t need them, so implementing that is left up to you the reader.)</p>
<p>I have the three functions I wrote, that are really variations of one another below. Just add them to your script and call them with the appropriate values and you should be in business!</p>
<p><span style="color: #0000ff">Function RemoteAllEnvironmentVariables(ServerName)<br />
     &#8216;Lists all environment variables on the remote system<br />
     </span><span style="color: #0000ff">Dim objWMIService, colItems, objItem<br />
 <br />
     RemoteAllEnvironmentVariables = &#8220;&#8221;<br />
     Set objWMIService = GetObject(&#8220;winmgmts:\\&#8221; &amp; ServerName &amp; &#8220;\root\cimv2&#8243;)<br />
     Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_Environment&#8221;)<br />
     For Each objItem in colItems<br />
         RemoteAllEnvironmentVariables = RemoteAllEnvironmentVariables &amp; objitem.name &amp; &#8220;: &#8221; &amp; objItem.VariableValue &amp; VbCrLf<br />
     Next<br />
End Function</span></p>
<p><span style="color: #0000ff">Function RemoteAllEnvironmentVariablesVariations(ServerName, VariableName)<br />
     &#8216;Lists all environment variables on the remote system, along with every case variation<br />
     Dim objWMIService, colItems, objItem<br />
 <br />
     RemoteAllEnvironmentVariablesVariations = &#8220;&#8221;<br />
     Set objWMIService = GetObject(&#8220;winmgmts:\\&#8221; &amp; ServerName &amp; &#8220;\root\cimv2&#8243;)<br />
     Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_Environment&#8221;)<br />
     For Each objItem in colItems<br />
         If UCase(objItem.name) = UCase(VariableName) Then<br />
         RemoteAllEnvironmentVariablesVariations = RemoteAllEnvironmentVariablesVariations &amp; objitem.name &amp; &#8220;: &#8221; &amp; objItem.VariableValue &amp; VbCrLf<br />
         End If<br />
     Next<br />
End Function</span></p>
<p> <br />
<span style="color: #0000ff">Function RemoteEnvironmentVariable(ServerName, VariableName)<br />
     &#8217;Lists all environment variables on the remote system, exactly as you typed it in the function call.<br />
     Dim objWMIService, colItems, objItem<br />
 <br />
     RemoteEnvironmentVariable = &#8220;&#8221;<br />
     Set objWMIService = GetObject(&#8220;winmgmts:\\&#8221; &amp; ServerName &amp; &#8220;\root\cimv2&#8243;)<br />
     Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_Environment Where Name = &#8216;&#8221; &amp; VariableName &amp; &#8220;&#8216;&#8221;)<br />
     For Each objItem in colItems<br />
         RemoteEnvironmentVariable = objItem.VariableValue<br />
     Next<br />
End Function</span></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/retrieve-environment-variable-values-from-a-remote-system-with-wmi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
