<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://gilliath.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fgilliath.spaces.live.com%2fcategory%2fScripting%2b-%2bvbscript%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Gilliath: Scripting - vbscript</title><description /><link>http://Gilliath.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catScripting%2b-%2bvbscript</link><language>en-US</language><pubDate>Mon, 06 Oct 2008 20:07:10 GMT</pubDate><lastBuildDate>Mon, 06 Oct 2008 20:07:10 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://Gilliath.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>226155696666371674</live:id><live:alias>Gilliath</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Local Administrators Group Enumeration</title><link>http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!153.entry</link><description>&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;font size=2&gt;I can't take all the credit for this script, some of it came from a source that I honestly don't remember. I usually find interesting snippets when looking for something else and save them to my /Snippets directory. This project came about because I needed a way to collect the members of a PC's local Administrators group into an SMS database. I could not find a good way to do it so I came up with a 2 step process;&lt;br&gt;&lt;br&gt;1. Run a script on the PC that stuffs a registry key with the members of the local Administrators group&lt;br&gt;2. Configure the SMS_DEF.MOF to collect the registry key.&lt;br&gt;&lt;br&gt;The first part is what this blog post is about; the vbscript. I will start with the following snippet:&lt;br&gt;&lt;br&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Dim oNetwork, sComputer, oLocalGroup, aUsers&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Set oNetwork = CreateObject(&amp;quot;Wscript.Network&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;sComputer = oNetwork.ComputerName&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Set oLocalGroup = GetObject(&amp;quot;WinNT://&amp;quot; &amp;amp; sComputer &amp;amp; &amp;quot;/Administrators,group&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;For Each oMember In oLocalGroup.Members&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;    aUsers = Split(oMember.AdsPath, &amp;quot;/&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;    WScript.Echo aUsers(UBOUND(aUsers)-1) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; aUsers(UBOUND(aUsers))&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace"&gt;&lt;span style="font-weight:bold"&gt;Next&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;Very simple really. When the AdsPath of a user is returned, it looks like this WinNT://XXX/YYY/ZZZ if it is a local account (user or group) or WinNT://XXX/ZZZ if it is a domain account (user or group). XXX = Workgroup or Domain name, YYY = Server name, ZZZ = account name (user or group). You will notice that if you take each line and split it into elements separated by the forward slash '/', the last two elements are always what we want.  The line  &lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;font size=2&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;    WScript.Echo aUsers(UBOUND(aUsers)-1) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; aUsers(UBOUND(aUsers)) &lt;/span&gt;&lt;span style="font-family:Courier New,Courier,Monospace"&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;takes the second to last and last elements and puts them together in the familiar DOMAIN\Account format. &lt;br&gt;&lt;br&gt;With a little more editing, I was able to stuff the registry with the &amp;quot;rebuilt&amp;quot; account name;&lt;br&gt;&lt;br&gt;&lt;font size=2&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Dim oShell, oFSO, oNetwork, sComputer, oLocalGroup, aUsers&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Set oShell = Wscript.CreateObject(&amp;quot;Wscript.Shell&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Set oFSO = CreateObject(&amp;quot;Scripting.FileSystemObject&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Set oNetwork = CreateObject(&amp;quot;Wscript.Network&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;sComputer = oNetwork.ComputerName&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Set oLocalGroup = GetObject(&amp;quot;WinNT://&amp;quot; &amp;amp; sComputer &amp;amp; &amp;quot;/Administrators,group&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;x = 1&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;For Each oMember In oLocalGroup.Members&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;    aUsers = Split(oMember.AdsPath, &amp;quot;/&amp;quot;)&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;    oShell.RegWrite &amp;quot;HKLM\SYSTEM\MYCOMPANYSINFO\Security\LocalGroup\Administrators\Member&amp;quot; &amp;amp; x, aUsers(UBOUND(aUsers)-1) &amp;amp; &amp;quot;\&amp;quot; &amp;amp; aUsers(UBOUND(aUsers)), &amp;quot;REG_SZ&amp;quot;&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;/span&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;    x = x + 1&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Next&lt;/span&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;br style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;&lt;span style="font-family:Courier New,Courier,Monospace;font-weight:bold"&gt;Wscript.Quit(0)&lt;/span&gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;font size=2&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;font style="font-style:italic;font-weight:bold" size=1&gt;Note that the oShell.RegWrite line is continuous through the &amp;quot;REG_SZ&amp;quot;. This window may have broken it up.&lt;/font&gt;&lt;br&gt;&lt;br&gt;The result is that in the desired registry key, you will have Member1, Member2, etc with their values set to the member name. &lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;font size=2&gt;&lt;span style="font-family:Courier New,Courier,Monospace"&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;-Gill&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;font size=2&gt;&lt;span style="font-family:Courier New,Courier,Monospace"&gt;&lt;span style="font-family:Verdana,Geneva,Arial,Sans-serif"&gt;&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=226155696666371674&amp;page=RSS%3a+Local+Administrators+Group+Enumeration&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=gilliath.spaces.live.com&amp;amp;GT1=Gilliath"&gt;</description><comments>http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!153.entry#comment</comments><guid isPermaLink="true">http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!153.entry</guid><pubDate>Tue, 19 Sep 2006 04:34:26 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://Gilliath.spaces.live.com/blog/cns!32377686BBAE65A!153/comments/feed.rss</wfw:commentRss><wfw:comment>http://Gilliath.spaces.live.com/Blog/cns!32377686BBAE65A!153.entry#comment</wfw:comment><dcterms:modified>2006-09-19T04:34:26Z</dcterms:modified></item></channel></rss>