none
Test Code Colorization RRS feed

  • Question

  • Test code:

    $fso=New-Object -ComObject Scripting.FileSystemObject
    $folder=$fso.GetFolder('c:\')
    $folder.SubFolders|select name,size


    Richard Mueller - MVP Directory Services

    Sunday, September 22, 2013 6:11 PM

All replies

  • function Get-FolderSize
    {
    	<#
    		.SYNOPSIS
    			Returns size of folder
    	
    		.DESCRIPTION
    			Returns the size of the folder parameter. The sum of all childitems (recursive) is returned
    	
    		.PARAMETER path
    			The path of the folder to be thus scanned
    	
    		.INPUTS
    			System.String
    	
    		.OUTPUTS
    			System.Int32
    	#>
    	Param(
    		[String]
    		$path
    	)
    	
    	# If path is valid, do it
    	if (Test-Path $path)
    	{
    		$folderStats = Get-ChildItem $path -Recurse | Measure-Object -property length -sum
    		$size = $folderStats.sum
    		return $size
    	}
    	
    	# Throw error if path not valid
    	Else
    	{
    		Write-Error "Illegal or empty Path parameter"
    	}
    }


    Richard Mueller - MVP Directory Services

    Sunday, September 22, 2013 6:21 PM
  • function Get-FolderSize
    {
    	Param(
    		[String]
    		$path
    	)
    	
    	# If path is valid, do it
    	if (Test-Path $path)
    	{
    		$folderStats = Get-ChildItem $path -Recurse | Measure-Object -property length -sum
    		$size = $folderStats.sum
    		return $size
    	}
    	
    	# Throw error if path not valid
    	Else
    	{
    		Write-Error "Illegal or empty Path parameter"
    	}
    }


    Richard Mueller - MVP Directory Services

    Sunday, September 22, 2013 6:21 PM