Skip to content

Instantly share code, notes, and snippets.

Last active December 13, 2022 23:58
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