powershell folder size, last modified, author attributes

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)} |
LVL 3
pma111Asked:
Who is Participating?
 
Dope ADMSr. Systems EngineerCommented:
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

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


»bp
0
 
aikimarkCommented:
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

0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
pma111Author Commented:
If you right click the headers in a folder in windows explorer author is an option to tick just like date modified
0
 
aikimarkCommented:
Do you see any "authors" data related to a folder?
0
 
pma111Author 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.
0
 
aikimarkCommented:
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

0
 
itavdelingenCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.