<?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>vbscriptblog.com &#187; wmi</title>
	<atom:link href="http://vbscriptblog.com/tag/wmi/feed/" rel="self" type="application/rss+xml" />
	<link>http://vbscriptblog.com</link>
	<description>Scripting for Windows Sysadmins</description>
	<lastBuildDate>Wed, 11 Apr 2012 07:23:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>VBscript: vbscript to enumerate the printers of Active Directory users and write the results to a file</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/#comments</comments>
		<pubDate>Fri, 27 May 2011 14:11:57 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[printers]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=1097</guid>
		<description><![CDATA[Today&#8217;s script is made for Hassan. He asked me to do a script that enumerates the printers of each user. Although that sounds easy it is a little complicated. The printers of each user are saved in the user profile (in the ntuser.dat file to be precisely). The easiest way to get a list of [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s script is made for <a href="http://deludi.nl/blog/vbscript/active-directory/sendasrights/active-directory-vbscript-to-enumerate-the-send-as-rights-on-a-user-or-resource-account/">Hassan</a>.<br />
He asked me to do a script that enumerates the printers of each user. Although that sounds easy it is a little complicated.</p>
<p>The printers of each user are saved in the user profile<br />
(in the ntuser.dat file to be precisely).<br />
The easiest way to get a list of printers per user is to add a small script to the <a href="http://technet.microsoft.com/en-us/library/cc758918%28WS.10%29.aspx">logon script</a> (can also be done with a <a href="http://en.wikipedia.org/wiki/Group_Policy">group policy</a>).<br />
The script below is such a script.<br />
It is very compact and can be run under the users credentials.<br />
The script does a WMI query (the <a href="http://msdn.microsoft.com/en-us/library/aa394363%28v=vs.85%29.aspx">Win32_Printer Class</a>) for the printers and writes the output to a file.<br />
Unfortunately we cannot use the same file for all users because of potential &#8220;file locking&#8221; problems.<br />
This can be adressed by using a database but that is beyond the scope of this article.</p>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* change the UNC path (&#8220;\srvXXXlogfiles&#8221;) in the LogToFile function on line 19 to your UNC path<br />
* save the script (for example c:tempprinters.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript printers.vbs&#8221; (without quotes) and enter</p>
<p>To run the script as a logon script you can copy the script to the netlogon share or another user accessible location.</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : printers.vbs
' Description : script to enumerate the printers of Active Directory users and write the results to a file
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 27-05-2011

Set objNetwork = CreateObject(&quot;Wscript.Network&quot;)
Set objWMIService = GetObject(&quot;winmgmts:\.rootcimv2&quot;)
Set colPrinters = objWMIService.ExecQuery(&quot;Select * From Win32_Printer&quot;)
For Each objPrinter in colPrinters
    LogToFile(objNetwork.UserDomain &amp; &quot;&quot; &amp; objNetwork.UserName &amp; &quot; ; &quot; &amp; objPrinter.Name)
Next
Set colPrinters = Nothing
Set objWMIService = Nothing
Set objNetwork = Nothing 

Function LogToFile(Message)
Set ObjFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objTextFile = ObjFSO.OpenTextFile(&quot;\srvXXXlogfiles&quot; &amp; objNetwork.UserName &amp; Date &amp; &quot;.txt&quot;,8,True)
objTextFile.WriteLine Message
objTextFile.Close
Set objTextFile = Nothing
Set ObjFSO = Nothing
End Function
</pre>
<p>When you have problems/questions with the script please post a reply.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fprinters%2Fvbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/"  data-text="VBscript: vbscript to enumerate the printers of Active Directory users and write the results to a file" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VBscript and WMI: VBscript to find files with specific extensions and creation date on remote servers</title>
		<link>http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 14:27:40 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[files]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=993</guid>
		<description><![CDATA[I recently got the question to find all Symantec BESR snaphot files older than 2 weeks (the retention period) on the company servers. This so that we could clear up some space on the snapshot volumes. I decided to make a general purpose script of it. You can use it to find old logfiles, etc. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got the question to find all <a href="http://www.symantec.com/business/backup-exec-system-recovery-server-edition">Symantec BESR</a> snaphot files older than 2 weeks (the retention period) on the company servers. This so that we could clear up some space on the snapshot volumes.<br />
I decided to make a general purpose script of it.<br />
You can use it to find old logfiles, etc.</p>
<p>What the script does:</p>
<ul>
<li>create an array with all server you want to check (replace srv001, etc with your server names)</li>
<li>create a variable with a date of 2 weeks ago (Date -14)(can easily be changed in 30, 60 days ago)</li>
<li>change the variable date to the UTC date of 14 days ago (because WMI works with UTC dates)</li>
<li>for each server in the array</li>
<li>make a wmi connection</li>
<li>query for files with specific extensions and a creation date older than 14 days ago</li>
<li>in this example i took .txt and .csv extensions, change them in whatever filetype you want</li>
</ul>
<p>The script is tested in an win2003 environment.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>replace the strings &#8216;srv001&#8242; and &#8216;srv002&#8242; with the name of your exchange server</li>
<li>replace the extensions &#8216;txt&#8217; and &#8216;csv with the extensions you need</li>
<li>save the script (for example c:tempfindoldfileswithspecificextensions.vbs)(or something shorter..)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript findoldfileswithspecificextensions.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>When you want the output in a file please give this command:</p>
<p>&#8220;cscript findoldfileswithspecificextensions.vbs &gt; findoldfileswithspecificextensions.txt&#8221; (again without the quotes)</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : findoldfileswithspecificextensions.vbs
' Description : VBscript to find files with specific extensions and creation date on remote servers
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 21-03-2011
' Level: intermediate

arrServers = Array(&quot;srv001&quot;,&quot;srv002&quot;)
strDate = Date - 14
Set objDateToUtcDate = CreateObject(&quot;WbemScripting.SWbemDateTime&quot;)
objDateToUtcDate.SetVarDate(strDate)

For Each Server in arrServers
	Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\&quot; &amp; Server &amp; &quot;rootcimv2&quot;)
	Set colFiles = objWMIService.ExecQuery(&quot;Select * from CIM_DataFile where (Extension = 'txt' or Extension = 'csv') and CreationDate &lt; '&quot; &amp; objDateToUtcDate &amp; &quot;'&quot;)
	For Each objFile in colFiles
		Wscript.Echo objFile.Name
	Next
	Set colFiles = Nothing
	Set objWMIService = Nothing
Next
Set objDateToUtcDate = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Fwmi%2Ffiles-wmi%2Fvbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/"  data-text="VBscript and WMI: VBscript to find files with specific extensions and creation date on remote servers" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VBscript and WMI: VBscript to enumerate all mailboxes on a given Exchange server</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 13:07:47 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[exchange]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[adsi]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=911</guid>
		<description><![CDATA[This script is made for Jeff Doty. What the script does: make a wmi connection to a given exchange server and create a list of the mailboxes and their size The script is tested in an win2003/exchange2003 environment. Follow the next steps to run the script (admin rights needed): copy and paste the script in [...]]]></description>
			<content:encoded><![CDATA[<p>This script is made for <a href="http://deludi.nl/blog/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/comment-page-1/#comment-328">Jeff Doty</a>.</p>
<p>What the script does:</p>
<ul>
<li>make a wmi connection to a given exchange server and create a list of the mailboxes and their size</li>
</ul>
<p>The script is tested in an win2003/exchange2003 environment.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>replace the string &#8216;srv001&#8242; with the name of your exchange server</li>
<li>save the script (for example c:tempmailboxes.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript mailboxes.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>When you want the output in a file please give this command:</p>
<p>&#8220;cscript mailboxes.vbs &gt; mailboxes.txt&#8221; (again without the quotes)</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : mailboxes.vbs
' Description : script to enumerate all mailboxes on a given Exchange server
' Author : dirk adamsky - deludi bv
' Version : 1.10 (changed/corrected based on input by Mike)
' Date : 23-03-2011
' Level: intermediate

strServer = &quot;srv001&quot;
Const MinimalSize = 2048 'size in MB
Set objWMIExchange = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!//&quot; &amp; strServer &amp; &quot;/root/MicrosoftExchangeV2&quot;)
Set colExchangeMailboxes = objWMIExchange.InstancesOf(&quot;Exchange_Mailbox&quot;)
For Each objExchangeMailbox in colExchangeMailboxes
    If (Left(objExchangeMailbox.StorageGroupName, 5) &lt;&gt; &quot;Recov&quot;) And (Round(objExchangeMailbox.Size/1024,0) &gt; MinimalSize) Then
		Wscript.Echo objExchangeMailbox.MailboxDisplayName &amp; &quot; ; &quot; &amp;_
			Round(objExchangeMailbox.Size/1024,0) &amp; &quot; MB&quot;
	End If
Next
Set colExchange_Mailboxes = Nothing
Set objWMIExchange = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fexchange-active-directory-vbscript%2Fvbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/"  data-text="VBscript and WMI: VBscript to enumerate all mailboxes on a given Exchange server" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path and a given level of subfolders</title>
		<link>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 11:39:09 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[ntfsrights]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[subfolders]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=779</guid>
		<description><![CDATA[Today I have extended the previous script: it now also enumerates the NTFS rights of subfolders below the share. As a bonus the level of subfolders can be set Follow the next steps to run the script (admin rights needed for the WMI connection): copy and paste the script in your favorite text editor save [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have extended the <a href="http://deludi.nl/blog/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/">previous script:</a><br />
it now also enumerates the NTFS rights of subfolders below the share.<br />
As a bonus the level of subfolders can be set</p>
<p>Follow the next steps to run the script (admin rights needed for the <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" target="_blank">WMI</a> connection):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:\temp\uncacl2.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:\temp&#8221;</li>
<li>give &#8220;cscript uncacl2.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : uncacl2.vbs
' Description : script to enumerate the ntfs rights of a given UNC path and a given level of subfolders
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 22-10-2010

strUNCPathName = InputBox(&quot;please supply the UNC path to the shared folder&quot;)
strSubfolderLevel = InputBox(&quot;please supply the subfolder depth (1,2,etc.)&quot;)
arrUNC = split(strUNCPathName,&quot;\&quot;)
If Ubound(arrUNC) &gt; 3 Then
strRightPartOfPath = Mid(strUNCPathName,(Instr(strUNCPathName,arrUNC(4)) -1))
End If
Set objWMI = GetObject(&quot;winmgmts:\\&quot; &amp; arrUNC(2) &amp; &quot;\root\CIMV2&quot;)
Set objFileShare = objWMI.Get(&quot;Win32_Share.Name=&quot;&quot;&quot; &amp; arrUNC(3) &amp; &quot;&quot;&quot;&quot;)
If Right(arrUNC(3),1) = &quot;$&quot; And Len(arrUNC(3)) = 2 Then
strPath = objFileShare.Path &amp; Mid(strRightPartOfPath,2)
Else
strPath = objFileShare.Path &amp; strRightPartOfPath
End If
ShowACL strPath
ViewSubFolders strPath, strSubfolderLevel
Set objFileShare = Nothing
Set objWMI = Nothing

Function ViewSubfolders(strFolder, strMaxlevel)
Set colSubfolders = objWMI.ExecQuery(&quot;Associators Of {Win32_Directory.Name='&quot; &amp; strFolder &amp; &quot;'} &quot; &amp;_
&quot;Where AssocClass = Win32_Subdirectory ResultRole = PartComponent&quot;)
If strMaxlevel &gt;= 1 Then
    For Each SubFolder in colSubfolders
        wscript.echo SubFolder.Name
        ShowACL SubFolder.Name
        ViewSubFolders SubFolder.Name, (strMaxlevel - 1)
    Next
End If
Set colSubfolders = Nothing
End Function

Function ShowACL(strDir)
Set objFolderSecuritySettings = objWMI.Get(&quot;Win32_LogicalFileSecuritySetting.Path='&quot; &amp; strDir &amp; &quot;'&quot;)
objFolderSecuritySettings.GetSecurityDescriptor objSD
For Each objAce in objSD.DACL
    Select Case objAce.AccessMask
        Case 1179817
            strRights = &quot;read-only&quot;
        Case 2032127
            strRights = &quot;full-control&quot;
        Case 1245631
            strRights = &quot;change&quot;
    End Select
Wscript.Echo strUNCPathName &amp; &quot; ; &quot; &amp; strDir &amp; &quot; ; &quot; &amp; objAce.Trustee.Domain &amp; &quot; ; &quot; &amp; objAce.Trustee.Name &amp; &quot; ; &quot; &amp; strRights
Next
Set objSD = Nothing
Set objFolderSecuritySettings = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Fwmi%2Fntfsrights%2Factive-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/"  data-text="Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path and a given level of subfolders" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path</title>
		<link>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 11:29:22 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[ntfsrights]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[GetSecurityDescriptor]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[ntfs rights]]></category>
		<category><![CDATA[unc path]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[Win32_LogicalFileSecuritySetting]]></category>
		<category><![CDATA[Win32_Share.Name]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=763</guid>
		<description><![CDATA[Last weeks I haven&#8217;t done much scripting (lack of inspiration, bad weather, etc.). But today I finished a script that I wanted to make for quite some time. The script enumerates the NTFS rights (to be more precisely a subset of the possible NTFS rights: read, change and full-control) of a given UNC path. What [...]]]></description>
			<content:encoded><![CDATA[<p>Last weeks I haven&#8217;t done much scripting (<a target="_blank" href="http://www.galactic-guide.com/articles/6R34.html">lack of inspiration</a>, bad weather, etc.).<br />
But today I finished a script that I wanted to make for quite some time.<br />
The script enumerates the <a target="_blank" href="http://www.windowsecurity.com/articles/Understanding-Windows-NTFS-Permissions.html">NTFS rights</a> (to be more precisely a subset of the possible NTFS rights: read, change and full-control) of a given <a target="_blank" href="http://en.wikipedia.org/wiki/Path_%28computing%29">UNC path</a>.<br />
What the script does:</p>
<ul>
<li>ask for a UNC path</li>
<li>split the UNC path and put the substrings in an array</li>
<li>make a wmi connection to the target server</li>
<li>find the absolut path of the share</li>
<li>enumerate the acl&#8217;s</li>
<li>close the used objects</li>
</ul>
<p>Follow the next steps to run the script  (admin rights needed for the <a target="_blank" href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation">WMI</a> connection):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:tempuncacl.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript uncacl.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : uncacl.vbs
' Description : script to enumerate the ntfs rights of a given UNC path
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 20-10-2010

strUNCPathName = InputBox(&quot;please supply the UNC path to the shared folder&quot;)
arrUNC = split(strUNCPathName,&quot;&quot;)
If Ubound(arrUNC) &gt; 3 Then
	strRightPartOfPath = Mid(strUNCPathName,(Instr(strUNCPathName,arrUNC(4)) -1))
End If
Set objWMI = GetObject(&quot;winmgmts:\&quot; &amp; arrUNC(2) &amp; &quot;rootCIMV2&quot;)
Set objFileShare = objWMI.Get(&quot;Win32_Share.Name=&quot;&quot;&quot; &amp; arrUNC(3) &amp; &quot;&quot;&quot;&quot;)
If Right(arrUNC(3),1) = &quot;$&quot; And Len(arrUNC(3)) = 2 Then
	strPath = objFileShare.Path &amp; Mid(strRightPartOfPath,2)
Else
	strPath = objFileShare.Path &amp; strRightPartOfPath
End If
Set objFolderSecuritySettings = objWMI.Get(&quot;Win32_LogicalFileSecuritySetting.Path='&quot; &amp; strPath &amp; &quot;'&quot;)
objFolderSecuritySettings.GetSecurityDescriptor objSD
For Each objAce in objSD.DACL
	Select Case objAce.AccessMask
		Case 1179817
			strRights = &quot;read-only&quot;
		Case 2032127
			strRights = &quot;full-control&quot;
		Case 1245631
			strRights = &quot;change&quot;
	End Select
	Wscript.Echo strUNCPathName &amp; &quot; ; &quot; &amp; strPath &amp; &quot; ; &quot; &amp; objAce.Trustee.Domain &amp; &quot; ; &quot; &amp; objAce.Trustee.Name &amp; &quot; ; &quot; &amp; strRights
Next
Set objSD = Nothing
Set objFolderSecuritySettings = Nothing
Set objFileShare = Nothing
Set objWMI = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<p>[adrotate group="3"] </p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Fwmi%2Fntfsrights%2Factive-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/"  data-text="Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate the system uptime of all servers in Active Directory V2</title>
		<link>http://vbscriptblog.com/vbscript/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 06:13:40 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[active directory]]></category>
		<category><![CDATA[uptime]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>
		<category><![CDATA[alive]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=654</guid>
		<description><![CDATA[The script for today is created for Paul. It is an extension of the previous server uptime script. The uptime is now formatted in: xx days, xx hours, xx minutes. Follow the next steps to run the script (admin rights needed for the WMI connections): copy and paste the script in your favorite text editor [...]]]></description>
			<content:encoded><![CDATA[<p>The script for today is created for <a href="http://deludi.nl/blog/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/comment-page-1/#comment-98">Paul</a>.<br />
It is an extension of the <a href="http://deludi.nl/blog/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/">previous server uptime script</a>.<br />
The uptime is now formatted in: xx days, xx hours, xx minutes.</p>
<p><br class="spacer_" /></p>
<p>Follow the next steps to run the script  (admin rights needed for the WMI connections):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:tempserveruptimev2.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript serveruptimev2.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : serveruptimev2.vbs
' Description : script to enumerate the system uptime of all servers in Active Directory V2
' Author : dirk adamsky - deludi bv
' Version : 2.00
' Date : 15-07-2010

Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;
strFilter = &quot;(&amp;(objectCategory=computer)(operatingSystem=*server*))&quot;
strAttributes = &quot;name&quot;

strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 30
adoCommand.Properties(&quot;Cache Results&quot;) = False
Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
	On Error Resume Next
	strHostname = adoRecordset.Fields(&quot;name&quot;).Value
	If CheckStatus(strHostname) = False Then
		Wscript.Echo strHostname &amp; &quot; does not reply&quot;
	Else
		Wscript.Echo strHostname &amp; &quot; is up for &quot; &amp; GetUptime(strHostname)
	End If
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

Function CheckStatus(strAddress)
	Dim objPing, objRetStatus
	Set objPing = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}&quot;).ExecQuery _
      (&quot;select * from Win32_PingStatus where address = '&quot; &amp; strAddress &amp; &quot;'&quot;)
	For Each objRetStatus In objPing
        If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode &lt;&gt; 0 Then
			CheckStatus = False
        Else
			CheckStatus = True
        End If
    Next
	Set objPing = Nothing
End Function 

Function GetUptime(strServer)
	Set objDateTime = CreateObject(&quot;WbemScripting.SWbemDateTime&quot;)
	Set objWMIService = GetObject(&quot;winmgmts:\&quot; &amp; strServer &amp; &quot;rootcimv2&quot;)
	Set colOperatingSystems = objWMIService.ExecQuery(&quot;Select * from Win32_OperatingSystem&quot;)
	For Each objOS in colOperatingSystems
		objDateTime.Value = objOS.LastBootUpTime
		strMinutes = DateDiff(&quot;n&quot;, objDateTime.GetVarDate, Now)
		If strMinutes =&lt; 0 Then
			strUptime = &quot;0 days, 0 hours, 0 minutes&quot;
		Else
			strUptime = &quot;&quot;
			If strMinutes &gt;= 1440 Then
				strUptime = Round(strMinutes1440,0) &amp; &quot; days,&quot;
			End If
			strMinutes = strMinutes Mod 1440
			If strMinutes &gt;= 60 Then
				strUptime = strUptime &amp; (strMinutes60) &amp; &quot; hours,&quot;
			End If
			strMinutes = strMinutes Mod 60
			GetUptime = strUptime &amp; strMinutes &amp; &quot; minutes&quot;
		End If
	Next
	Set colOperatingSystems = Nothing
	Set objWMIService = Nothing
	Set objDateTime = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<p>[adrotate group="2" banner="3"] </p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2/"  data-text="Active Directory and WMI: VBscript to enumerate the system uptime of all servers in Active Directory V2" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory-v2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WMI: Vbscript to enumerate who is connected to a domain controller</title>
		<link>http://vbscriptblog.com/vbscript/wmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 13:39:44 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[connections]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>
		<category><![CDATA[adsi]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[connected]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=575</guid>
		<description><![CDATA[Ok let&#8217;s do another script. The script shows you who is connected to a domain controller. This is accomplished through the WMI class &#8220;Win32_ServerSession&#8221;. Enumerated are: prew2k username, hostname, workstation os and the time connected. The script needs to be run as admin because of the wmi connection to the server. Follow the next steps [...]]]></description>
			<content:encoded><![CDATA[<p>Ok let&#8217;s do another script.<br />
The script shows you who is connected to a domain controller.<br />
This is accomplished through the WMI class &#8220;Win32_ServerSession&#8221;.<br />
Enumerated are: prew2k username, hostname, workstation os and the time connected.<br />
The script needs to be run as admin because of the wmi connection to the server.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>change the value of strServer to the name of your domain controller (example: strServer = &#8220;srv001&#8243;)</li>
<li>save the script (for example c:tempconnected.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript connected.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : connected.vbs
' Description : script to enumerate who is connected to a domain controller
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 22-04-2010
' Level: intermediate

strServer = &quot;domaincontroller&quot;
Set objWMI = GetObject(&quot;winmgmts://&quot; &amp; strServer &amp; &quot;/rootcimv2&quot;)
Set objInstances = objWMI.InstancesOf(&quot;Win32_ServerSession&quot;,48)

For Each objInstance in objInstances
    With objInstance
        WScript.Echo .UserName &amp; &quot; ; &quot; &amp; .ComputerName &amp; &quot; ; &quot; &amp; .ClientType &amp;_
		.Name &amp; &quot; ; &quot; &amp; Round(.ActiveTime/60,0) &amp; &quot; minutes connected&quot;
    End With
Next

Set objInstances = Nothing
Set objWMI = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Fwmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/wmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/wmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller/"  data-text="WMI: Vbscript to enumerate who is connected to a domain controller" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/wmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi-vbscript-to-enumerate-who-is-connected-to-a-domain-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate all mailboxes and their size in your AD domain</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 09:59:37 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[exchange]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[mailbox size]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=523</guid>
		<description><![CDATA[Today&#8217;s script is an extension of yesterday&#8217;s script. What the script does: get all exchange servers from your AD domain make a wmi connection to each server and create a list of the mailboxes and their size The script is tested in an win2003/exchange2003 environment. Follow the next steps to run the script (admin rights [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s script is an extension of <a href="http://deludi.nl/blog/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-vbscript-to-enumerate-all-exchange-servers-in-your-ad-domain/">yesterday&#8217;s script</a>.<br />
What the script does:</p>
<ul>
<li>get all exchange servers from your AD domain</li>
<li>make a wmi connection to each server and create a list of the mailboxes and their size</li>
</ul>
<p>The script is tested in an win2003/exchange2003 environment.</p>
<p>Follow the next steps to run the script (admin rights needed):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:\temp\listallmailboxes.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:\temp&#8221;</li>
<li>give &#8220;cscript listallmailboxes.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : listallmailboxes.vbs
' Description : script to enumerate all mailboxes and their size in your AD domain
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 07-04-2010
' Level: intermediate

Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;configurationnamingcontext&quot;) &amp; &quot;&gt;&quot;
strFilter = &quot;(objectCategory=msExchExchangeServer)&quot;
strAttributes = &quot;name&quot;

strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 30
adoCommand.Properties(&quot;Cache Results&quot;) = False

Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
	Set objWMIExchange = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!//&quot;&amp;_
	adoRecordset.Fields(&quot;name&quot;).Value &amp; &quot;/root/MicrosoftExchangeV2&quot;)
    Set colExchangeMailboxes = objWMIExchange.InstancesOf(&quot;Exchange_Mailbox&quot;)
    For Each objExchangeMailbox in colExchangeMailboxes
        If Left(objExchangeMailbox.StorageGroupName, 5) &lt;&gt; &quot;Recov&quot; Then
			Wscript.Echo adoRecordset.Fields(&quot;name&quot;).Value &amp; &quot; ; &quot; &amp; objExchangeMailbox.MailboxDisplayName &amp; &quot; ; &quot; &amp;_
			Round(objExchangeMailbox.Size/1024,0) &amp; &quot; MB&quot;
		End If
	Next
	Set colExchange_Mailboxes = Nothing
	Set objWMIExchange = Nothing
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fexchange-active-directory-vbscript%2Factive-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/"  data-text="Active Directory and WMI: VBscript to enumerate all mailboxes and their size in your AD domain" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate the system uptime of all servers in Active Directory</title>
		<link>http://vbscriptblog.com/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 14:15:17 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[uptime]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[alive]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=441</guid>
		<description><![CDATA[In large Active Directory environments it is useful to know the uptime of each server (for patches, etc.). This script lists all servers in Active Directory, checks if they are alive and if so check their uptime. It can be run as a scheduled task (for example every day or week). Follow the next steps [...]]]></description>
			<content:encoded><![CDATA[<p>In large Active Directory environments it is useful to know the uptime of each server (for patches, etc.).<br />
This script lists all servers in Active Directory, checks if they are alive and if so check their uptime.<br />
It can be run as a scheduled task (for example every day or week).</p>
<p>Follow the next steps to run the script  (admin rights needed for the WMI connections):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:tempserveruptime.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript serveruptime.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : serveruptime.vbs
' Description : script to monitor all servers in Active Directory
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 17-03-2010

Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;
strFilter = &quot;(&amp;(objectCategory=computer)(operatingSystem=*server*))&quot;
strAttributes = &quot;name&quot;

strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 30
adoCommand.Properties(&quot;Cache Results&quot;) = False
Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
	strHostname = adoRecordset.Fields(&quot;name&quot;).Value
	If CheckStatus(strHostname) = False Then
		Wscript.Echo strHostname &amp; &quot; does not reply&quot;
	Else
		Wscript.Echo strHostname &amp; &quot; is up for &quot; &amp; GetUptime(strHostname) &amp; &quot; days&quot;
	End If
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

Function CheckStatus(strAddress)
	Dim objPing, objRetStatus
	Set objPing = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}&quot;).ExecQuery _
      (&quot;select * from Win32_PingStatus where address = '&quot; &amp; strAddress &amp; &quot;'&quot;)
	For Each objRetStatus In objPing
        If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode &lt;&gt; 0 Then
			CheckStatus = False
        Else
			CheckStatus = True
        End If
    Next
	Set objPing = Nothing
End Function 

Function GetUptime(strServer)
	Set objDateTime = CreateObject(&quot;WbemScripting.SWbemDateTime&quot;)
	Set objWMIService = GetObject(&quot;winmgmts:\&quot; &amp; strServer &amp; &quot;rootcimv2&quot;)
	Set colOperatingSystems = objWMIService.ExecQuery(&quot;Select * from Win32_OperatingSystem&quot;)
	For Each objOS in colOperatingSystems
		objDateTime.Value = objOS.LastBootUpTime
		GetUptime = DateDiff(&quot;d&quot;, objDateTime.GetVarDate, Now)
	Next
	Set colOperatingSystems = Nothing
	Set objWMIService = Nothing
	Set objDateTime = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<p>[adrotate group="3"] </p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Fwmi%2Fuptime%2Factive-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/"  data-text="Active Directory and WMI: VBscript to enumerate the system uptime of all servers in Active Directory" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi/uptime/active-directory-and-wmi-vbscript-to-enumerate-the-system-uptime-of-all-servers-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to enumerate the last logon of all AD users and a lot of user attributes V2</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/lastlogon-active-directory-vbscript/active-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/lastlogon-active-directory-vbscript/active-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 13:03:57 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[lastlogon]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[bias]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[lastlogontimestamp]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[Win32_TimeZone]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=421</guid>
		<description><![CDATA[This script is a further development of my previous lastlogon script. Changes are: time bias with wmi, less code, array based attributes. By adding extra attributes to the arrAttributes array you can expand the output. Follow the next steps to run the script (no admin rights needed): * open your favorite text editor * copy [...]]]></description>
			<content:encoded><![CDATA[<p>This script is a further development of my <a href="http://deludi.nl/blog/category/vbscript/active-directory/lastlogon-active-directory-vbscript/">previous lastlogon script.</a><br />
Changes are: time bias with wmi, less code, array based attributes.<br />
By adding extra attributes to the arrAttributes array you can expand the output.</p>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* save the script (for example c:\temp\enumerate-lastlogon-details2.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript enumerate-lastlogon-details2.vbs&#8221; (without quotes) and enter</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : enumerate-lastlogon-details2.vbs
' Description : script to enumerate the last logon of all AD users and a lot of user attributes V2
' Author : dirk adamsky - deludi bv
' Version : 2.00
' Date : 12-03-2010
' Level : advanced

intBias = TimeZoneBias
arrAttributes = Array(&quot;lastLogonTimeStamp&quot;,&quot;displayname&quot;,&quot;mail&quot;)

Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;defaultNamingContext&quot;) &amp; &quot;&gt;&quot;
Set objRootDSE = Nothing

strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user))&quot;
strAttributes = Join(arrAttributes,&quot;,&quot;)
Wscript.Echo Join(arrAttributes,&quot;;&quot;)
strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 30
adoCommand.Properties(&quot;Cache Results&quot;) = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
	On Error Resume Next
	strTempOutput = &quot;&quot;
	For i = 1 To Ubound(arrAttributes)
		strTempOutput =  strTempOutput &amp; &quot; ; &quot; &amp; adoRecordset.Fields(arrAttributes(i)).Value
		strOutput = Mid(Ltrim(strTempOutput),3)
	Next
	Set objDate = adoRecordset.Fields(arrAttributes(0)).Value
	If (Err.Number &lt;&gt; 0) Then
        dtmDate = #1/1/1601#
    Else
		dtmDate = ((((objDate.Highpart * (2^32)) + objDate.LowPart)/(600000000 - intBias))/1440) + #1/1/1601#
	End If
	Set objDate = Nothing
	Wscript.Echo strOutput &amp; &quot; ; &quot; &amp; dtmDate
	adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

Function TimeZoneBias
	strComputer = &quot;.&quot;
	Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\cimv2&quot;)
	Set colTimeZone = objWMIService.ExecQuery(&quot;Select * from Win32_TimeZone&quot;)
	For Each objTimeZone in colTimeZone
		TimeZoneBias = objTimeZone.Bias
	Next
	Set colTimeZone = Nothing
	Set objWMIService = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Flastlogon-active-directory-vbscript%2Factive-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/lastlogon-active-directory-vbscript/active-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/lastlogon-active-directory-vbscript/active-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2/"  data-text="Active Directory: VBscript to enumerate the last logon of all AD users and a lot of user attributes V2" data-count="horizontal" data-via="dirkadamsky"></a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/lastlogon-active-directory-vbscript/active-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/lastlogon-active-directory-vbscript/active-directory-vbscript-to-enumerate-the-last-logon-of-all-ad-users-and-a-lot-of-user-attributes-v2/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

