Skip to content

Latest commit

 

History

History
211 lines (150 loc) · 5.06 KB

New-PSPropertySet.md

File metadata and controls

211 lines (150 loc) · 5.06 KB
external help file Module Name online version schema
PSTypeExtensionTools-help.xml
PSTypeExtensionTools
2.0.0

New-PSPropertySet

SYNOPSIS

Create a new property set ps1xml file.

SYNTAX

new (Default)

New-PSPropertySet [-Typename] <String> -Name <String> -Properties <String[]> -FilePath <String> [-NoClobber] [-WhatIf] [-Confirm] [<CommonParameters>]

append

New-PSPropertySet [-Typename] <String> -Name <String> -Properties <String[]> -FilePath <String> [-Append] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

PowerShell has a concept of property sets. A property set allows you to reference a collection of properties with a single name. Property set definitions have to be stored in a .ps1xml file. This command will create the file for you. You also have the option to append to an existing file.

Use Update-TypeData to append the file. If you import your file more than once in the same session, you might see a warning about existing property names. Existing entries won't be overwritten.

Property set updates are not persistent. You will need to import your ps1xml, ideally in your PowerShell profile script.

EXAMPLES

Example 1

PS C:\> New-PSPropertySet -typename System.IO.FileInfo -name info -properties Fullname,IsReadOnly,CreationTime,LastWriteTime -filepath c:\work\myfileinfo.types.ps1xml
PS C:\> Update-TypeData C:\work\myfileinfo.types.ps1xml
PS C:\> dir c:\work -file | select info

FullName                     IsReadOnly CreationTime           LastWriteTime
--------                     ---------- ------------           -------------
C:\work\a.csv                False 12/1/2023 11:30:55 AM  12/1/2023 11:30:55 AM
C:\work\a.dat                False 2/12/2024 5:36:55 PM   2/12/2024 5:36:55 PM
C:\work\a.md                 False 11/6/2023 9:50:19 AM   12/1/2023 12:40:03 PM
C:\work\a.txt                False 12/31/2023 9:10:15 AM  12/31/2023 9:10:15 AM
C:\work\a.xml                False 12/31/2023 12:15:44 PM 12/31/2023 12:15:44 PM
C:\work\aa.ps1               False 12/31/2023 9:13:16 AM  12/31/2023 9:13:16 AM
C:\work\aa.txt               False 12/31/2023 9:11:18 AM  12/31/2023 9:11:18 AM
...

The first command creates the property set definition file. The second command loads it into PowerShell. The last command uses the custom property set.

PARAMETERS

-Append

Append to an existing file.

Type: SwitchParameter
Parameter Sets: append
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts 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: False

-FilePath

Enter the name of the .ps1xml file to create. It must have a .ps1xml file extension and ideally should take the format .types.ps1xml.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Name

Enter the new property set name. It should be alphanumeric.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-NoClobber

Don't overwrite an existing file.

Type: SwitchParameter
Parameter Sets: new
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Properties

Enter the existing property names or aliases to belong to this property set. If using aliases, they must be defined in your PowerShell session before you can use the custom property set.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Typename

Enter the object typename. This is the value you would see in Get-Member.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows 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: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

None

OUTPUTS

System.IO.FileInfo

NOTES

Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/

RELATED LINKS

Update-TypeData

Add-PSTypeExtension