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]
##"$arrFolderName[i] $arrFolderSize[i]"
$Combine[$i] = $arrFolderName[$i] + "," + $arrFolderSize[$i]
}
$Combine | Sort
$Combine | Out-File c:\temp\PowerShell.csv

Comments

Popular posts from this blog

Restoring Master, Model and MSDB from Netbackup

Oracle Job Operations