Functions/Hue/Remove-HueRoom.ps1
function Remove-HueRoom { <# .Synopsis Removes Hue Groups .Description Removes Groups from one or more Hue Bridges .Example Remove-HueRoom -Name 'HueRoomName' .Link Get-HueRoom .Link Get-HueBridge .Link Send-HueBridge #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="High")] [OutputType([PSObject])] param( #If provided, will filter returned items by name [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] [string[]] $Name, #If set, will treat the Name parameter as a regular expression pattern. By default, Name will be treated as a wildcard [Parameter(ValueFromPipelineByPropertyName=$true)] [switch] $RegularExpression, #If set, will treat the Name parameter as a specific match [Parameter(ValueFromPipelineByPropertyName=$true)] [switch] $ExactMatch, #If provided, will filter returned items by ID [Parameter(ValueFromPipelineByPropertyName=$true)] [string[]] $ID ) process { $GetHueBridgeParametersDefault = ConvertFrom-Json @' { "Groups": true } '@ $GetHueBridgeParameters = @{} foreach ($property in $GetHueBridgeParametersDefault.psobject.properties) { $GetHueBridgeParameters[$property.Name] = $property.Value if ($property.Value -is [string] -and $property.Value.StartsWith('$')) { $GetHueBridgeParameters[$property.Name] = $executionContext.SessionState.PSVariable.Get($property.Value.Substring(1)).Value } } #region Copy Parameters from Get-HueBridge $MyParameters = [Ordered]@{} + $psBoundParameters # Copy $PSBoundParameters foreach ($in in 'Name','ExactMatch','RegularExpression','ID','Detailed') { if (-not $GetHueBridgeParameters.$in -and $myParameters.$in) { $GetHueBridgeParameters.$in = $myParameters.$in } } #endregion Copy Parameters from Get-HueBridge Get-HueBridge @GetHueBridgeParameters | Where-Object {$PSCmdlet.ShouldProcess("Delete Group$($_.Name) ($($_.ID))")}| Send-HueBridge -Method DELETE -Command {"groups/$($_.ID)"} } } |