CmdID / PowerShell / Cmdlets / Update
Update-TypeData
Updates the extended type data in the session. PowerShell reference
From the PowerShell reference 22 parameters
What it does
Updates the extended type data in the session. The Update-TypeData cmdlet updates the extended type data in the session by reloading the Types.ps1xml files into memory and adding new extended type data. By default, PowerShell loads extended type data as it is needed. Without parameters, Update-TypeData reloads all of the Types.ps1xml files that it has loaded in the session, including any type files that you added. You can use the parameters of Update-TypeData to add new type files and add and replace extended type data. The Update-TypeData cmdlet can be used to preload all type data. This feature is particularly useful when you are developing types and want to load those new types for testing purposes. Beginning in Windows PowerShell 3.0, you can use Update-TypeData to add and replace extended type data in the session without using a Types.ps1xml file. Type data that is added dynamically, that is, without a file, is added only to the current session. To add the type data to all sessions, add an Update-TypeData command to your PowerShell profile. For more information, see about_Profiles. Also, beginning in Windows PowerShell 3.0, you can use the Get-TypeData cmdlet to get the extended types in the current session and the Remove-TypeData cmdlet to delete extended types from the current session. Exceptions that occur in properties, or from adding properties to an Update-TypeData command, do not report errors. This is to suppress exceptions that would occur in many common types during formatting and outputting. If you are getting .NET properties, you can work around the suppression of exceptions by using method syntax instead, as shown in the following example: "hello".get_Length() Note that method syntax can only be used with .NET properties. Properties that are added by running the Update-TypeData cmdlet cannot use method syntax. For more information about the Types.ps1xml files in PowerShell, see about_Types.ps1xml.
Update-TypeData [[-AppendPath] <String[]>] [-PrependPath <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]Update-TypeData [-MemberType <PSMemberTypes>] [-MemberName <String>] [-Value <Object>] [-SecondValue <Object>] [-TypeConverter <Type>] [-TypeAdapter <Type>] [-SerializationMethod <String>] [-TargetTypeForDeserialization <Type>] [-SerializationDepth <Int32>] [-DefaultDisplayProperty <String>] [-InheritPropertySerializationSet <Nullable1>] [-StringSerializationSource <String>] [-DefaultDisplayPropertySet <String[]>] [-DefaultKeyPropertySet <String[]>] [-PropertySerializationSet <String[]>] -TypeName <String> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]Update-TypeData [-Force] [-TypeData] <TypeData[]> [-WhatIf] [-Confirm] [<CommonParameters>]
Update extended types
Update-TypeDataIdentifyUpdate types multiple times
Update-TypeData -PrependPath TypesA.types.ps1xml, TypesB.types.ps1xml
Update-TypeData -PrependPath TypesA.types.ps1xmlIdentifyAdd a script property to DateTime objects
$typeDataParams = @{
TypeName = 'System.DateTime'
MemberType = 'ScriptProperty'
MemberName = 'Quarter'
Value = {
switch ($this.Month) {
{ $_ -in @(1, 2, 3) } { return 'Q1' }
{ $_ -in @(4, 5, 6) } { return 'Q2' }
{ $_ -in @(7, 8, 9) } { return 'Q3' }
default { return 'Q4' }
}
}
}
Update-TypeData @typeDataParams
(Get-Date).QuarterIdentifyUpdate a type that displays in lists by default
Get-Date | Format-List
Update-TypeData -TypeName "System.DateTime" -DefaultDisplayPropertySet @(
'DateTime'
'DayOfYear'
'Quarter'
)
Get-Date | Format-ListIdentifySet the property a type displays in wide format
Get-Command File | Format-WideIdentifyUpdate type data for a piped object
$typeDataParams = @{
MemberType = 'ScriptProperty'
MemberName = 'SupportsUpdatableHelp'
Value = {
[OutputType([bool])]
param()
return (-not [string]::IsNullOrEmpty($this.HelpInfoUri))
}
}
Get-Module Microsoft.PowerShell.Utility | Update-TypeData @typeDataParams
Get-Module -ListAvailable -Name Microsoft.PowerShell.* |
Format-Table Name, SupportsUpdatableHelpIdentifyIts page in the reference: Update-TypeData.
Parameters
Show its 22 parameters
-AppendPathSpecifies the path to optional .ps1xml files. The specified files are loaded in the order that they are listed after the built-in files are loaded. You can also pipe an AppendPath value to Update-TypeData.-DefaultDisplayPropertySpecifies the property of the type that is displayed by the Format-Wide cmdlet when no other properties are specified.
This value is effective only when there are no wide views defined for the type in a Format.ps1xml file.
This parameter was introduced in Windows PowerShell 3.0.-DefaultDisplayPropertySetSpecifies one or more properties of the type. These properties are displayed by the Format-List, Format-Table, and Format-Custom cmdlets when no other properties are specified.
This value is effective only when there are no list, table, or custom views, respectively, defined for the type in a Format.ps1xml file.
This parameter was introduced in Windows PowerShell 3.0.-DefaultKeyPropertySetSpecifies one or more properties of the type. These properties are used by the Group-Object and
Sort-Object cmdlets when no other properties are specified.
This parameter was introduced in Windows PowerShell 3.0.-ForceIndicates that the cmdlet uses the specified type data, even if type data has already been specified for that type.
This parameter was introduced in Windows PowerShell 3.0.-InheritPropertySerializationSetIndicates whether the set of properties that are serialized is inherited. The default value is
$null. The acceptable values for this parameter are:
- $true. The property set is inherited.
- $false. The property set is not inherited.
- $null. Inheritance is not defined.
This parameter is valid only when the value of the SerializationMethod parameter is SpecificProperties. When the value of this parameter is $false, the PropertySerializationSet parameter is required.
This parameter was introduced in Windows PowerShell 3.0.-MemberNameSpecifies the name of a property or method.
Use this parameter with the TypeName, MemberType, Value and SecondValue parameters to add or change a property or method of a type.
This parameter was introduced in Windows PowerShell 3.0.-MemberTypeSpecifies the type of the member to add or change.
Use this parameter with the TypeName, MemberType, Value and SecondValue parameters to add or change a property or method of a type. The acceptable values for this parameter are:
- AliasProperty
- CodeMethod
- CodeProperty
- Noteproperty
- ScriptMethod
- ScriptProperty
For information about these values, see PSMemberTypes Enumeration.
This parameter was introduced in Windows PowerShell 3.0.-PrependPathSpecifies the path to the optional .ps1xml files. The specified files are loaded in the order that they are listed before the built-in files are loaded.-PropertySerializationSetSpecifies the names of properties that are serialized. Use this parameter when the value of the SerializationMethod parameter is SpecificProperties.-SecondValueSpecifies additional values for AliasProperty, ScriptProperty, CodeProperty, or CodeMethod members.
Use this parameter with the TypeName, MemberType, Value, and SecondValue parameters to add or change a property or method of a type.
When the value of the MemberType parameter is AliasProperty, the value of the SecondValue parameter must be a data type. PowerShell converts (that is, casts) the value of the alias property to the specified type. For example, if you add an alias property that provides an alternate name for a string property, you can also specify a SecondValue of System.Int32 to convert the aliased string value to an integer.
When the value of the MemberType parameter is ScriptProperty, you can use the SecondValue parameter to specify an additional scriptblock. The scriptblock in the value of the Value parameter gets the value of a variable. The scriptblock in the value of the SecondValue parameter sets the value of the variable.
This parameter was introduced in Windows PowerShell 3.0.-SerializationDepthSpecifies how many levels of type objects are serialized as strings. The default value 1 serializes the object and its properties. A value of 0 serializes the object, but not its properties. A value of 2 serializes the object, its properties, and any objects in property values.
This parameter was introduced in Windows PowerShell 3.0.-SerializationMethodSpecifies a serialization method for the type. A serialization method determines which properties of the type are serialized and the technique that is used to serialize them. The acceptable values for this parameter are:
- AllPublicProperties. Serialize all public properties of the type. You can use the
SerializationDepth parameter to determine whether child properties are serialized.
- String. Serialize the type as a string. You can use the StringSerializationSource to specify
a property of the type to use as the serialization result. Otherwise, the type is serialized by
using the ToString method of the object.
- SpecificProperties. Serialize only the specified properties of this type. Use the
PropertySerializationSet parameter to specify the properties of the type that are serialized.
You can also use the InheritPropertySerializationSet parameter to determine whether the
property set is inherited and the SerializationDepth parameter to determine whether child
properties are serialized.
In PowerShell, serialization methods are stored in PSStandardMembers internal objects.
This parameter was introduced in Windows PowerShell 3.0.-StringSerializationSourceSpecifies the name of a property of the type. The value of specified property is used as the serialization result. This parameter is valid only when the value of the SerializationMethod parameter is String.-TargetTypeForDeserializationSpecifies the type to which object of this type are converted when they are deserialized.
This parameter was introduced in Windows PowerShell 3.0.-TypeAdapterSpecifies the type of a type adapter, such as Microsoft.PowerShell.Cim.CimInstanceAdapter. A type adapter enables PowerShell to get the members of a type.
This parameter was introduced in Windows PowerShell 3.0.-TypeConverterSpecifies a type converter to convert values between different types. If a type converter is defined for a type, an instance of the type converter is used for the conversion.
Enter a System.Type value that is derived from the System.ComponentModel.TypeConverter or System.Management.Automation.PSTypeConverter classes.
This parameter was introduced in Windows PowerShell 3.0.-TypeDataSpecifies an array of type data that this cmdlet adds to the session. Enter a variable that contains a TypeData object or a command that gets a TypeData object, such as a Get-TypeData command. You can also pipe a TypeData object to Update-TypeData.
This parameter was introduced in Windows PowerShell 3.0.-TypeNameSpecifies the name of the type to extend.
For types in the System namespace, enter the short name. Otherwise, the full type name is required. Wildcards are not supported.
You can pipe type names to Update-TypeData. When you pipe an object to Update-TypeData,
Update-TypeData gets the type name of the object and type data to the object type.
Use this parameter with the MemberName, MemberType, Value and SecondValue parameters to add or change a property or method of a type.
This parameter was introduced in Windows PowerShell 3.0.-ValueSpecifies the value of the property or method.
If you add an AliasProperty, CodeProperty, ScriptProperty, or CodeMethod member, you can use the SecondValue parameter to add additional information.
Use this parameter with the MemberName, MemberType, Value and SecondValue parameters to add or change a property or method of a type.
This parameter was introduced in Windows PowerShell 3.0.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.