Functions/Remove-IACategory.ps1
Function Remove-IACategory { [CmdletBinding()] Param( [Parameter(Mandatory = $true, ParameterSetName = 'IACategory', ValueFromPipeline = $true)] [PSObject] $IACategory, [Parameter(Mandatory = $true, ParameterSetName = 'Id', ValueFromPipelineByPropertyName = $true)] [PSObject] $Id ) Process{ if($IACategory){ foreach($category in $IACategory){ $ViewsToBeDeleted = Get-IAView -All | Where-Object -Property CategoryId -eq $category.Id foreach($view in $ViewsToBeDeleted) { Remove-IAView -Id $view.Id } $Uri = "Categories($($category.Id))" $response = Invoke-IAQuery -QueryUrl $Uri -Method Delete if ($null -eq $response.value) { return $null } return $response.value } } if($Id){ foreach($item in $Id){ $ViewsToBeDeleted = Get-IAView -All | Where-Object -Property CategoryId -eq $item foreach($view in $ViewsToBeDeleted) { Remove-IAView -Id $view.Id } $Uri = "Categories($item)" $response = Invoke-IAQuery -QueryUrl $Uri -Method Delete if ($null -eq $response.value) { return $null } return $response.value } } } } |