Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get-ChildItem of Share

Posted on 2013-01-08
6
Medium Priority
?
431 Views
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"
$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
Comment
Question by:Joseph Moody
6 Comments
 
LVL 11

Assisted Solution

by:X_layer
X_layer earned 400 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

0
 
LVL 11

Assisted Solution

by:netballi
netballi earned 400 total points
ID: 38756715
Try this,

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

Accepted Solution

by:
Subsun earned 1200 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"
$Directory="E:\Data\"
Get-ChildItem $Directory -recurse -file | ? {$($_ | Get-Acl).Owner -match $user} | Select-Object *

Open in new window

0
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

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

Assisted Solution

by:Subsun
Subsun earned 1200 total points
ID: 38759629
Try with..
$user.UserName.trimstart("Test\")
0
 
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

971 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