Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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