SnipeitPS/SnipeitPS/Public/Set-SnipeitDepartment.ps1

116 lines
2.9 KiB
PowerShell
Raw Normal View History

2021-06-13 18:41:27 +03:00
<#
.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
2021-07-08 23:59:31 +03:00
.PARAMETER image
Image file name and path for item
.PARAMETER image_delete
Remove current image
2021-07-14 11:09:12 +03:00
.PARAMETER RequestType
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
2021-06-13 18:41:27 +03:00
.PARAMETER url
2021-08-02 08:14:38 +03:00
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
2021-06-13 18:41:27 +03:00
.PARAMETER apiKey
2021-08-02 08:14:38 +03:00
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
2021-06-13 18:41:27 +03:00
.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,
2021-06-16 10:37:57 +03:00
[Nullable[System.Int32]]$company_id,
2021-06-13 18:41:27 +03:00
2021-06-16 10:37:57 +03:00
[Nullable[System.Int32]]$location_id,
2021-06-13 18:41:27 +03:00
2021-06-16 10:37:57 +03:00
[Nullable[System.Int32]]$manager_id,
2021-06-13 18:41:27 +03:00
[string]$notes,
2021-07-08 23:59:31 +03:00
[ValidateScript({Test-Path $_})]
[string]$image,
[switch]$image_delete=$false,
2021-07-14 11:09:12 +03:00
[ValidateSet("Put","Patch")]
[string]$RequestType = "Patch",
2021-07-31 22:25:13 +03:00
[parameter(mandatory = $false)]
2021-06-13 18:41:27 +03:00
[string]$url,
2021-07-31 22:25:13 +03:00
[parameter(mandatory = $false)]
2021-06-13 18:41:27 +03:00
[string]$apiKey
)
begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
}
process {
foreach ($department_id in $id) {
$Parameters = @{
2021-08-02 08:14:38 +03:00
Api = "/api/v1/departments/$department_id"
2021-07-14 11:09:12 +03:00
Method = $RequestType
Body = $Values
2021-06-13 18:41:27 +03:00
}
2021-09-03 19:44:43 +03:00
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
2021-08-02 08:14:38 +03:00
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
2021-08-22 22:23:08 +03:00
Set-SnipeitPSLegacyApiKey -apiKey $apikey
2021-08-02 08:14:38 +03:00
}
2021-09-03 19:44:43 +03:00
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
2021-08-02 08:14:38 +03:00
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
2021-08-22 22:23:08 +03:00
Set-SnipeitPSLegacyUrl -url $url
2021-08-02 08:14:38 +03:00
}
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
2021-06-13 18:41:27 +03:00
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
end {
# reset legacy sessions
2021-09-03 19:44:43 +03:00
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
Reset-SnipeitPSLegacyApi
}
}
2021-06-13 18:41:27 +03:00
}