Add and remove items from a property value that contains a collection of objects.
Syntax Update-List [-Add Object] [-Remove Object] [[-Property] string] [-InputObject psobject] [CommonParameters] Update-List -Replace Object [[-Property] string] [-InputObject psobject] [CommonParameters] Key -Add Object The property values to be added to the collection. Enter the values in the order that they should appear in the collection. -InputObject psobject The objects to be updated. The object to be updated may be piped to Update-List. -Property string The property that contains the collection that is being updated. If omitted, Update-List will return an object that represents the change instead of changing the object. -Remove Object The property values to be removed from the collection. -Replace Object Specifies a new collection. This parameter replaces all items in the original collection with the items specified by this parameter. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
Update-List adds items to and removes items from a property value of an object, and then it returns the
updated object. This cmdlet is designed for properties that contain collections of objects.
The -Add and -Remove parameters add individual items to and remove them from the collection. The -Replace parameter replaces the entire collection.
If no property is specified in the command, Update-List will return an object that describes the update instead of updating the object. The update object may be submitted to cmdlets that change objects, such as Set-* cmdlets.
This cmdlet works only when the property that is being updated supports the IList interface that Update-List uses. Also, any Set-* cmdlets that accept an update must support the IList interface. The core cmdlets that are installed with PowerShell do not support this interface.
Add A and B and remove X and Y from the Aliases property of an Exchange mailbox:
PS C:\> get-mailbox | update-list -Property aliases -Add "A","B" -Remove "X","Y" | set-mailbox Hello
Add A and B to the value of the Aliases property of a Exchange mailbox and remove X and Y. This command has the same effect as the previous command, although it has a slightly different format:
PS C:\> $mb = get-mailbox
PS C:\> update-list -InputObject $mb -Property aliases -Add "A","B" -Remove "X", "Y" | set-mailbox
Add A and B and remove X and Y from the Aliases property of an Exchange mailbox, again this command has the same effect:
PS C:\> get-mailbox | set-mailbox -alias (update-list -Add "A", "B" -Remove "X","Y")
“You never have to change anything you got up in the middle of the night to write” ~ Saul Bellow
Related PowerShell Cmdlets:
Set-Content - Set content in an item (specific location).
Set-Item - Change the value of an item.