|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Removes a property from a LogicMonitor device group. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | +The Remove-LMDeviceGroupProperty function removes a specified property from a LogicMonitor device group. It can remove the property either by providing the device group ID or the device group name. |
| 7 | +
|
| 8 | +.PARAMETER Id |
| 9 | +The ID of the device group from which the property should be removed. This parameter is mandatory when using the 'Id' parameter set. |
| 10 | +
|
| 11 | +.PARAMETER Name |
| 12 | +The name of the device group from which the property should be removed. This parameter is mandatory when using the 'Name' parameter set. |
| 13 | +
|
| 14 | +.PARAMETER PropertyName |
| 15 | +The name of the property to be removed. This parameter is mandatory. |
| 16 | +
|
| 17 | +.EXAMPLE |
| 18 | +Remove-LMDeviceGroupProperty -Id 1234 -PropertyName "Property1" |
| 19 | +Removes the property named "Property1" from the device with ID 1234. |
| 20 | +
|
| 21 | +.EXAMPLE |
| 22 | +Remove-LMDeviceGroupProperty -Name "Device1" -PropertyName "Property2" |
| 23 | +Removes the property named "Property2" from the device with the name "Device1". |
| 24 | +
|
| 25 | +.INPUTS |
| 26 | +None. |
| 27 | +
|
| 28 | +.OUTPUTS |
| 29 | +System.Management.Automation.PSCustomObject. The output object contains the following properties: |
| 30 | +- Id: The ID of the device group from which the property was removed. |
| 31 | +- Message: A message indicating the success of the operation. |
| 32 | +
|
| 33 | +.NOTES |
| 34 | +- This function requires a valid LogicMonitor API authentication. Make sure you are logged in before running any commands. |
| 35 | +- Use the Connect-LMAccount function to log in before using this function. |
| 36 | +#> |
| 37 | +Function Remove-LMDeviceGroupProperty { |
| 38 | + |
| 39 | + [CmdletBinding(DefaultParameterSetName = 'Id', SupportsShouldProcess, ConfirmImpact = 'High')] |
| 40 | + Param ( |
| 41 | + [Parameter(Mandatory, ParameterSetName = 'Id')] |
| 42 | + [Int]$Id, |
| 43 | + |
| 44 | + [Parameter(Mandatory, ParameterSetName = 'Name')] |
| 45 | + [String]$Name, |
| 46 | + |
| 47 | + [Parameter(Mandatory)] |
| 48 | + [String]$PropertyName |
| 49 | + |
| 50 | + ) |
| 51 | + Begin {} |
| 52 | + Process { |
| 53 | + #Check if we are logged in and have valid api creds |
| 54 | + If ($Script:LMAuth.Valid) { |
| 55 | + |
| 56 | + #Lookup Id if supplying username |
| 57 | + If ($Name) { |
| 58 | + $LookupResult = (Get-LMDeviceGroup -Name $Name).Id |
| 59 | + If (Test-LookupResult -Result $LookupResult -LookupString $Name) { |
| 60 | + return |
| 61 | + } |
| 62 | + $Id = $LookupResult |
| 63 | + } |
| 64 | + |
| 65 | + #Build header and uri |
| 66 | + $ResourcePath = "/device/groups/$Id/properties/$PropertyName" |
| 67 | + |
| 68 | + If ($Name) { |
| 69 | + $Message = "Id: $Id | Name: $Name | Property: $PropertyName" |
| 70 | + } |
| 71 | + Else { |
| 72 | + $Message = "Id: $Id | Property: $PropertyName" |
| 73 | + } |
| 74 | + |
| 75 | + Try { |
| 76 | + If ($PSCmdlet.ShouldProcess($Message, "Remove Device Group Property")) { |
| 77 | + $Headers = New-LMHeader -Auth $Script:LMAuth -Method "DELETE" -ResourcePath $ResourcePath |
| 78 | + $Uri = "https://$($Script:LMAuth.Portal).logicmonitor.com/santaba/rest" + $ResourcePath |
| 79 | + |
| 80 | + Resolve-LMDebugInfo -Url $Uri -Headers $Headers[0] -Command $MyInvocation |
| 81 | + |
| 82 | + #Issue request |
| 83 | + $Response = Invoke-RestMethod -Uri $Uri -Method "DELETE" -Headers $Headers[0] -WebSession $Headers[1] |
| 84 | + |
| 85 | + $Result = [PSCustomObject]@{ |
| 86 | + Id = $Id |
| 87 | + Message = "Successfully removed ($Message)" |
| 88 | + } |
| 89 | + |
| 90 | + Return $Result |
| 91 | + } |
| 92 | + } |
| 93 | + Catch [Exception] { |
| 94 | + $Proceed = Resolve-LMException -LMException $PSItem |
| 95 | + If (!$Proceed) { |
| 96 | + Return |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + Else { |
| 101 | + Write-Error "Please ensure you are logged in before running any commands, use Connect-LMAccount to login and try again." |
| 102 | + } |
| 103 | + } |
| 104 | + End {} |
| 105 | +} |
0 commit comments