Skip to content

Instantly share code, notes, and snippets.

@gravejester
Last active December 13, 2022 23:58
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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