<?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; uptime</title>
	<atom:link href="http://vbscriptblog.com/category/vbscript/wmi/uptime/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>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>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>
	</channel>
</rss>

