I need a script to find out who are the owner of files and folders in file server.
A script that can specific the user and scan shared drive in file server after that save into csv file.
Appreciate for help.
Pretty easy to do, as it turns out:
$Path = "c:\Test" $LogPath = "c:\test" Get-ChildItem $Path -force -Recurse | Select Name,Directory,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},CreationTime,LastAccessTime | Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation
I also have a more advanced version that will produce an HTML report:
community.spiceworks.com/.../1722-get-fileowner
Hi Martin,
Thanks a lot for your scripts, it helped me a lot!
If there is a filtering for specific Owner name is even perfect!
I tried to add -filter username in the script but seems not working.
Sorry that I've asking the stupid question, I admit that I am still a fresh beginner for PowerShell :p
You'd have to put a Where statement at the end to filter by user. The downside is the script has to gather ALL information and THEN filter the user out so you won't be saving any time. You could also just put a filter row in an Excel spreadsheet and select the user you want.
$Path = "c:\Test" $LogPath = "c:\test" $User = "domain\user" Get-ChildItem $Path -force -Recurse | Select Name,Directory,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},CreationTime,LastAccessTime | Where Owner -eq $User | Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation
OK, understand.
I just wondering to have "length" which is file size information from the script as well.
And trying to convert it to human-readable file size like MB but doesn't seems work.
Do you have any idea which part is wrong?
$Path = "c:\test"
$LogPath = "c:\test"
$User = "Domain\user"
Get-ChildItem $Path -force -Recurse |
Select Name,Directory,Length,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},@{Length="MB";Expression={$_.Length / 1MB}},CreationTime,LastAccessTime |
Where Owner -eq $User |
Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation
You were SO close! Calculated fields in Select follow this format:
So the script would be:
$Path = "c:\test" $LogPath = "c:\test" $User = "Domain\user" Get-ChildItem $Path -force -Recurse | Select Name,Directory,Length,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},@{Name="MB";Expression={$_.Length / 1MB}},CreationTime,LastAccessTime | Where Owner -eq $User | Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation
THANKS Martin!!
It's Working!
You are so good!
This was super useful over seven years later lol. Thanks. Do you know how I would be able to include the name of the person who last saved the file? Please and Thanks.