July 2018
Beginner
552 pages
13h 18m
English
PowerShell types are already very useful, but sometimes you will need to extend them with additional properties, for example. You already know that this is possible to use the Add-Member cmdlet to extend each object. However, this approach does not scale well.
If you know the type that needs to be extended, you might want to consider using custom type extensions. As with format data in the previous section, you have the opportunity to override existing types by prepending your custom data and appending type extensions:
$typeDefinition = @'<Types><Type> <Name>System.IO.FileInfo</Name> <Members> <ScriptProperty> <Name>Hash</Name> <GetScriptBlock>Get-FileHash -Path $this.FullName</GetScriptBlock> </ScriptProperty> </Members> ...
Read now
Unlock full access