Posts

Showing posts from October, 2012

Powershell code snipets

$DirArray=Get-ChildItem c:\temp | ?{ $_.PSIsContainer } | Select-Object FullName $arrFolderName = @() $arrFolderSize = @() $Combine = @() $varCount = 0   #### Allocate Memory for all arrays for ($i = 0;$i -lt $DirArray.length;$i++){ $arrFolderName += @($i) $arrFolderSize += @($i) $Combine += @($i) }   #### Populate folder name and size in two arrays Foreach($Item in $DirArray) { $Item = "$Item" $pos = $Item.IndexOf("=") $SubActualDir=$Item.Substring($pos+1) $pos=$SubActualDir.IndexOf("}") $actualDir=$SubActualDir.Substring(0,$pos) $arrFolderName[$varCount] = $actualDir $arrFolderSize[$varCount] = (gci $actualDir -r -force -exclude *.pst | measure -sum -property Length).Sum #"$arrFolderName[$varCount] :  $arrFolderSize[$varCount]" $varCount = $varCount + 1 }   #### Print in single line for ($i = 0;$i -lt $varCount;$i++){ ##echo $arrFolderName[$i] $arrFolderSize[$i] ##"$arrFolderNa

PowerShell: Simple task for finding top sized folders

First save the PS script Get-DirStats.ps1 Source Code of Get-DirStats.ps1 # Get-DirStats.ps1 # Written by Bill Stewart # Outputs file system directory statistics. #requires -version 2 <# .SYNOPSIS Outputs file system directory statistics. .DESCRIPTION Outputs file system directory statistics (number of files and the sum of all file sizes) for one or more directories. .PARAMETER Path Specifies a path to one or more file system directories. Wildcards are not permitted. The default path is the current directory (.). .PARAMETER LiteralPath Specifies a path to one or more file system directories. Unlike Path, the value of LiteralPath is used exactly as it is typed. .PARAMETER Only Outputs statistics for a directory but not any of its subdirectories. .PARAMETER Every Outputs statistics for every directory in the specified path instead of only the first level of directories. .PARAMETER FormatNumbers Formats numbers in the output object to include thousands separators. .PARAME