SnipeitPS/SnipeitPS/Public/New-SnipeitDepartment.ps1
2021-08-22 22:23:08 +03:00

90 lines
2.1 KiB
PowerShell

<#
.SYNOPSIS
Creates a department
.DESCRIPTION
Creates a new department on Snipe-It system
.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
Department Image filename and path
.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
New-SnipeitDepartment -name "Department1" -company_id 1 -localtion_id 1 -manager_id 3
#>
function New-SnipeitDepartment() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[int]$company_id,
[int]$location_id,
[int]$manager_id,
[string]$notes,
[ValidateScript({Test-Path $_})]
[string]$image,
[switch]$image_delete=$false,
[parameter(mandatory = $false)]
[string]$url,
[parameter(mandatory = $false)]
[string]$apiKey
)
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{
Api = "/api/v1/departments"
Method = 'POST'
Body = $Values
}
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
}