powershell folder size, last modified, author attributes

pma111
pma111 used Ask the Experts™
on
I need a simple one line powershell script to add to the below that will show me for each item the 'date modifided', 'date created', 'size' and 'author' attributes, can this be done in powershell, if so how would I finish the command off? the first part gets me just the folders which is what I am after:


Get-ChildItem \\server\share -Recurse | Where-Object{($_.psiscontainer)} |
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr. Systems Engineer
Commented:
A one-liner....with size, curious to see if someone can come up with that.
The below is not what you've requested, but in case you are interested....

Looking forward for someone to come up with a one liner for size, that'll help me a great deal with my scripts.

ps: Also, assuming it's for a file server, have you considered using FSRM?


$mainPath = Read-Host('Enter U$ drrive main path')

function Get-UdriveSize($pathName){
$item = $pathName
$params = New-Object System.Collections.Arraylist
$params.AddRange(@("/L","/S","/NJH","/BYTES","/FP","/NC","/NDL","/TS","/XJ","/R:0","/W:0"))
$countPattern = "^\s{3}Files\s:\s+(?<Count>\d+).*"
$sizePattern = "^\s{3}Bytes\s:\s+(?<Size>\d+(?:\.?\d+)).*"
$return = robocopy $item NULL $params
If ($return[-5] -match $countPattern) {
    $Count = $matches.Count
}
If ($Count -gt 0) {
    If ($return[-4] -match $sizePattern) {
        $Size = $matches.Size
    }
} Else {
    $Size = 0
}
$object = New-Object PSObject -Property @{
    FullName = $item
    Count = [int]$Count
    Size = "{0:N1}" -f (([math]::Round($Size,2)) / (1024*1024*1024))
}
$object.pstypenames.insert(0,'IO.Folder.Foldersize')
Write-Output $object
$Size=$Null
}
#############################################################################################

cd $MainPath
$Udrives = (Get-ChildItem $MainPath).name

#defining custom object
$outarray  = @() #array contstruct for data export csv or txt 

ForEach ($element in $Udrives) { #loop through each folder and compute file size under the user drive. 

$customOBJ = "" | select "Folder","SizeMB" #Object construct for the Select-Object

get-UdriveSize -pathName $element | Select-Object FullName,size | Export-Csv 'C:\FolderSizeReport2.csv' -Append

}

Open in new window

Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Your example will list folders.  What do you mean by "author" of a folder?


»bp
Top Expert 2014
Commented:
Although not a "one line" solution, this does return everything but the "author" property, which Bill already asked about.
Get-ChildItem \\server\share -Recurse | Where-Object{($_.psiscontainer)} |
    %{ 
        New-Object -TypeName PSObject -Property @{

        'Path' = $_.fullname
        'Date Created' = $_.CreationTime
        'Date Modified' = $_.LastWriteTime
        'Size' = (measure -sum -property length -InputObject (Get-ChildItem $_.fullname | ?{$_.psiscontainer -eq $false})).sum
        'Author' = 'unavailable'

        }
    }

Open in new window

OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Author

Commented:
If you right click the headers in a folder in windows explorer author is an option to tick just like date modified
Top Expert 2014

Commented:
Do you see any "authors" data related to a folder?

Author

Commented:
I do in some cases, not all, it lists a domain username in the authors column if I right click a folder, and tick the option.
Top Expert 2014
Commented:
Ah.  There was a way after all.
Get-ChildItem \\server\share -Recurse | Where-Object{($_.psiscontainer)} |
    %{ 
        New-Object -TypeName PSObject -Property @{

        'Path' = $_.fullname
        'Date Created' = $_.CreationTime
        'Date Modified' = $_.LastWriteTime
        'Size' = (measure -sum -property length -InputObject (Get-ChildItem $_.fullname | ?{$_.psiscontainer -eq $false})).sum
        'Author' = (Get-Acl $_.fullName).owner

        }
    }

Open in new window

Looking forward for someone to come up with a one liner for size, that'll help me a great deal with my scripts.

With this approach, I couldn't find a way to get author of each file, but the rest are here:
get-childitem | where {!$_.PSIsContainer} | Format-List FullName,LastWriteTime,CreationTime,Length

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial