• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

Get-ChildItem of Share

I am wanting to input a username into a script and have an output showing any files they own in order of size. I currently have the (very basic) script below. I can see the specific files a user owns but I can't figure out how to get it to list by size.

$User = read-host "Enter a pin number"
$Directory="E:\Data\"

Get-ChildItem $Directory -recurse -file | Get-Acl | where {$_.Owner -match $user}

Open in new window


My ultimate goal is to use this script to email users that exceed a certain quota percentage with a list of their largest files. Any help would be greatly appreciated!
0
Joseph Moody
Asked:
Joseph Moody
4 Solutions
 
X_layerCommented:
You can try to achive this with sort-object:
Get-ChildItem $Directory -recurse -file | Get-Acl | where {$_.Owner -match $user} | Sort-Object length -descending

Open in new window

0
 
netballiCommented:
Try this,

Get-ChildItem $Directory -recurse -file | Get-Acl | where {$_.Owner -match $user} | sort-Object -property length -Descending
0
 
SubsunCommented:
Try the following code.. you may select the required property of the file using Select-Object
$User = read-host "Enter a pin number"
$Directory="E:\Data\"
Get-ChildItem $Directory -recurse -file | ? {$($_ | Get-Acl).Owner -match $user} | Select-Object *

Open in new window

0
Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thank you for helping me get further!! I now have this:

 
$Users = Get-EventLog -ComputerName DataServer.TEST.local -LogName System -Source ntfs -username GCBE\* | Select-Object Username
$Directory="E:\Data"

Foreach ($User in $Users) {
Get-ChildItem $Directory -recurse -file | ? {$($_ | Get-Acl).Owner -match $user.trimstart("Test\")} | Select-Object Fullname,Length | Sort-Object length -Descending}

Open in new window


I am trying to get it to take each username pulled from the event log and have it give me a list of their largest files. It seems to fail because .Owner doesn't work if the username is prefixed by the domain name.

I tried using trimstart to remove the domain name but I am over my head! If I remove trimstart, my error is :

parsing "@{UserName=Test\User1}" - Unrecognized escape sequence \8.
At P:\Script Explorer\Scripts\Get User Quota\Get User Quota.ps1:5 char:48
+ Get-ChildItem $Directory -recurse -file | ? {$($_ | Get-Acl).Owner -match $user} ...
+                                                ~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException

 Any suggestions?
0
 
SubsunCommented:
Try with..
$user.UserName.trimstart("Test\")
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thank you all for the help! I am still working through the final solution and may open another question or two.
0

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now