SnipeitPS/SnipeitPS/Public/Set-SnipeitDepartment.ps1
2021-09-03 19:44:43 +03:00

115 lines
2.9 KiB
PowerShell

<#
.SYNOPSIS
Updates a department
.DESCRIPTION
Updates the department on Snipe-It system
.PARAMETER id
Id number of Department
.PARAMETER name
Department Name
.PARAMETER company_id
ID number of company
.PARAMETER location_id
ID number of location
.PARAMETER manager_id
ID number of manager
.PARAMETER image
Image file name and path for item
.PARAMETER image_delete
Remove current image
.PARAMETER RequestType
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
.PARAMETER url
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
.PARAMETER apiKey
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
.EXAMPLE
Set-SnipeitDepartment -id 4 -manager_id 3
#>
function Set-SnipeitDepartment() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[string]$name,
[Nullable[System.Int32]]$company_id,
[Nullable[System.Int32]]$location_id,
[Nullable[System.Int32]]$manager_id,
[string]$notes,
[ValidateScript({Test-Path $_})]
[string]$image,
[switch]$image_delete=$false,
[ValidateSet("Put","Patch")]
[string]$RequestType = "Patch",
[parameter(mandatory = $false)]
[string]$url,
[parameter(mandatory = $false)]
[string]$apiKey
)
begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
}
process {
foreach ($department_id in $id) {
$Parameters = @{
Api = "/api/v1/departments/$department_id"
Method = $RequestType
Body = $Values
}
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey
}
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$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') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
Reset-SnipeitPSLegacyApi
}
}
}