Enumerate Filesystem

This is a little script that I used to find the last 20 last written files and get back the owners of those files.

$ErrorActionPreference = "Continue" 
if (Get-PSDrive G) { Remove-PSDrive -name g}
$a = 1
$obj = Import-Csv .\test.csv
$obj | foreach {
New-PSDrive -name g -psprovider filesystem -root ($obj | where {$_.Name -eq $a }).literalpath
if (gci g: -recurse | sort LastWriteTime | select -last 1) { 
echo $_ | out-file c:\temp\master-ownerlist.txt -append
gci G: -recurse | Sort LastWriteTime | Select owner -last 20 | sort-object Owner | group-object owner|Select Count, Name | format-table -auto| out-file c:\temp\master-ownerlist.txt -append}
$a=$a+1 
Get-PSDrive G | Remove-PSDrive
}

Or if I would like to find empty shares I would enumerate through the folder structure with something like this:

$ErrorActionPreference = "Continue" 
if (Get-PSDrive G) { Remove-PSDrive -name g}
$a = 1
$obj = Import-Csv .\test.csv
$obj | foreach {
New-PSDrive -name g -psprovider filesystem -root ($obj | where {$_.Name -eq $a }).literalpath
$b = Get-ChildItem G: -recurse
if (!($b)) { $_ | out-file c:\temp\emptyfolders.txt -append }
$a = $a +1
Get-PSDrive G | Remove-PSDrive
}

On Me

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License