INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel
2

Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

(OP)
Hi,

I wonder if anyone can help me with the script (below).
This is for checking and exporting the NTUSER.DATfile "modified date" (for all users) on a share, to a spreadsheet.

The script runs without errors but exports modified date for all folders and files (for all users) to excel.
I only want the information for NTUSER.DAT

Any help on modifying the script to desired effect appreciated.
Thanks in advance

Script:
............................................
Option Explicit

Dim strFolder, objFSO, objFolder
Dim strExcelPath, objExcel, objSheet, intRow

Const xlExcel7 = 39

' Specify main folder.
strFolder = "D:\test"

' Retrieve folder object.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)

' Specify spreadsheet to be created.
strExcelPath = "d:\test\user.xls"

' Create workbook.
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Enumerate files.
intRow = 0
Call GetFiles(objFolder)

' Save spreadsheet, close workbook, and quit Excel.
objExcel.ActiveWorkbook.SaveAs strExcelPath, xlExcel7
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

' Alert user.
Wscript.Echo "Done"

Sub GetFiles(ByVal objParent)
' Enumerate files in folder.
' Variable intRow must have global scope.
Dim objFile, objChild

For Each objFile In objParent.Files
intRow = intRow + 1
objSheet.Cells(intRow, 1).Value = objFile.Path
objSheet.Cells(intRow, 2).Value = objFile.DateLastModified
Next

' Recurse through nested folders.
For Each objChild In objParent.SubFolders
Call GetFiles(objChild)
Next
End Sub
..............................................................

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

Try this for getting the desired info.

CODE --> PowerShell

$ErrorActionPreference = "SilentlyContinue"
$Report = $Null
$Path = "C:\Users"
$UserFolders = $Path | GCI -Directory

ForEach ($UserFolder in $UserFolders)
{
$UserName = $UserFolder.Name
If (Test-Path "$Path\$UserName\NTUSer.dat")
    {
    $Dat = Get-Item "$Path\$UserName\NTUSer.dat" -force 
    $Dat = $Dat.LastWriteTime
    Write-Host $UserName $Dat
    $Report = $Report + "$UserName`t$Dat`r`n"
    $Dat = $Null
    }
Else
    {
    $Dat = "No file"
    $Report = $Report + "$UserName`t$Dat`r`n"
    }
}
$Report | Out-File c:\Temp\NTUserDatInfo.txt 

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

(OP)
Hi Mark,

Thanks for your help.
copied script, edited it as below, changed to file.ps1, ran from powershell, runs without errors but output text file only contains: "No File"


$ErrorActionPreference = "SilentlyContinue"
$Report = $Null
$Path = "D:\test\Users"
$UserFolders = $Path | GCI -Directory

ForEach ($UserFolder in $UserFolders)
{
$UserName = $UserFolder.Name
If (Test-Path "$Path\$UserName\UPM_Profile\NTUSer.dat")
{
$Dat = Get-Item "$Path\$UserName\UPM_Profile\NTUSer.dat" -force
$Dat = $Dat.LastWriteTime
Write-Host $UserName $Dat
$Report = $Report + "$UserName`t$Dat`r`n"
$Dat = $Null
}
Else
{
$Dat = "No file"
$Report = $Report + "$UserName`t$Dat`r`n"
}
}
$Report | Out-File d:\test\NTUserDatInfo.txt

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

What version of PowerShell are you using. The LastWriteTime requires 3.0 or better.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

(OP)
Thanks Mark,
works fine with 4.0, appreciated.

Very grateful for your help and if you know how I can make the script look for ALL instances of NTuser.dat in all users profile directories and folders and report modified dates will be appreciated.

Regards
Ben

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

Ben, the code I provided should enumerate through all user folders (at the base level). NTUSER.DAT should only exist at the root of each users profile.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

Probably should point out that the account the script is run under needs to be an admin account to have read access to the other user folders.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

(OP)
Appreciated Mark,
Many thanks for your help

Regards
Ben

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

If the code provided is helpful, you can click the Great Post, Star it! link to let others looking for similar help what helped you.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

(OP)
Done, thanks

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

Doesn't appear that way but thanks anyway.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

(OP)
Got it right this time, appologies.

RE: Script for exporting NTUSER.DATfile modified date (for all users) on a share to excel

Thank you.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close