Get-ChildItem of Share

Posted on 2013-01-08
Last Modified: 2013-01-15
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"

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!
Question by:Joseph Moody
LVL 11

Assisted Solution

X_layer earned 100 total points
ID: 38756693
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

LVL 11

Assisted Solution

netballi earned 100 total points
ID: 38756715
Try this,

Get-ChildItem $Directory -recurse -file | Get-Acl | where {$_.Owner -match $user} | sort-Object -property length -Descending
LVL 40

Accepted Solution

Subsun earned 300 total points
ID: 38756790
Try the following code.. you may select the required property of the file using Select-Object
$User = read-host "Enter a pin number"
Get-ChildItem $Directory -recurse -file | ? {$($_ | Get-Acl).Owner -match $user} | Select-Object *

Open in new window

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

LVL 22

Author Comment

by:Joseph Moody
ID: 38759455
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

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?
LVL 40

Assisted Solution

Subsun earned 300 total points
ID: 38759629
Try with..
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38778593
Thank you all for the help! I am still working through the final solution and may open another question or two.

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now