Skip to content

Instantly share code, notes, and snippets.

@gravejester
Last active December 13, 2022 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravejester/ddc31e8feee2fbd1b379 to your computer and use it in GitHub Desktop.
Save gravejester/ddc31e8feee2fbd1b379 to your computer and use it in GitHub Desktop.
function Update-FileInfoType {
<#
Update FileInfo type to include SizeOnDisk
Author: Øyvind Kallstad
#>
$typeData = Get-TypeData System.IO.FileInfo
$scriptBlock = {
$blockSize = $this.PSDrive.BlockSize
$size = $this.Length
[math]::Ceiling($size/$blockSize) * $blockSize
}
$scriptProperty = New-Object System.Management.Automation.Runspaces.ScriptPropertyData 'SizeOnDisk', $scriptBlock
if (-not($typeData.Members['SizeOnDisk'])) {
$typeData.Members.Add('SizeOnDisk', $scriptProperty)
}
Update-TypeData $typeData -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment