Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Powershell Script for Folder size

$
0
0

got a script to get folder size with robocopy .This is for overcoming 256 character limitation in windows

when i am running it getting below error . could anyone plse help

Error

You cannot call a method on a null-valued expression.
At G:\folder_size\get_foldersize.ps1:13 char:137
+         $fldSize = (robocopy  $strDir "c:\FakeDir" /zb /e /l /r:1 /w:1 /nfl /ndl /nc /fp /bytes /np /njh | ? {$_ -match "Bytes :"}).trim <<<< ().split(" ")
    + CategoryInfo          : InvalidOperation: (trim:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

 

Script

 

#Set Start folder Location
$startFolder = "\\serevr\test"
#Set output folder
$output = "G:\folder_size\something.csv"
#Start the collections
$colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
$results = @()
foreach ($i in $colItems)
    {         
        #START TIMER
        $startDTM = (Get-Date)
        $i.FullName
        $fldSize = (robocopy  $strDir "c:\FakeDir" /zb /e /l /r:1 /w:1 /nfl /ndl /nc /fp /bytes /np /njh | ? {$_ -match "Bytes :"}).trim().split(" ")
        #END TIMER
        $endDTM = (Get-Date)
        $results += '"' +$i.FullName + '"' + ";" + "{0:N2}" -f ($subFolderItems.sum / 1MB) + ";" + "Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds"
    }
$results > $output

 

 


Viewing all articles
Browse latest Browse all 8583

Latest Images

Trending Articles



Latest Images