| external help file | PSTypeExtensionTools-help.xml |
|---|---|
| Module Name | PSTypeExtensionTools |
| online version | https://jdhitsolutions.com/yourls/0f26dc |
| schema | 2.0.0 |
Add a new type extension.
Add-PSTypeExtension [-TypeName] <String> -MemberType <String> -MemberName <String> -Value <Object> [-IncludeDeserialized] [-WhatIf] [-Confirm] [<CommonParameters>]Use this command to define a new type extension for a given object type. Existing members with the same name will be overwritten, so you can also use this as a "Set" command.
PS C:\> Add-PSTypeExtension -TypeName system.string -MemberType AliasProperty -MemberName Size -Value LengthDefine an alias property called Size for the Length property of the String type.
PS C:\> Add-PSTypeExtension -TypeName system.string -MemberType ScriptMethod -MemberName IsIPAddress -value {$this -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"}
PS C:\> $s = "10.4.7.10"
PS C:\> $s.IsIPAddress()
TrueDefine a script property called IsIPAddress which will return True if the string matches the pattern for an IP address.
PS C:\ Add-PSTypeExtension -TypeName System.IO.FileInfo -MemberType AliasProperty -MemberName Size -value Length -IncludeDeserializedCreate an alias called Size using the Length property on file objects. This expression will also create it for the deserialized version of the type so that you can use it with remoting results.
PS C:\> Show-Command Add-PSTypeExtensionHere is an easy way to get a GUI to create a new type extension.
The name of your type extension.
Type: String
Parameter Sets: (All)
Aliases: Name
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThe member type. You cannot use this command to define CodeMethods or CodeProperties.
Type: String
Parameter Sets: (All)
Aliases: Type
Accepted values: AliasProperty, NoteProperty, ScriptProperty, ScriptMethod
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseEnter the name of a type like System.IO.FileInfo.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseThe value for your type extension. Remember to enclose scriptblocks in {} and use $this.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseCreate the extension in the deserialized version of the specified type along with the specified type.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
This command has aliases of atex and Set-PSTypeExtension.
Learn more about PowerShell: http://jdhitsolutions.com/yourls/newsletter