 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: VBS &#8211; Taking input from one spreadsheet and output to another</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/vbs-taking-input-from-one-spreadsheet-and-output-to-another/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/vbs-taking-input-from-one-spreadsheet-and-output-to-another/</link>
	<description></description>
	<lastBuildDate>Mon, 20 May 2013 02:53:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: chippy088</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vbs-taking-input-from-one-spreadsheet-and-output-to-another/#comment-92210</link>
		<dc:creator>chippy088</dc:creator>
		<pubDate>Tue, 17 May 2011 16:21:45 +0000</pubDate>
		<guid isPermaLink="false">#comment-92210</guid>
		<description><![CDATA[If I have understood the code, I think the problem lies within the
         Sub WriteInfo 

‘Write values to OUTPUT Worksheet
	intWriteRow = 4     this is setting the output line to be always 4 as it is not being used properly within the sub routine

try incrementing writerow at the end of the sub and take out the 
        intWriteRow = 4 line 

and make the variable public. (it is telling the sub to write at line 4 and is not getting incremented as far as i can see, so it keeps writing to line 4, overwriting anything already there.)]]></description>
		<content:encoded><![CDATA[<p>If I have understood the code, I think the problem lies within the<br />
         Sub WriteInfo </p>
<p>‘Write values to OUTPUT Worksheet<br />
	intWriteRow = 4     this is setting the output line to be always 4 as it is not being used properly within the sub routine</p>
<p>try incrementing writerow at the end of the sub and take out the<br />
        intWriteRow = 4 line </p>
<p>and make the variable public. (it is telling the sub to write at line 4 and is not getting incremented as far as i can see, so it keeps writing to line 4, overwriting anything already there.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fsck</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/vbs-taking-input-from-one-spreadsheet-and-output-to-another/#comment-92127</link>
		<dc:creator>fsck</dc:creator>
		<pubDate>Fri, 13 May 2011 21:09:49 +0000</pubDate>
		<guid isPermaLink="false">#comment-92127</guid>
		<description><![CDATA[Anyone? I have updated the code (below).

My problem is that it is only working partially. To summarize, I am using a single workbook containing two worksheets. Worksheet 1 is where the script reads from, and it is just one column with a list of sAMAccountNames. Worksheet 2 is where the script writes the output to for each of the sAMAccountNames after fetching the values from the domain. My problem seems to be that I do not know how to code the Loop such that it increments to the next Row for each of worksheets as it parses through the sAMAccountNames. As a result, the script succeeds only for the first row (reads input from first row in worksheet 1 and writes output to first row in worksheet2) but it does not process the subsequent rows.

Does anyone know how I can accomplish this loop? 

&lt;pre&gt;
&#039; Abridged original remarks from Ralph Mongtomery
&#039; Get User Information NTUser.wsf
&#039; Version 1.0 Created 11-26-2001 by Ralph Montgomery (rmonty@myself.com)

&#039; Alan Kaplan remarks
&#039; 3/23/2009 I have been using this script for a very long time, and have probably hacked
&#039; it beyond recognition. I take neither the credit nor the blame for the clumsy bits...
&#039; I stripped out Win9x stuff, and system info detection, as everyone I know
&#039; using this is at XP or later.

&#039;10/23/2009 added support for and enumeration of UPN

Option Explicit
Dim strUserName, objUserDomain, objGroup, objUser, strGroupList
Dim WshShell, strMessage, strTitle
Dim oDomain, strNTDomain, strVer
Dim strSortedGroups, arrGroupList, strUserList
Dim objChangePwdTrue, objChangePwd, objUserProfile
Dim objPwdExpiresTrue, objFlags, oPwdExpire, strPwdExpires, iAdminCount, dPwdLastChanged, iAutoUnlock
Dim objAcctDisabled, intPwdExpired, objPwdExpiredTrue, objPwdExpires,bAccountDisabled
Dim StrQuote, iBadLogins, iMaxPadPw, iAccountLockout, iPwdAge, intPwdHistory
Dim strExcelPath, objExcel, objSheet, intReadRow, strUserDN, strPassword, xlExcel7, intWriteRow
Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
strVer = &quot;Ver 3.1 &quot;
strQuote = Chr(34)
Dim strNTName, strUPN
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Dim strNTUserName
Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_TYPE_UNKNOWN = 8
Const ADS_NAME_TYPE_CANONICAL = 2

Dim oTrans
Set oTrans = CreateObject(&quot;NameTranslate&quot;)

&#039; Check for required script arguments
If (Wscript.Arguments.Count &lt; 1) Then
    Wscript.Echo &quot;Arguments &lt;FileName&gt; required. For example:&quot; &amp; vbCrLf _
        &amp; &quot;cscript enumaccountpolicies.vbs c:spreadsheet.xls&quot;
    Wscript.Quit(0)
End If

&#039; Pull Environment variables for domain/user
strNTDomain = WshShell.ExpandEnvironmentStrings(&quot;%USERDOMAIN%&quot;)
strNTUserName = ucase(WshShell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;))


	&#039;------------------------------------------MAIN----------------------------------------------
	
	Call Excel
	Call ExcelAddOutputSheet
	Call GetandWriteInfo


	&#039; Format the spreadsheet.
	&#039;objSheet.Range(&quot;A1:A5&quot;).Font.Bold = True
	&#039;objSheet.Select
	&#039;objSheet.Range(&quot;B5&quot;).Select
	&#039;objExcel.ActiveWindow.FreezePanes = True
	&#039;objExcel.Columns(1).ColumnWidth = 20
	&#039;objExcel.Columns(2).ColumnWidth = 30
	
	&#039; Save the spreadsheet and close the workbook.
	objExcel.ActiveWorkbook.SaveAs strExcelPath
	objExcel.ActiveWorkbook.Close
	
	&#039; Quit Excel.
	objExcel.Application.Quit
	
	&#039; Clean up.
	Set objUser = Nothing
	Set objExcel = Nothing
	Set objSheet = Nothing
	
	Wscript.Echo &quot;Done&quot;

	&#039;---------------------------------------------END MAIN-------------------------------------------
	
	

&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;Subs and Functions &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;

Sub Excel  &#039;Bind to Excel object and Workbook

	&#039; Define Workbook Path
	strExcelPath = Wscript.Arguments(0)
	
	&#039; Bind to Excel object
	On Error Resume Next
	Set objExcel = CreateObject(&quot;Excel.Application&quot;)
	If (Err.Number &lt;&gt; 0) Then
	On Error GoTo 0
	Wscript.Echo &quot;Excel application not found&quot;
	Wscript.Quit
	End If
	objExcel.Visible = True
	On Error GoTo 0
	
	&#039; Bind to Workbook
	On Error Resume Next
	objExcel.Workbooks.Open strExcelPath
	If (Err.Number &lt;&gt; 0) Then
	On Error GoTo 0
	Wscript.Echo &quot;Spreadsheet cannot be opened: &quot; &amp; strExcelPath
	Wscript.Quit
	End If
	On Error GoTo 0
End Sub


Sub ExcelReadSheet &#039;Bind to INPUT Worksheet in Workbook
	Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
End Sub


Sub ExcelWritesheet  &#039;Bind to OUTPUT Worksheet in Workbook
	Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
End Sub


Sub ExcelAddOutputSheet &#039;Populate Headings in OUTPUT Worksheet
	
	&#039;Bind to OUTPUT worksheet in current Workbook
	Call ExcelWriteSheet
	&#039;Name Worksheet
	objSheet.Name = &quot;Audit Results&quot;
	&#039;Populate
	objSheet.Cells(1, 1).Value = &quot;Account Attributes&quot;
	objSheet.Cells(1, 2).Value = &quot;Date &amp; Time of Retrieval: &quot; &amp; (NOW())
	objSheet.Cells(3, 1).Value = &quot;Full Name&quot;
	objSheet.Cells(3, 2).Value = &quot;Account Name&quot;
	objSheet.Cells(3, 3).Value = &quot;Description&quot;
	objSheet.Cells(3, 4).Value = &quot;Account Disabled&quot;
	objSheet.Cells(3, 5).Value = &quot;Account Locked Out&quot;
	objSheet.Cells(3, 6).Value = &quot;Bad Logins&quot;
	objSheet.Cells(3, 7).Value = &quot;~Last Logon&quot;
	objSheet.Cells(3, 8).Value = &quot;Max Password Attempts&quot;
	objSheet.Cells(3, 9).Value = &quot;Attempts Left&quot;
	objSheet.Cells(3, 10).Value = &quot;Password Never Expires&quot;
	objSheet.Cells(3, 11).Value = &quot;Password Expired?&quot;
	objSheet.Cells(3, 12).Value = &quot;Password Age&quot;
	objSheet.Cells(3, 13).Value = &quot;Password Last Changed&quot;
	objSheet.Cells(3, 14).Value = &quot;Password Next Change&quot;
	objSheet.Cells(3, 15).Value = &quot;User can Change Password&quot;
	objSheet.Cells(3, 16).Value = &quot;Password Minimum Length&quot;
	objSheet.Cells(3, 17).Value = &quot;Passwords Kept in History&quot;
	objSheet.Cells(3, 18).Value = &quot;Lock-out Time&quot;
	objSheet.Cells(3, 19).Value = &quot;Auto-Unlock Time&quot;
	objSheet.Cells(3, 20).Value = &quot;Group Memberships&quot;
End Sub


Sub GetandWriteInfo  &#039;Reads INPUT Worksheet, Fetches Parameters, and writes to OUTPUT Worksheet

	&#039;Read INPUT Worksheet
	Call ExcelReadSheet
	
	&#039;The first row of the input worksheet is skipped (column headings). 
	&#039;Each row after the first is processed until the first blank entry 
	&#039;in the first column is encountered.
	intReadRow = 2
	Do While objSheet.Cells(intReadRow, 1).Value &lt;&gt; &quot;&quot;
	strUserName = objSheet.Cells(intReadRow, 1).Value
	strNTUserName = strUserName
	On Error Resume Next
	
	&#039;Attempt to bind to the user account
	Set objUser = GetObject(&quot;WinNT://&quot;&amp; strNTDomain &amp; &quot;/&quot; &amp; strNTUserName &amp; &quot;, user&quot;)
	If (Err.Number &lt;&gt; 0) Then
	On Error GoTo 0
	Wscript.Echo &quot;User NOT found: &quot; &amp; strNTUserName 
	
	Else
	
	&#039;&#039;&#039;&#039;&#039;&#039;Fetch Account Parameters&#039;&#039;&#039;&#039;&#039;&#039;
	On Error resume Next
	&#039; Creates the list of groups the user belongs To
	For Each objGroup In objUser.Groups
	If strGroupList = &quot;&quot; Then
	strGroupList = objGroup.Name
	Else
	strGroupList = strGroupList &amp; &quot;, &quot; &amp; objGroup.Name
	End If
	Next
	&#039; Convert strgrouplist to Array
	arrGroupList = Split(strGroupList,&quot;,&quot;)
	&#039;Sort the darn thing
	Quicksort arrGroupList, LBound(arrGroupList), UBound(arrGroupList)
	&#039; Now concatenate arrGroupList into a variable for display
	strSortedGroups = trim(Join(arrGroupList, &quot;, &quot;))
	
	&#039;check for expired password
	intPwdExpired = objUser.Get(&quot;PasswordExpired&quot;)
	If intPwdExpired = 1 Then
	objPwdExpiredTrue = &quot;Yes&quot;
	Else objPwdExpiredTrue = &quot;No&quot;
	End If
	
	&#039;Check for Must Change Password Flag
	objFlags = objUser.Get(&quot;UserFlags&quot;)
	If (objFlags And &amp;H00040) &lt;&gt; 0 Then
	objChangePwdTrue = &quot;No&quot;
	Else objChangePwdTrue = &quot;Yes&quot;
	End If
	
	&#039; Is password set to NEVER expire?
	objPwdExpires = objUser.Get(&quot;UserFlags&quot;)
	If (objPwdExpires And &amp;H10000) &lt;&gt; 0 Then
	objPwdExpiresTrue = &quot;Yes&quot;
	strPwdExpires = &quot;Date Set: &quot;
	Else objPwdExpiresTrue = &quot;No&quot;
	strPwdExpires = &quot;Password Expires: &quot;
	End If
	
	&#039; Is the account disabled?
	If objUser.AccountDisabled = True Then
	bAccountDisabled = &quot;Yes&quot;
	Else bAccountDisabled = &quot;No&quot;
	End If
	
	&#039;How many wrong logins?
	iBadLogins = objUser.BadPasswordAttempts
	
	&#039;Maximum bad password attempts?
	iMaxPadPw = objUser.MaxBadPasswordsAllowed
	
	&#039;Account Lockout Observation Interval
	iAccountLockout = FormatNumber((objUser.LockoutObservationInterval/60), 0)
	
	&#039;How old is the current password?
	iPwdAge = FormatNumber(((objUser.Get(&quot;PasswordAge&quot;)/60)/60)/24, 0)
	
	&#039;Calculate the date the password was last changed
	dPwdLastChanged = CStr(objUser.PasswordExpirationDate - objUser.Get(&quot;MaxPasswordAge&quot;) / (60 * 60 * 24))
	
	iAdminCount = objUser.Get(&quot;AdminCount&quot;)
	
	&#039;Set Profile path to tabs if blank
	objUserProfile = objUser.Profile
	If objUserProfile = &quot;&quot; Then
	objUserProfile= &quot;&lt;None&gt;&quot; &amp; vbTab
	Else objUserProfile = objUserProfile
	End If
	
	&#039;Determine how many passwords are saved
	Set oDomain = GetObject(&quot;WinNT://&quot; &amp; strNTDomain)
	intPwdHistory = oDomain.PasswordHistoryLength
	iAutoUnlock = oDomain.AutoUnlockInterval/60
	
	
	&#039;Bind to OUTPUT Worksheet in current Workbook
	Call ExcelWriteSheet
	&#039;Write results to OUTPUT Worksheet
	Call Writeinfo
	
	End If
	
	&#039;Attempt to process next worksheet rows via Loop
	intReadRow = intReadRow + 1
	&#039;intWriteRow = intWriteRow + 1
	Loop

End Sub 


Sub WriteInfo &#039;Writes Fetched Parameters to OUTPUT Worksheet
	
	&#039;Write values to OUTPUT Worksheet
	intWriteRow = 4
	objSheet.Cells(intWriteRow, 1).Value = objUser.FullName
	objSheet.Cells(intWriteRow, 2).Value = strNTDomain &amp; &quot;&quot; &amp; strNTUserName
	objSheet.Cells(intWriteRow, 3).Value = objUser.Description
	objSheet.Cells(intWriteRow, 4).Value = bAccountDisabled
	objSheet.Cells(intWriteRow, 5).Value = objUser.IsAccountLocked
	objSheet.Cells(intWriteRow, 6).Value = iBadLogins
	objSheet.Cells(intWriteRow, 7).Value = objUser.LastLogin
	objSheet.Cells(intWriteRow, 8).Value = iMaxPadPw
	objSheet.Cells(intWriteRow, 9).Value = iMaxPadPw - iBadLogins
	objSheet.Cells(intWriteRow, 10).Value = objPwdExpiresTrue
	objSheet.Cells(intWriteRow, 11).Value = objPwdExpiredTrue
	objSheet.Cells(intWriteRow, 12).Value = iPwdAge
	objSheet.Cells(intWriteRow, 13).Value = dPwdLastChanged
	objSheet.Cells(intWriteRow, 14).Value = strPwdExpires
	objSheet.Cells(intWriteRow, 15).Value = objChangePwdTrue
	objSheet.Cells(intWriteRow, 16).Value = objUser.PasswordMinimumLength
	objSheet.Cells(intWriteRow, 17).Value = intPwdHistory &amp; &quot; password(s)&quot;
	objSheet.Cells(intWriteRow, 18).Value = iAccountLockout &amp; &quot; minutes&quot;
	objSheet.Cells(intWriteRow, 19).Value = iAutoUnlock &amp; &quot; minutes&quot;
	objSheet.Cells(intWriteRow, 20).Value = strSortedGroups

End Sub


Sub Quicksort(strValues(), ByVal min, ByVal max) &#039;Sorts the items in the array (between the two values you pass in)
	Dim strMediumValue, high, low, i
	
	&#039;If the list has only 1 item, it&#039;s sorted.
	If min &gt;= max Then Exit Sub
	
	&#039; Pick a dividing item randomly.
	i = min + Int(Rnd(max - min + 1))
	strMediumValue = strValues(i)
	
	&#039; Swap the dividing item to the front of the list.
	strValues(i) = strValues(min)
	
	&#039; Separate the list into sublists.
	low = min
	high = max
	Do
	&#039; Look down from high for a value &lt; strMediumValue.
	Do While strValues(high) &gt;= strMediumValue
	high = high - 1
	If high &lt;= low Then Exit Do
	Loop
	
	If high &lt;= low Then
	&#039;The list is separated.
	strValues(low) = strMediumValue
	Exit Do
	End If
	
	&#039;Swap the low and high strValues.
	strValues(low) = strValues(high)
	
	&#039;Look up from low for a value &gt;= strMediumValue.
	low = low + 1
	Do While strValues(low) &lt; strMediumValue
	low = low + 1
	If low &gt;= high Then Exit Do
	Loop
	
	If low &gt;= high Then
	&#039;The list is separated.
	low = high
	strValues(high) = strMediumValue
	Exit Do
	End If
	
	&#039;Swap the low and high strValues.
	strValues(high) = strValues(low)
	Loop &#039;Loop until the list is separated.
	
	&#039;Recursively sort the sublists.
	Quicksort strValues, min, low - 1
	Quicksort strValues, low + 1, max

End Sub


Function GetUPN (strNTName)
	On Error Resume Next
	oTrans.Init ADS_NAME_INITTYPE_GC, &quot;&quot;
	oTrans.Set ADS_NAME_TYPE_UNKNOWN,strNTName
	If Err &lt;&gt; 0 Then
	MsgBox &quot;Unable to lookup &quot; &amp; strNTName,vbCritical + vbOKOnly,&quot;Error&quot;
	WScript.Quit
	End If
	GetUPN = oTrans.Get(5)
End Function


Function GetNTPath (strUPN)
	On Error Resume next
	oTrans.Init ADS_NAME_INITTYPE_GC, &quot;&quot;
	oTrans.Set ADS_NAME_TYPE_USER_PRINCIPAL_NAME,strUPN
	If Err &lt;&gt; 0 Then
	MsgBox &quot;Unable to lookup &quot; &amp; strUPN,vbCritical + vbOKOnly,&quot;Error&quot;
	WScript.Quit
	End If
	
	GetNTPath = oTrans.Get(ADS_NAME_TYPE_NT4)
	GetNTPath = Replace(GetNTPath,&quot;&quot;,&quot;/&quot;)
End Function &lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Anyone? I have updated the code (below).</p>
<p>My problem is that it is only working partially. To summarize, I am using a single workbook containing two worksheets. Worksheet 1 is where the script reads from, and it is just one column with a list of sAMAccountNames. Worksheet 2 is where the script writes the output to for each of the sAMAccountNames after fetching the values from the domain. My problem seems to be that I do not know how to code the Loop such that it increments to the next Row for each of worksheets as it parses through the sAMAccountNames. As a result, the script succeeds only for the first row (reads input from first row in worksheet 1 and writes output to first row in worksheet2) but it does not process the subsequent rows.</p>
<p>Does anyone know how I can accomplish this loop? </p>
<pre>
' Abridged original remarks from Ralph Mongtomery
' Get User Information NTUser.wsf
' Version 1.0 Created 11-26-2001 by Ralph Montgomery (rmonty@myself.com)

' Alan Kaplan remarks
' 3/23/2009 I have been using this script for a very long time, and have probably hacked
' it beyond recognition. I take neither the credit nor the blame for the clumsy bits...
' I stripped out Win9x stuff, and system info detection, as everyone I know
' using this is at XP or later.

'10/23/2009 added support for and enumeration of UPN

Option Explicit
Dim strUserName, objUserDomain, objGroup, objUser, strGroupList
Dim WshShell, strMessage, strTitle
Dim oDomain, strNTDomain, strVer
Dim strSortedGroups, arrGroupList, strUserList
Dim objChangePwdTrue, objChangePwd, objUserProfile
Dim objPwdExpiresTrue, objFlags, oPwdExpire, strPwdExpires, iAdminCount, dPwdLastChanged, iAutoUnlock
Dim objAcctDisabled, intPwdExpired, objPwdExpiredTrue, objPwdExpires,bAccountDisabled
Dim StrQuote, iBadLogins, iMaxPadPw, iAccountLockout, iPwdAge, intPwdHistory
Dim strExcelPath, objExcel, objSheet, intReadRow, strUserDN, strPassword, xlExcel7, intWriteRow
Set WshShell = WScript.CreateObject("WScript.Shell")
strVer = "Ver 3.1 "
strQuote = Chr(34)
Dim strNTName, strUPN
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Dim strNTUserName
Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_TYPE_UNKNOWN = 8
Const ADS_NAME_TYPE_CANONICAL = 2

Dim oTrans
Set oTrans = CreateObject("NameTranslate")

' Check for required script arguments
If (Wscript.Arguments.Count &lt; 1) Then
    Wscript.Echo "Arguments &lt;FileName&gt; required. For example:" &amp; vbCrLf _
        &amp; "cscript enumaccountpolicies.vbs c:spreadsheet.xls"
    Wscript.Quit(0)
End If

' Pull Environment variables for domain/user
strNTDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
strNTUserName = ucase(WshShell.ExpandEnvironmentStrings("%USERNAME%"))


	'------------------------------------------MAIN----------------------------------------------
	
	Call Excel
	Call ExcelAddOutputSheet
	Call GetandWriteInfo


	' Format the spreadsheet.
	'objSheet.Range("A1:A5").Font.Bold = True
	'objSheet.Select
	'objSheet.Range("B5").Select
	'objExcel.ActiveWindow.FreezePanes = True
	'objExcel.Columns(1).ColumnWidth = 20
	'objExcel.Columns(2).ColumnWidth = 30
	
	' Save the spreadsheet and close the workbook.
	objExcel.ActiveWorkbook.SaveAs strExcelPath
	objExcel.ActiveWorkbook.Close
	
	' Quit Excel.
	objExcel.Application.Quit
	
	' Clean up.
	Set objUser = Nothing
	Set objExcel = Nothing
	Set objSheet = Nothing
	
	Wscript.Echo "Done"

	'---------------------------------------------END MAIN-------------------------------------------
	
	

'''''''''Subs and Functions ''''''''''

Sub Excel  'Bind to Excel object and Workbook

	' Define Workbook Path
	strExcelPath = Wscript.Arguments(0)
	
	' Bind to Excel object
	On Error Resume Next
	Set objExcel = CreateObject("Excel.Application")
	If (Err.Number &lt;&gt; 0) Then
	On Error GoTo 0
	Wscript.Echo "Excel application not found"
	Wscript.Quit
	End If
	objExcel.Visible = True
	On Error GoTo 0
	
	' Bind to Workbook
	On Error Resume Next
	objExcel.Workbooks.Open strExcelPath
	If (Err.Number &lt;&gt; 0) Then
	On Error GoTo 0
	Wscript.Echo "Spreadsheet cannot be opened: " &amp; strExcelPath
	Wscript.Quit
	End If
	On Error GoTo 0
End Sub


Sub ExcelReadSheet 'Bind to INPUT Worksheet in Workbook
	Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
End Sub


Sub ExcelWritesheet  'Bind to OUTPUT Worksheet in Workbook
	Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
End Sub


Sub ExcelAddOutputSheet 'Populate Headings in OUTPUT Worksheet
	
	'Bind to OUTPUT worksheet in current Workbook
	Call ExcelWriteSheet
	'Name Worksheet
	objSheet.Name = "Audit Results"
	'Populate
	objSheet.Cells(1, 1).Value = "Account Attributes"
	objSheet.Cells(1, 2).Value = "Date &amp; Time of Retrieval: " &amp; (NOW())
	objSheet.Cells(3, 1).Value = "Full Name"
	objSheet.Cells(3, 2).Value = "Account Name"
	objSheet.Cells(3, 3).Value = "Description"
	objSheet.Cells(3, 4).Value = "Account Disabled"
	objSheet.Cells(3, 5).Value = "Account Locked Out"
	objSheet.Cells(3, 6).Value = "Bad Logins"
	objSheet.Cells(3, 7).Value = "~Last Logon"
	objSheet.Cells(3, 8).Value = "Max Password Attempts"
	objSheet.Cells(3, 9).Value = "Attempts Left"
	objSheet.Cells(3, 10).Value = "Password Never Expires"
	objSheet.Cells(3, 11).Value = "Password Expired?"
	objSheet.Cells(3, 12).Value = "Password Age"
	objSheet.Cells(3, 13).Value = "Password Last Changed"
	objSheet.Cells(3, 14).Value = "Password Next Change"
	objSheet.Cells(3, 15).Value = "User can Change Password"
	objSheet.Cells(3, 16).Value = "Password Minimum Length"
	objSheet.Cells(3, 17).Value = "Passwords Kept in History"
	objSheet.Cells(3, 18).Value = "Lock-out Time"
	objSheet.Cells(3, 19).Value = "Auto-Unlock Time"
	objSheet.Cells(3, 20).Value = "Group Memberships"
End Sub


Sub GetandWriteInfo  'Reads INPUT Worksheet, Fetches Parameters, and writes to OUTPUT Worksheet

	'Read INPUT Worksheet
	Call ExcelReadSheet
	
	'The first row of the input worksheet is skipped (column headings). 
	'Each row after the first is processed until the first blank entry 
	'in the first column is encountered.
	intReadRow = 2
	Do While objSheet.Cells(intReadRow, 1).Value &lt;&gt; ""
	strUserName = objSheet.Cells(intReadRow, 1).Value
	strNTUserName = strUserName
	On Error Resume Next
	
	'Attempt to bind to the user account
	Set objUser = GetObject("WinNT://"&amp; strNTDomain &amp; "/" &amp; strNTUserName &amp; ", user")
	If (Err.Number &lt;&gt; 0) Then
	On Error GoTo 0
	Wscript.Echo "User NOT found: " &amp; strNTUserName 
	
	Else
	
	''''''Fetch Account Parameters''''''
	On Error resume Next
	' Creates the list of groups the user belongs To
	For Each objGroup In objUser.Groups
	If strGroupList = "" Then
	strGroupList = objGroup.Name
	Else
	strGroupList = strGroupList &amp; ", " &amp; objGroup.Name
	End If
	Next
	' Convert strgrouplist to Array
	arrGroupList = Split(strGroupList,",")
	'Sort the darn thing
	Quicksort arrGroupList, LBound(arrGroupList), UBound(arrGroupList)
	' Now concatenate arrGroupList into a variable for display
	strSortedGroups = trim(Join(arrGroupList, ", "))
	
	'check for expired password
	intPwdExpired = objUser.Get("PasswordExpired")
	If intPwdExpired = 1 Then
	objPwdExpiredTrue = "Yes"
	Else objPwdExpiredTrue = "No"
	End If
	
	'Check for Must Change Password Flag
	objFlags = objUser.Get("UserFlags")
	If (objFlags And &amp;H00040) &lt;&gt; 0 Then
	objChangePwdTrue = "No"
	Else objChangePwdTrue = "Yes"
	End If
	
	' Is password set to NEVER expire?
	objPwdExpires = objUser.Get("UserFlags")
	If (objPwdExpires And &amp;H10000) &lt;&gt; 0 Then
	objPwdExpiresTrue = "Yes"
	strPwdExpires = "Date Set: "
	Else objPwdExpiresTrue = "No"
	strPwdExpires = "Password Expires: "
	End If
	
	' Is the account disabled?
	If objUser.AccountDisabled = True Then
	bAccountDisabled = "Yes"
	Else bAccountDisabled = "No"
	End If
	
	'How many wrong logins?
	iBadLogins = objUser.BadPasswordAttempts
	
	'Maximum bad password attempts?
	iMaxPadPw = objUser.MaxBadPasswordsAllowed
	
	'Account Lockout Observation Interval
	iAccountLockout = FormatNumber((objUser.LockoutObservationInterval/60), 0)
	
	'How old is the current password?
	iPwdAge = FormatNumber(((objUser.Get("PasswordAge")/60)/60)/24, 0)
	
	'Calculate the date the password was last changed
	dPwdLastChanged = CStr(objUser.PasswordExpirationDate - objUser.Get("MaxPasswordAge") / (60 * 60 * 24))
	
	iAdminCount = objUser.Get("AdminCount")
	
	'Set Profile path to tabs if blank
	objUserProfile = objUser.Profile
	If objUserProfile = "" Then
	objUserProfile= "&lt;None&gt;" &amp; vbTab
	Else objUserProfile = objUserProfile
	End If
	
	'Determine how many passwords are saved
	Set oDomain = GetObject("WinNT://" &amp; strNTDomain)
	intPwdHistory = oDomain.PasswordHistoryLength
	iAutoUnlock = oDomain.AutoUnlockInterval/60
	
	
	'Bind to OUTPUT Worksheet in current Workbook
	Call ExcelWriteSheet
	'Write results to OUTPUT Worksheet
	Call Writeinfo
	
	End If
	
	'Attempt to process next worksheet rows via Loop
	intReadRow = intReadRow + 1
	'intWriteRow = intWriteRow + 1
	Loop

End Sub 


Sub WriteInfo 'Writes Fetched Parameters to OUTPUT Worksheet
	
	'Write values to OUTPUT Worksheet
	intWriteRow = 4
	objSheet.Cells(intWriteRow, 1).Value = objUser.FullName
	objSheet.Cells(intWriteRow, 2).Value = strNTDomain &amp; "" &amp; strNTUserName
	objSheet.Cells(intWriteRow, 3).Value = objUser.Description
	objSheet.Cells(intWriteRow, 4).Value = bAccountDisabled
	objSheet.Cells(intWriteRow, 5).Value = objUser.IsAccountLocked
	objSheet.Cells(intWriteRow, 6).Value = iBadLogins
	objSheet.Cells(intWriteRow, 7).Value = objUser.LastLogin
	objSheet.Cells(intWriteRow, 8).Value = iMaxPadPw
	objSheet.Cells(intWriteRow, 9).Value = iMaxPadPw - iBadLogins
	objSheet.Cells(intWriteRow, 10).Value = objPwdExpiresTrue
	objSheet.Cells(intWriteRow, 11).Value = objPwdExpiredTrue
	objSheet.Cells(intWriteRow, 12).Value = iPwdAge
	objSheet.Cells(intWriteRow, 13).Value = dPwdLastChanged
	objSheet.Cells(intWriteRow, 14).Value = strPwdExpires
	objSheet.Cells(intWriteRow, 15).Value = objChangePwdTrue
	objSheet.Cells(intWriteRow, 16).Value = objUser.PasswordMinimumLength
	objSheet.Cells(intWriteRow, 17).Value = intPwdHistory &amp; " password(s)"
	objSheet.Cells(intWriteRow, 18).Value = iAccountLockout &amp; " minutes"
	objSheet.Cells(intWriteRow, 19).Value = iAutoUnlock &amp; " minutes"
	objSheet.Cells(intWriteRow, 20).Value = strSortedGroups

End Sub


Sub Quicksort(strValues(), ByVal min, ByVal max) 'Sorts the items in the array (between the two values you pass in)
	Dim strMediumValue, high, low, i
	
	'If the list has only 1 item, it's sorted.
	If min &gt;= max Then Exit Sub
	
	' Pick a dividing item randomly.
	i = min + Int(Rnd(max - min + 1))
	strMediumValue = strValues(i)
	
	' Swap the dividing item to the front of the list.
	strValues(i) = strValues(min)
	
	' Separate the list into sublists.
	low = min
	high = max
	Do
	' Look down from high for a value &lt; strMediumValue.
	Do While strValues(high) &gt;= strMediumValue
	high = high - 1
	If high &lt;= low Then Exit Do
	Loop
	
	If high &lt;= low Then
	'The list is separated.
	strValues(low) = strMediumValue
	Exit Do
	End If
	
	'Swap the low and high strValues.
	strValues(low) = strValues(high)
	
	'Look up from low for a value &gt;= strMediumValue.
	low = low + 1
	Do While strValues(low) &lt; strMediumValue
	low = low + 1
	If low &gt;= high Then Exit Do
	Loop
	
	If low &gt;= high Then
	'The list is separated.
	low = high
	strValues(high) = strMediumValue
	Exit Do
	End If
	
	'Swap the low and high strValues.
	strValues(high) = strValues(low)
	Loop 'Loop until the list is separated.
	
	'Recursively sort the sublists.
	Quicksort strValues, min, low - 1
	Quicksort strValues, low + 1, max

End Sub


Function GetUPN (strNTName)
	On Error Resume Next
	oTrans.Init ADS_NAME_INITTYPE_GC, ""
	oTrans.Set ADS_NAME_TYPE_UNKNOWN,strNTName
	If Err &lt;&gt; 0 Then
	MsgBox "Unable to lookup " &amp; strNTName,vbCritical + vbOKOnly,"Error"
	WScript.Quit
	End If
	GetUPN = oTrans.Get(5)
End Function


Function GetNTPath (strUPN)
	On Error Resume next
	oTrans.Init ADS_NAME_INITTYPE_GC, ""
	oTrans.Set ADS_NAME_TYPE_USER_PRINCIPAL_NAME,strUPN
	If Err &lt;&gt; 0 Then
	MsgBox "Unable to lookup " &amp; strUPN,vbCritical + vbOKOnly,"Error"
	WScript.Quit
	End If
	
	GetNTPath = oTrans.Get(ADS_NAME_TYPE_NT4)
	GetNTPath = Replace(GetNTPath,"","/")
End Function </pre>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/8 queries in 0.011 seconds using memcached
Object Caching 283/284 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-20 03:36:19 -->