It's been a while but given the success of my last PowerShell script I thought I would post another one I have been asked to produce recently.
This one is heavily inspired from no other than the famous Gary Lapointe's excellent script:
(Gary if you are reading this, just wanted to thank you for the awesome stsadm custom extensions I was using heavily in my SharePoint 2003/2007 days!) :)
I have only made the following enhancements to it:
- Made sure the SharePoint PowerShell snapIn is added at the start of the script if not already there
- Added some "Write-Host" lines to give an idea where the script is at when scanning the entire farm as it can be a long running process...
- Added the "File Extension" calculation, for some reason the $item.File.Item["FileType"] was not always returning a value on non-english SharePoint site collections. So had to use [System.IO.FileInfo] in the end
- Generated the output CSV filename automatically based on the time the script is run. I just like to do that... makes sure it never overwrites previous exports and allows you not to have to modify the script every time.
- Wrapped the entire function call in "[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges" as I noticed that when the scan was hitting the "My Site" web application it would struggle with my sites of employees who had left, because the credentials under which you are running the script need to be site owner (either primary or secondary admin on the site collection - basically site collection administrator). Web application security policies are not enough in this case.
Here is the script: