need help with powershell script to obtain "my document" folder size
i work @ college have 1000 staff users within our campus, need report of users local documents folder size windows xp , windows 7. came across script obtains "my documents" folder size still need other information , have never used powershell before hoping able help. script below displays "my documents" folder size need display computer name , username , export file. in format of computername username mydocumentsfoldersize deploying using group policy need export existing file dont want through 1000 seperate files $path = [environment]::getfolderpath([environment+specialfolder]::mydocuments) $totalsize = get-childitem -path $path -recurse -erroraction "silentlycontinue" | measure-object -property length -sum if($totalsize.sum -ge 1gb) { "{0:n2}" -f ($totalsize.sum / 1gb) + " gigabytes" } elseif($totalsize.sum -ge 1mb) { "{0:n2}" -f ($totalsize.sum / 1mb) + " megabytes" } else { "{0:n2}" -f ($totalsize.sum / 1kb) + " kilobytes" } | |
hi, script good. have size calcualted, thing have left build customized object fileds. in case computername, username , mydocumentsfoldersize. can create new object properties , using enviroment variables rest of information. script looking one:
$path = [environment]::getfolderpath([environment+specialfolder]::mydocuments) $totalsize = get-childitem -path $path -recurse -erroraction "silentlycontinue" | measure-object -property length -sum if($totalsize.sum -ge 1gb) { $size="{0:n2}" -f ($totalsize.sum / 1gb) + " gigabytes" } elseif($totalsize.sum -ge 1mb) { $size="{0:n2}" -f ($totalsize.sum / 1mb) + " megabytes" } else { $size="{0:n2}" -f ($totalsize.sum / 1kb) + " kilobytes" } $res = new-object object $res | add-member noteproperty computername $env:computername $res | add-member noteproperty username $env:username $res | add-member noteproperty mydocumentsfoldersize $size $res
i hope :)!
Windows Server > Windows PowerShell
Comments
Post a Comment