Reputation: 26262
I'd like to extend the PsCredential
class (in a PowerShell v4 module) to include a server name, then be able to serialize/deserialize the class using a script like Export-PsCredential. Can this (extending the class) be done easily in a PowerShell module?
Upvotes: 1
Views: 102
Reputation: 47812
Yes it can! You can define your extension in XML, in a .ps1xml
file and then update it with Update-TypeData
, or even better you can specify this right in your module manifest so it gets done when the module is imported.
Perhaps the best example of this is from Keith Hill's blog where he adds a BigEndianAddress property to [System.Net.IPAddress]
so that they can be easily sorted.
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.Management.Automation.PSCredential</Name>
<Members>
<NoteProperty>
<Name>ServerName</Name>
<Value></Value>
</NoteProperty>
</Members>
</Type>
</Types>
(note, I haven't tested the above)
When you create a New-ModuleManfifest
you can specify the -TypesToProcess
parameter with the file name.
Upvotes: 1