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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

752 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