On Jul 30, 4:46*pm, aukiman <gu...@xxxxxx-email.com> wrote:
> (Testing on Windows XP Sp2)
>
> I wonder if anyone can help me with this one.
>
> I am testing a script as below to be run on our client servers to
> return the properties of any given directory (specified by client) for
> pre/post backup comparisons.
>
> For testing I used the c:\windows directory on my machine simply
> because it contains a wide variety of file/folder attributes as opposed
> to standard directories containing just data.
>
> $FolderList = gc "d:\folderlist.txt"
> $Date = ( get-date ).ToString('yyyy-MM-dd')
> $Report = New-Item -type file "$Date-directory.report.txt"
> ForEach($TargetFolder In $folderlist) {
> $OutItems = (Get-ChildItem $TargetFolder -include *.* -recurse -force |
> Measure-Object -property length -sum)
> $OutFileNum = @(Get-ChildItem $TargetFolder -recurse -force |
> ?{!($_.PSIsContainer)}).Count
> $OutFolderNum = @(Get-ChildItem $TargetFolder -recurse -force |
> ?{$_.PSIsContainer}).Count
> "$TargetFolder : " + "{0:N2}" -f ($OutItems.sum / 1MB) + " MB" + " :
> Files=$OutFileNum" + " : Folders=$OutFolderNum" |
> out-file $Report -append
>
> }
>
> So far I have noticed discrepancies (only very slight) in the returned
> number of files and folders.
>
> The script returns the below results for the windows directory.
>
>
>
> > c:\windows : 4,516.26 MB : Files=23140 : Folders=2261 >
> In windows, right-clicking and selecting properties returns this :
>
> [image:http://i85.photobucket.com/albums/k6...roperties.jpg]
>
> The differences in File and Folder counts is puzzling me. Am I doing
> something wrong in my script or is there an explanation at the OS level?
>
> Other directories with 'normal' attributes and content seem to report
> ok by the way.
>
> --
> aukiman
>
> '[image:http://i85.photobucket.com/albums/k6...onmansig-n...]'
> (http://www.radioaukiman.com/forums) So I was fooling around with the code a bit, and after some
refactoring I seem to be getting better results, but I'm actually not
sure why yet. I took out the formatting because I was trying to see
if the way MB was measuring megabytes (1000000 bytes vs 1024^2 bytes),
and I changed it so that Get-ChildItem is only called once to avoid re-
scanning directories. I also used tab-separated values because it
made it easier to open in Excel and suppressed errors from Get-
ChildItem.
$FolderList = @(gc 'folderlist.txt')
$Report = "$((get-date).ToString('yyyy-MM-dd'))-directory.report.txt"
"`nGetting a list of folders from folderlist.txt...`n"
"Folder`tSize`tFiles`tFolders`tErrors" > $Report
ForEach ($TargetFolder In $folderlist) {
if (-not $TargetFolder) { # skip blank lines
continue
}
$Results = @(Get-ChildItem $TargetFolder -recurse -force -
ErrorAction 'SilentlyContinue' -ErrorVariable DirErrors)
$OutItemNum = $Results | Measure-Object -property length -sum
$OutFileNum = ($Results | ?{$_.PsIsContainer -eq $false}).Count
$OutFolderNum = ($Results | ?{$_.PsIsContainer -eq $true}).Count
"$TargetFolder`t$($OutItemNum.sum)`t$OutFileNum`t$OutFolderNum`t$
($DirErrors.Count)"
"$TargetFolder`t$($OutItemNum.sum)`t$OutFileNum`t$OutFolderNum`t$
($DirErrors.Count)" >> $Report
}