Skip to content

Instantly share code, notes, and snippets.

@martin9700
Last active October 12, 2015 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martin9700/d325b61f06071130e3f0 to your computer and use it in GitHub Desktop.
Save martin9700/d325b61f06071130e3f0 to your computer and use it in GitHub Desktop.
cls
Write-Verbose "$(Get-Date): Getting DIR information..." -Verbose
$Dir = "C:\dropbox\test"
$Files = Get-ChildItem $Dir -File -Recurse | Select FullName,BaseName,Length
Write-Verbose "$(Get-Date): $($Files.Count) files found" -Verbose
Write-Verbose "$(Get-Date): Using calculated fields in Select..." -Verbose
Measure-Command {
$Files | Select Fullname,BaseName,Length,@{Name="SizeMB";Expression={ [math]::Round($_.Length / 1MB,2) }},@{Name="SizeGB";Expression={ [math]::Round($_.Length / 1GB,2) }}
}
Write-Verbose "$(Get-Date): Now calculating with dynamic properties..." -Verbose
Measure-Command {
$Files |
Add-Member -MemberType ScriptProperty -Name SizeMB -Value { [math]::Round($this.Length / 1MB,2) } -PassThru |
Add-Member -MemberType ScriptProperty -Name SizeGB -Value { [math]::Round($this.Length / 1GB,2) }
$Files
}
Write-Verbose "$(Get-Date): Done!" -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment