This simple PowerShell Script goes through a folder and its sub-folders, looking for specific types of files, and then it outputs those file names, size, directory and age to a text file.
You can easily deploy this script using Group Policies for an Active Directory user.
You can download the complete script here –> UserFilesPSScript.
- @{Name=”Kbytes”;Expression={ “{0:N0}” -f ($_.Length / 1Kb) }}
This will display the file sizes in Kbytes rather than in bytes. If you want to keep the script simple, you could have just used “size” instead of all that. - @{Name=”Age”;Expression={ (((Get-Date) – $_.CreationTime).Days) }}
This will give you the difference between the current date and the file creation date in days. - format-table -wrap
-wrap option will wrap long strings like Directory and Name, otherwise you won’t see the complete string in your text file.
You can easily deploy this via a GPO by navigating to User Configuration / Policies / Windows Settings / Scripts (Logon/Logoff) / Logon –> PowerShell Scripts
I hope this will help someone out there. Good Luck.