VBScript to get local user account information and export to csv file

Hi,

   I want a VBScript could help get the local user account information on specified computer like user name, last logon date & time, password expiration date & time...etc. Then, the output would be able to write to a .csv file.

   Thanks for any suggestoin.

 

January 3rd, 2012 11:52am

Why not in powershell? That's much easier.
Free Windows Admin Tool Kit Click here and download it now
January 3rd, 2012 1:44pm

Use the WinNT provider for local accounts. You could redirect the output from the following to a text file:

 

$ComputerName = "MyComputer"
$Computer = [ADSI]"WinNT://$ComputerName,computer"
$Users = $Computer.psbase.Children | Where-Object {$_.psbase.schemaclassname -eq "user"}
ForEach ($User in $Users)
{
    $Name = $User.Name
    $Login = $User.lastLogin
    If ($Login.Name -eq "lastLogin") {$Login = "Never"}
    $PwdAge = $User.passwordAge
    $PwdExpired = $User.passwordExpired
    "$Name,$PwdAge,$PwdExpired,$Login"
}

-----

 

January 3rd, 2012 2:31pm

Hi Richard,

   Thanks for your update.

   However, would you mind to let me know the complete vbscript to redirect the output to a csv file.

   Thanks and look for your reply.

 

B.rgds,

Jordan

Free Windows Admin Tool Kit Click here and download it now
January 4th, 2012 7:20am

Hi Richard,

   Thanks for your update.

   However, would you mind to let me know the complete vbscript to redirect the output to a csv file.

   Thanks and look for your reply.

 

B.rgds,

Jordan

Try this: http://www.google.com/#sclient=psy-ab&hl=en&site=&source=hp&q=how+to+export+from+powershell&pbx=1&oq=how+to+export+from+powershell&aq=f&aqi=g-j1&aql=&gs_sm=e&gs_upl=2344l9891l0l10063l29l15l0l13l13l0l360l3093l0.8.6.1l25l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=dc9072f4d1d34f4c&biw=975&bih=629

January 4th, 2012 7:51am

What I meant before is that you can redirect the output from the PowerShell script to a text file when you run it at a PowerShell prompt. For example, if the PowerShell script is saved in the file LocalUsers.ps1:

.\LocalUsers.ps1 > LocalUsers.csv

 

An alternative is to use the Out-File cmdlet in the script. Change the line that outputs to this:

 

"$Name,$PwdAge,$PwdExpired,$Login" | Out-File -FilePath "c:\rlm\PowerShell\LocalUsers.csv" -Append

-----

 

Free Windows Admin Tool Kit Click here and download it now
January 4th, 2012 5:04pm

Hello Richard,

The script you mentioned above works like a charm, but is there anyway we can change the password age to be in Days instead of seconds ?

Thank you.

Baljit

July 2nd, 2013 7:39pm

Hello Richard,

The script you mentioned above works like a charm, but is there anyway we can change the password age to be in Days instead of seconds ?

Thank you.

Baljit

Arithmatic!

12 Day = 24 * 60 * 60 seconds

What is it they say.... "Do the math!"

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 9:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics