mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-15 18:55:47 +00:00
71 lines
2 KiB
PowerShell
71 lines
2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Removes department from Snipe-it asset system
|
|
.DESCRIPTION
|
|
Removes department or multiple departments from Snipe-it asset system
|
|
.PARAMETER ID
|
|
Unique ID For department to be removed
|
|
.PARAMETER url
|
|
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
|
|
|
.PARAMETER apiKey
|
|
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
|
|
|
.EXAMPLE
|
|
Remove-SnipeitDepartment -ID 44
|
|
|
|
.EXAMPLE
|
|
Get-SnipeitDepartment | Where-object {$_.name -like '*head*'} | Remove-SnipeitDepartment
|
|
#>
|
|
|
|
function Remove-SnipeitDepartment () {
|
|
[CmdletBinding(
|
|
SupportsShouldProcess = $true,
|
|
ConfirmImpact = "Low"
|
|
)]
|
|
|
|
Param(
|
|
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
|
[int[]]$id,
|
|
|
|
[parameter(mandatory = $false)]
|
|
[string]$url,
|
|
|
|
[parameter(mandatory = $false)]
|
|
[string]$apiKey
|
|
|
|
)
|
|
begin {
|
|
}
|
|
process {
|
|
foreach($department_id in $id) {
|
|
$Parameters = @{
|
|
Api = "/api/v1/departments/$department_id"
|
|
Method = 'Delete'
|
|
}
|
|
|
|
if ($PSBoundParameters.ContainsKey('apiKey')) {
|
|
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
|
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
|
}
|
|
|
|
if ($PSBoundParameters.ContainsKey('url')) {
|
|
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
|
Set-SnipeitPSLegacyUrl -url $url
|
|
}
|
|
|
|
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
|
$result = Invoke-SnipeitMethod @Parameters
|
|
}
|
|
|
|
$result
|
|
}
|
|
}
|
|
|
|
end {
|
|
# reset legacy sessions
|
|
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
|
|
Reset-SnipeitPSLegacyApi
|
|
}
|
|
}
|
|
}
|