SnipeitPS/SnipeitPS/Public/New-SnipeitSupplier.ps1

137 lines
2.9 KiB
PowerShell
Raw Normal View History

2021-07-09 15:17:41 +03:00
<#
.SYNOPSIS
Creates a supplier
.DESCRIPTION
Creates a new supplier on Snipe-It system
.PARAMETER name
Department Name
.PARAMETER address
Address line 1 of supplier
.PARAMETER address2
Address line 1 of supplier
.PARAMETER city
City
.PARAMETER state
State
.PARAMETER country
Country
.PARAMETER zip
Zip code
.PARAMETER phone
Phone number
.PARAMETER fax
Fax number
.PARAMETER email
Email address
.PARAMETER contact
Contact person
.PARAMETER notes
Email address
.PARAMETER image
Image file name and path for item
.PARAMETER url
2021-08-02 08:14:38 +03:00
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
2021-07-09 15:17:41 +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-07-09 15:17:41 +03:00
.EXAMPLE
New-SnipeitDepartment -name "Department1" -company_id 1 -localtion_id 1 -manager_id 3
#>
function New-SnipeitSupplier() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[string]$address,
[string]$address2,
[string]$city,
[string]$state,
[string]$country,
[string]$zip,
[string]$phone,
[string]$fax,
[string]$email,
[string]$contact,
[string]$notes,
[ValidateScript({Test-Path $_})]
[string]$image,
2021-07-31 22:25:13 +03:00
[parameter(mandatory = $false)]
2021-07-09 15:17:41 +03:00
[string]$url,
2021-07-31 22:25:13 +03:00
[parameter(mandatory = $false)]
2021-07-09 15:17:41 +03:00
[string]$apiKey
)
2021-08-23 18:01:09 +03:00
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{
Api = "/api/v1/suppilers"
Method = 'POST'
Body = $Values
}
2021-09-03 19:44:43 +03:00
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
2021-08-23 18:01:09 +03:00
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey
}
2021-09-03 19:44:43 +03:00
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
2021-08-23 18:01:09 +03:00
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
2021-07-09 15:17:41 +03:00
}
2021-08-23 18:01:09 +03:00
process {
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
2021-08-02 08:14:38 +03:00
2021-08-23 18:01:09 +03:00
$result
2021-08-02 08:14:38 +03:00
}
2021-08-23 18:01:09 +03:00
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) {
2021-08-23 18:01:09 +03:00
Reset-SnipeitPSLegacyApi
}
}
2021-07-09 15:17:41 +03:00
}