Public/Tools/Set-ConfigurationItemProperty.ps1
function Set-ConfigurationItemProperty { <# .SYNOPSIS Sets the value of a given ConfigurationItem property by key .DESCRIPTION A ConfigurationItem may have zero or more Property objects in the Properties array. Each property has a key name and a value. Since the Properties property on a ConfigurationItem has no string-based indexer, you are required to search the array of properties for the one with the Key you're interested in, and then set the Value property on it. This cmdlet is a simple wrapper which does the Where-Object for you, throws an error if the Key does not exist, and optionally passes the modified ConfigurationItem back into the pipeline. .PARAMETER InputObject A [VideoOS.ConfigurationApi.ClientService.ConfigurationItem] with a property to be modified. .PARAMETER Key A string representing the key of the property to be modified. .Parameter Value A string value to be used as the new value for the property named by the given key. .Parameter PassThru Pass the modified ConfigurationItem from $InputObject back into the pipeline. .EXAMPLE PS C:\> Get-ConfigurationItem -Path / | Set-ConfigurationItemProperty -Key Description -Value 'A new description' -PassThru | Set-ConfigurationItem Gets a ConfigurationItem representing the Management Server, changes the Description property, and pushes the change to the Management Server using Set-ConfigurationItem. #> [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipeline)] [VideoOS.ConfigurationApi.ClientService.ConfigurationItem] [ValidateNotNullOrEmpty()] $InputObject, [Parameter(Mandatory)] [string] [ValidateNotNullOrEmpty()] $Key, [Parameter(Mandatory)] [string] [ValidateNotNullOrEmpty()] $Value, [Parameter()] [switch] $PassThru ) process { $property = $InputObject.Properties | Where-Object Key -eq $Key if ($null -eq $property) { Write-Error -Message "Key '$Key' not found on configuration item $($InputObject.Path)" -TargetObject $InputObject -Category InvalidArgument return } $property.Value = $Value if ($PassThru) { $InputObject } } } |