begin, process, end

This commit is contained in:
Petri Asikainen 2021-08-23 18:01:09 +03:00
parent 3446a885dc
commit 923838e15f
37 changed files with 1357 additions and 1201 deletions

View file

@ -36,18 +36,17 @@ function Invoke-SnipeitMethod {
BEGIN { BEGIN {
#use legacy per command based url and apikey #use legacy per command based url and apikey
if ( $null -ne $SnipeitPSSession.legacyUrl -and $null -ne $SnipeitPSSession.legacyApiKey ) { if ( $null -ne $SnipeitPSSession.legacyUrl -and $null -ne $SnipeitPSSession.legacyApiKey ) {
[string]$Url = $SnipeitPSSession.legacyrl [string]$Url = $SnipeitPSSession.legacyUrl
Write-Debug "Invoke-SnipeitMethod url: $Url" Write-Debug "Invoke-SnipeitMethod url: $Url"
$Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.legacyApiKey $Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.legacyApiKey
throw "Cannot connect to Snipe it. Please run Connect-SnipePS to set connection information."
} elseif ($null -ne $SnipeitPSSession.url -and $null -ne $SnipeitPSSession.apiKey) { } elseif ($null -ne $SnipeitPSSession.url -and $null -ne $SnipeitPSSession.apiKey) {
} else {
[string]$Url = $SnipeitPSSession.url [string]$Url = $SnipeitPSSession.url
Write-Debug "Invoke-SnipeitMethod url: $Url" Write-Debug "Invoke-SnipeitMethod url: $Url"
$Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.apiKey $Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.apiKey
} else {
throw "Please use Connect-SnipeitPS to setup connection before any other commands."
} }
# Validation of parameters # Validation of parameters
@ -57,9 +56,6 @@ function Invoke-SnipeitMethod {
Throw $exception Throw $exception
} }
# Double check those old deprecated -url parameters
$Url = $Url.TrimEnd('/')
#Build request uri #Build request uri
$apiUri = "$Url$Api" $apiUri = "$Url$Api"
#To support images "image" property have be handled before this #To support images "image" property have be handled before this

View file

@ -6,6 +6,7 @@ function Reset-SnipeitPSLegacyApi {
param( param(
) )
process { process {
Write-Verbose 'Reset-SnipeitPSLegacyApi'
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$SnipeitPSSession.legacyUrl = $null $SnipeitPSSession.legacyUrl = $null
$SnipeitPSSession.legacyApiKey = $null $SnipeitPSSession.legacyApiKey = $null

View file

@ -8,7 +8,7 @@ function Set-SnipeitPSLegacyUrl {
) )
process { process {
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$SnipeitPSSession.legacyUrl = $url $SnipeitPSSession.legacyUrl = $url.TrimEnd('/')
} }
} }
} }

View file

@ -69,7 +69,7 @@ function Connect-SnipeitPS {
switch ($PsCmdlet.ParameterSetName) { switch ($PsCmdlet.ParameterSetName) {
'Connect with url and apikey' { 'Connect with url and apikey' {
$SnipeitPSSession.url = $url.TrimEnd('/') $SnipeitPSSession.url = $url.TrimEnd('/')
$SnipeitPSSession.apiKey = $apiKey | ConvertTo-SecureString -AsPlainText $SnipeitPSSession.apiKey = ConvertTo-SecureString -AsPlainText -String $apiKey
} }
'Connect with url and secure apikey' { 'Connect with url and secure apikey' {

View file

@ -85,55 +85,61 @@ function Get-SnipeitAccessory() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
switch($PsCmdlet.ParameterSetName) { switch($PsCmdlet.ParameterSetName) {
'Search' {$api = "/api/v1/accessories"} 'Search' {$api = "/api/v1/accessories"}
'Get by ID' {$api= "/api/v1/accessories/$id"} 'Get by ID' {$api= "/api/v1/accessories/$id"}
'Accessories checked out to user id' {$api = "/api/v1/users/$user_id/accessories"} 'Accessories checked out to user id' {$api = "/api/v1/users/$user_id/accessories"}
} }
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitAccessory @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitAccessory @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -32,30 +32,33 @@ function Get-SnipeitAccessoryOwner() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
$Parameters = @{
Api = "/api/v1/accessories/$id/checkedout"
Method = 'GET'
}
$Parameters = @{ if ($PSBoundParameters.ContainsKey('apiKey')) {
Api = "/api/v1/accessories/$id/checkedout" Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Method = 'GET' Set-SnipeitPSLegacyApiKey -apiKey $apikey
}
if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
}
process {
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { end {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyApiKey -apiKey $apikey if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
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
}
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
return $result
} }

View file

@ -77,59 +77,64 @@ function Get-SnipeitActivity() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
if (($target_type -and -not $target_id) -or if (($target_type -and -not $target_id) -or
($target_id -and -not $target_type)) { ($target_id -and -not $target_type)) {
throw "Please specify both target_type and target_id" throw "Please specify both target_type and target_id"
} }
if (($item_type -and -not $item_id) -or if (($item_type -and -not $item_id) -or
($item_id -and -not $item_type)) { ($item_id -and -not $item_type)) {
throw "Please specify both item_type and item_id" throw "Please specify both item_type and item_id"
} }
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{ $Parameters = @{
Api = "/api/v1/reports/activity" Api = "/api/v1/reports/activity"
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitActivity @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitActivity @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -206,61 +206,67 @@ function Get-SnipeitAsset() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
switch ($PsCmdlet.ParameterSetName) { switch ($PsCmdlet.ParameterSetName) {
'Search' { $api = "/api/v1/hardware" } 'Search' { $api = "/api/v1/hardware" }
'Get with id' {$api= "/api/v1/hardware/$id"} 'Get with id' {$api= "/api/v1/hardware/$id"}
'Get with asset tag' {$api= "/api/v1/hardware/bytag/$asset_tag"} 'Get with asset tag' {$api= "/api/v1/hardware/bytag/$asset_tag"}
'Get with serial' { $api= "/api/v1/hardware/byserial/$serial"} 'Get with serial' { $api= "/api/v1/hardware/byserial/$serial"}
'Assets due auditing soon' {$api = "/api/v1/hardware/audit/due"} 'Assets due auditing soon' {$api = "/api/v1/hardware/audit/due"}
'Assets overdue for auditing' {$api = "/api/v1/hardware/audit/overdue"} 'Assets overdue for auditing' {$api = "/api/v1/hardware/audit/overdue"}
'Assets checked out to user id'{$api = "/api/v1/users/$user_id/assets"} 'Assets checked out to user id'{$api = "/api/v1/users/$user_id/assets"}
'Assets with component id' {$api = "/api/v1/components/$component_id/assets"} 'Assets with component id' {$api = "/api/v1/components/$component_id/assets"}
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
Write-Verbose "Callargs: $($callargs | convertto-json)"
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitAsset @callargs
$res
if ( $res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
Write-Verbose "Callargs: $($callargs | convertto-json)"
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitAsset @callargs
$res
if ( $res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -60,50 +60,55 @@ function Get-SnipeitAssetMaintenance() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Parameters = @{
Api = "/api/v1/maintenances"
$Parameters = @{ Method = 'Get'
Api = "/api/v1/maintenances" GetParameters = $SearchParameter
Method = 'Get' }
GetParameters = $SearchParameter
} if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
if ($PSBoundParameters.ContainsKey('apiKey')) { Set-SnipeitPSLegacyApiKey -apiKey $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."
if ($PSBoundParameters.ContainsKey('url')) { Set-SnipeitPSLegacyUrl -url $url
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitAssetMaintenance @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitAssetMaintenance @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -59,58 +59,64 @@ function Get-SnipeitCategory() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$api = "/api/v1/categories" $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($search -and $id ) { $api = "/api/v1/categories"
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
}
if ($id) { if ($search -and $id ) {
$api= "/api/v1/categories/$id" Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
$Parameters = @{ if ($id) {
Api = $api $api= "/api/v1/categories/$id"
Method = 'Get' }
GetParameters = $SearchParameter
} $Parameters = @{
Api = $api
if ($PSBoundParameters.ContainsKey('apiKey')) { Method = 'Get'
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." GetParameters = $SearchParameter
Set-SnipeitPSLegacyApiKey -apiKey $apikey }
}
if ($PSBoundParameters.ContainsKey('apiKey')) {
if ($PSBoundParameters.ContainsKey('url')) { Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Set-SnipeitPSLegacyApiKey -apiKey $apikey
Set-SnipeitPSLegacyUrl -url $url }
}
if ($PSBoundParameters.ContainsKey('url')) {
if ($all) { Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
$offstart = $(if ($offset) {$offset} Else {0}) Set-SnipeitPSLegacyUrl -url $url
$callargs = $SearchParameter }
$callargs.Remove('all') }
process {
while ($true) { if ($all) {
$callargs['offset'] = $offstart $offstart = $(if ($offset) {$offset} Else {0})
$callargs['limit'] = $limit $callargs = $SearchParameter
$res=Get-SnipeitCategory @callargs $callargs.Remove('all')
$res
if ($res.count -lt $limit) { while ($true) {
break $callargs['offset'] = $offstart
} $callargs['limit'] = $limit
$offstart = $offstart + $limit $res=Get-SnipeitCategory @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions end {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { # reset legacy sessions
Reset-SnipeitPSLegacyApi if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -61,58 +61,63 @@ function Get-SnipeitCompany() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$api = "/api/v1/companies" $api = "/api/v1/companies"
if ($search -and $id ) { if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
if ($id) { if ($id) {
$api= "/api/v1/companies/$id" $api= "/api/v1/companies/$id"
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
} }
}
if ($all) { process {
$offstart = $(if ($offset) {$offset} Else {0}) if ($all) {
$callargs = $SearchParameter $offstart = $(if ($offset) {$offset} Else {0})
$callargs.Remove('all') $callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart while ($true) {
$callargs['limit'] = $limit $callargs['offset'] = $offstart
$res=Get-SnipeitCompany @callargs $callargs['limit'] = $limit
$res $res=Get-SnipeitCompany @callargs
if ($res.count -lt $limit) { $res
break if ($res.count -lt $limit) {
} break
$offstart = $offstart + $limit }
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions end {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { # reset legacy sessions
Reset-SnipeitPSLegacyApi if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -78,58 +78,64 @@ function Get-SnipeitComponent() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$api = "/api/v1/components" $api = "/api/v1/components"
if ($search -and $id ) { if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
if ($id) { if ($id) {
$api= "/api/v1/components/$id" $api= "/api/v1/components/$id"
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitComponent @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitComponent @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -33,37 +33,40 @@ function Get-SnipeitCustomField() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
if ($id) { if ($id) {
$api= "/api/v1/fields/$id" $api= "/api/v1/fields/$id"
} else { } else {
$api = "/api/v1/fields" $api = "/api/v1/fields"
}
$Parameters = @{
Api = $api
Method = 'Get'
}
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
}
} }
$Parameters = @{ process {
Api = $api $result = Invoke-SnipeitMethod @Parameters
Method = 'Get' $result
}
if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { end {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyUrl -url $url if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
$result = Invoke-SnipeitMethod @Parameters
$result
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -66,60 +66,65 @@ function Get-SnipeitDepartment() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$api = "/api/v1/departments" $api = "/api/v1/departments"
if ($search -and $id ) { if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
if ($id) { if ($id) {
$api= "/api/v1/departments/$id" $api= "/api/v1/departments/$id"
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
} }
}
if ($all) { process {
$offstart = $(if ($offset) {$offset} Else {0}) if ($all) {
$callargs = $SearchParameter $offstart = $(if ($offset) {$offset} Else {0})
$callargs.Remove('all') $callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart while ($true) {
$callargs['limit'] = $limit $callargs['offset'] = $offstart
$res=Get-SnipeitDepartment @callargs $callargs['limit'] = $limit
$res $res=Get-SnipeitDepartment @callargs
if ($res.count -lt $limit) { $res
break if ($res.count -lt $limit) {
} break
$offstart = $offstart + $limit }
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions end {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { # reset legacy sessions
Reset-SnipeitPSLegacyApi if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -31,36 +31,39 @@ function Get-SnipeitFieldset() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
bagin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name if ($id) {
$api = "/api/v1/fieldsets/$id"
} else {
$api = "/api/v1/fieldsets"
}
if ($id) { $Parameters = @{
$api = "/api/v1/fieldsets/$id" Api = $api
} else { Method = 'Get'
$api = "/api/v1/fieldsets" }
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
}
} }
process {
$result = Invoke-SnipeitMethod @Parameters
$Parameters = @{ $result
Api = $api
Method = 'Get'
} }
end {
if ($PSBoundParameters.ContainsKey('apiKey')) { # reset legacy sessions
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey Reset-SnipeitPSLegacyApi
} }
if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
$result = Invoke-SnipeitMethod @Parameters
$result
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -104,57 +104,62 @@ function Get-SnipeitLicense() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
bagin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters switch($PsCmdlet.ParameterSetName) {
'Search' {$api = "/api/v1/licenses"}
switch($PsCmdlet.ParameterSetName) { 'Get with ID' {$api= "/api/v1/licenses/$id"}
'Search' {$api = "/api/v1/licenses"} 'Get licenses checked out to user ID' {$api= "/api/v1/users/$user_id/licenses"}
'Get with ID' {$api= "/api/v1/licenses/$id"} 'Get licenses checked out to asset ID' {$api= "/api/v1/hardware/$asset_id/licenses"}
'Get licenses checked out to user ID' {$api= "/api/v1/users/$user_id/licenses"} }
'Get licenses checked out to asset ID' {$api= "/api/v1/hardware/$asset_id/licenses"}
} $Parameters = @{
Api = $api
$Parameters = @{ Method = 'Get'
Api = $api GetParameters = $SearchParameter
Method = 'Get' }
GetParameters = $SearchParameter
} if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
if ($PSBoundParameters.ContainsKey('apiKey')) { Set-SnipeitPSLegacyApiKey -apiKey $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."
if ($PSBoundParameters.ContainsKey('url')) { Set-SnipeitPSLegacyUrl -url $url
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitLicense @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitLicense @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -53,57 +53,62 @@ function Get-SnipeitLicenseSeat() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $api = "/api/v1/licenses/$id/seats"
$api = "/api/v1/licenses/$id/seats"
if ($seat_id) { if ($seat_id) {
$api= "/api/v1/licenses/$id/seats/$seat_id" $api= "/api/v1/licenses/$id/seats/$seat_id"
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitLicenseSeat @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitLicenseSeat @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -59,60 +59,65 @@ function Get-SnipeitLocation() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $api = "/api/v1/locations"
$api = "/api/v1/locations" if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
if ($search -and $id ) { }
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} if ($id) {
$api= "/api/v1/locations/$id"
if ($id) { }
$api= "/api/v1/locations/$id"
} $Parameters = @{
Api = $api
$Parameters = @{ Method = 'Get'
Api = $api GetParameters = $SearchParameter
Method = 'Get' }
GetParameters = $SearchParameter
} if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
if ($PSBoundParameters.ContainsKey('apiKey')) { Set-SnipeitPSLegacyApiKey -apiKey $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."
if ($PSBoundParameters.ContainsKey('url')) { Set-SnipeitPSLegacyUrl -url $url
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitLocation @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitLocation @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -60,59 +60,64 @@ function Get-SnipeitManufacturer() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $api = "/api/v1/manufacturers"
$api = "/api/v1/manufacturers" if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
if ($search -and $id ) { }
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} if ($id) {
$api= "/api/v1/manufacturers/$id"
if ($id) { }
$api= "/api/v1/manufacturers/$id"
} $Parameters = @{
Api = $api
$Parameters = @{ Method = 'Get'
Api = $api GetParameters = $SearchParameter
Method = 'Get' }
GetParameters = $SearchParameter
} if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
if ($PSBoundParameters.ContainsKey('apiKey')) { Set-SnipeitPSLegacyApiKey -apiKey $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."
if ($PSBoundParameters.ContainsKey('url')) { Set-SnipeitPSLegacyUrl -url $url
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitManufacturer @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitManufacturer @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -60,58 +60,64 @@ function Get-SnipeitModel() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$api = "/api/v1/models" $api = "/api/v1/models"
if ($search -and $id ) { if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
if ($id) { if ($id) {
$api= "/api/v1/models/$id" $api= "/api/v1/models/$id"
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitModel @callargs
$res
if ($res.count -ne $limit ) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitModel @callargs
$res
if ($res.count -ne $limit ) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -59,59 +59,64 @@ function Get-SnipeitStatus() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $api = "/api/v1/statuslabels"
$api = "/api/v1/statuslabels" if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
if ($search -and $id ) { }
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} if ($id) {
$api= "/api/v1/statuslabels/$id"
if ($id) { }
$api= "/api/v1/statuslabels/$id"
} $Parameters = @{
Api = $api
$Parameters = @{ Method = 'Get'
Api = $api GetParameters = $SearchParameter
Method = 'Get' }
GetParameters = $SearchParameter
} if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
if ($PSBoundParameters.ContainsKey('apiKey')) { Set-SnipeitPSLegacyApiKey -apiKey $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."
if ($PSBoundParameters.ContainsKey('url')) { Set-SnipeitPSLegacyUrl -url $url
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitStatus @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitStatus @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -59,59 +59,64 @@ function Get-SnipeitSupplier() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$api = "/api/v1/suppliers" $api = "/api/v1/suppliers"
if ($search -and $id ) { if ($search -and $id ) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
} }
if ($id) { if ($id) {
$api= "/api/v1/suppliers/$id" $api= "/api/v1/suppliers/$id"
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
}
if ($all) {
$offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitSupplier @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions process {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { if ($all) {
Reset-SnipeitPSLegacyApi $offstart = $(if ($offset) {$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeitSupplier @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}
end {
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -97,53 +97,58 @@ function Get-SnipeitUser() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
switch ($PsCmdlet.ParameterSetName) { switch ($PsCmdlet.ParameterSetName) {
'Search' { $api = "/api/v1/users"} 'Search' { $api = "/api/v1/users"}
'Get with id' {$api= "/api/v1/users/$id"} 'Get with id' {$api= "/api/v1/users/$id"}
'Get users a specific accessory id has been checked out to' {$api= "/api/v1/accessories/$accessory_id/checkedout"} 'Get users a specific accessory id has been checked out to' {$api= "/api/v1/accessories/$accessory_id/checkedout"}
} }
$Parameters = @{ $Parameters = @{
Api = $api Api = $api
Method = 'Get' Method = 'Get'
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { if ($PSBoundParameters.ContainsKey('apiKey')) {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyApiKey -apiKey $apikey Set-SnipeitPSLegacyApiKey -apiKey $apikey
} }
if ($PSBoundParameters.ContainsKey('url')) { if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
} }
}
if ($all) { process {
$offstart = $(if ($offset) {$offset} Else {0}) if ($all) {
$callargs = $SearchParameter $offstart = $(if ($offset) {$offset} Else {0})
$callargs.Remove('all') $callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart while ($true) {
$callargs['limit'] = $limit $callargs['offset'] = $offstart
$res=Get-SnipeitUser @callargs $callargs['limit'] = $limit
$res $res=Get-SnipeitUser @callargs
if ($res.count -lt $limit) { $res
break if ($res.count -lt $limit) {
} break
$offstart = $offstart + $limit }
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
} }
# reset legacy sessions end {
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { # reset legacy sessions
Reset-SnipeitPSLegacyApi if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
}
} }
} }

View file

@ -115,40 +115,44 @@ function New-SnipeitAccessory() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($values['purchase_date']) { $Parameters = @{
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") Api = "/api/v1/accessories"
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
}
} }
$Parameters = @{ process {
Api = "/api/v1/accessories" if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Method = 'POST' $result = Invoke-SnipeitMethod @Parameters
Body = $Values }
$result
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { end {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyApiKey -apiKey $apikey if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -144,55 +144,61 @@ function New-SnipeitAsset() {
[hashtable] $customfields [hashtable] $customfields
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) { if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($customfields) {
$Values += $customfields
}
#Checkout asset when creating it
if ($PsCmdlet.ParameterSetName -eq 'Checkout asset when creating') {
switch ($checkout_to_type) {
'location' { $Values += @{ "assigned_location" = $assigned_id } }
'user' { $Values += @{ "assigned_user" = $assigned_id } }
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
} }
#This are not needed for API if ($customfields) {
if ($Values.ContainsKey('assigned_id')) {$Values.Remove('assigned_id')} $Values += $customfields
if ($Values.ContainsKey('checkout_to_type')) {$Values.Remove('checkout_to_type')} }
#Checkout asset when creating it
if ($PsCmdlet.ParameterSetName -eq 'Checkout asset when creating') {
switch ($checkout_to_type) {
'location' { $Values += @{ "assigned_location" = $assigned_id } }
'user' { $Values += @{ "assigned_user" = $assigned_id } }
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
}
#This are not needed for API
if ($Values.ContainsKey('assigned_id')) {$Values.Remove('assigned_id')}
if ($Values.ContainsKey('checkout_to_type')) {$Values.Remove('checkout_to_type')}
}
$Parameters = @{
Api = "/api/v1/hardware"
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
}
} }
$Parameters = @{ process {
Api = "/api/v1/hardware" if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Method = 'Post' $result = Invoke-SnipeitMethod @Parameters
Body = $Values }
$result
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { end {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyApiKey -apiKey $apikey if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -76,44 +76,49 @@ function New-SnipeitAssetMaintenance() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($Values['start_date']) {
$Values['start_date'] = $Values['start_date'].ToString("yyyy-MM-dd")
}
if ($Values['start_date']) { if ($Values['completion_date']) {
$Values['start_date'] = $Values['start_date'].ToString("yyyy-MM-dd") $Values['completion_date'] = $Values['completion_date'].ToString("yyyy-MM-dd")
}
$Parameters = @{
Api = "/api/v1/maintenances"
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 ($Values['completion_date']) { process {
$Values['completion_date'] = $Values['completion_date'].ToString("yyyy-MM-dd") if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
} }
end {
$Parameters = @{ # reset legacy sessions
Api = "/api/v1/maintenances" if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Method = 'Post' Reset-SnipeitPSLegacyApi
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -35,41 +35,46 @@ function New-SnipeitAudit() {
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = @{
"location_id" = $location_id
}
$Values = @{ if ($PSBoundParameters.ContainsKey('tag')) {
"location_id" = $location_id $Values += @{"asset_tag" = $tag}
}
$Parameters = @{
Api = "/api/v1/hardware/audit"
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 ($PSBoundParameters.ContainsKey('tag')) { process {
$Values += @{"asset_tag" = $tag} if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
} }
$Parameters = @{ end {
Api = "/api/v1/hardware/audit" # reset legacy sessions
Method = 'Post' if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Body = $Values Reset-SnipeitPSLegacyApi
} }
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -41,36 +41,41 @@ function New-SnipeitCompany() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Parameters = @{
Api = "/api/v1/companies"
Method = 'POST'
Body = $Values
}
$Parameters = @{ if ($PSBoundParameters.ContainsKey('apiKey')) {
Api = "/api/v1/companies" Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Method = 'POST' Set-SnipeitPSLegacyApiKey -apiKey $apikey
Body = $Values }
if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { process {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey $result = Invoke-SnipeitMethod @Parameters
}
$result
} }
if ($PSBoundParameters.ContainsKey('url')) { end {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyUrl -url $url if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -76,40 +76,45 @@ function New-SnipeitComponent() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($Values['purchase_date']) {
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($Values['purchase_date']) { $Parameters = @{
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") Api = "/api/v1/components"
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
}
} }
$Parameters = @{ process {
Api = "/api/v1/components" if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Method = 'POST' $result = Invoke-SnipeitMethod @Parameters
Body = $Values }
$result
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { end {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyApiKey -apiKey $apikey if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -122,9 +122,7 @@ function New-SnipeitConsumable() {
if ($Values['purchase_date']) { if ($Values['purchase_date']) {
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
} }
}
process {
$Parameters = @{ $Parameters = @{
Api = "/api/v1/consumables" Api = "/api/v1/consumables"
Method = 'Post' Method = 'Post'
@ -140,7 +138,9 @@ function New-SnipeitConsumable() {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url Set-SnipeitPSLegacyUrl -url $url
} }
}
process {
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters $result = Invoke-SnipeitMethod @Parameters
} }

View file

@ -60,36 +60,41 @@ function New-SnipeitDepartment() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Parameters = @{
Api = "/api/v1/departments"
Method = 'POST'
Body = $Values
}
$Parameters = @{ if ($PSBoundParameters.ContainsKey('apiKey')) {
Api = "/api/v1/departments" Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Method = 'POST' Set-SnipeitPSLegacyApiKey -apiKey $apikey
Body = $Values }
if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { process {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey $result = Invoke-SnipeitMethod @Parameters
}
$result
} }
if ($PSBoundParameters.ContainsKey('url')) { end {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyUrl -url $url if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -123,48 +123,52 @@ function New-SnipeitLicense() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($Values['expiration_date']) {
$Values['expiration_date'] = $Values['expiration_date'].ToString("yyyy-MM-dd")
}
if ($Values['expiration_date']) { if ($Values['purchase_date']) {
$Values['expiration_date'] = $Values['expiration_date'].ToString("yyyy-MM-dd") $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($Values['termination_date']) {
$Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd")
}
$Parameters = @{
Api = "/api/v1/licenses"
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 ($Values['purchase_date']) { process {
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
} }
end {
if ($Values['termination_date']) { # reset legacy sessions
$Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd") if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
$Parameters = @{
Api = "/api/v1/licenses"
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -93,34 +93,40 @@ function New-SnipeitLocation() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{ $Parameters = @{
Api = "/api/v1/locations" Api = "/api/v1/locations"
Method = 'post' Method = 'post'
Body = $Values 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 ($PSBoundParameters.ContainsKey('apiKey')) { process {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey $result = Invoke-SnipeitMethod @Parameters
}
$result
} }
if ($PSBoundParameters.ContainsKey('url')) { end {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyUrl -url $url if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -46,36 +46,40 @@ function New-SnipeitManufacturer() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = @{ $Values = @{
"name" = $Name "name" = $Name
}
$Parameters = @{
Api = "/api/v1/manufacturers"
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
}
} }
process {
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$Parameters = @{ $result
Api = "/api/v1/manufacturers"
Method = 'post'
Body = $Values
} }
end {
if ($PSBoundParameters.ContainsKey('apiKey')) { # reset legacy sessions
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey Reset-SnipeitPSLegacyApi
} }
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -66,43 +66,49 @@ function New-SnipeitModel() {
[string]$apiKey [string]$apiKey
) )
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = @{ $Values = @{
name = $name name = $name
category_id = $category_id category_id = $category_id
manufacturer_id = $manufacturer_id manufacturer_id = $manufacturer_id
fieldset_id = $fieldset_id fieldset_id = $fieldset_id
}
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
$Parameters = @{
Api = "/api/v1/models"
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 ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) } process {
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) } if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
$Parameters = @{
Api = "/api/v1/models"
Method = 'post'
Body = $Values
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { end {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyApiKey -apiKey $apikey if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -96,36 +96,41 @@ function New-SnipeitSupplier() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Parameters = @{
Api = "/api/v1/suppilers"
Method = 'POST'
Body = $Values
}
$Parameters = @{ if ($PSBoundParameters.ContainsKey('apiKey')) {
Api = "/api/v1/suppilers" Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
Method = 'POST' Set-SnipeitPSLegacyApiKey -apiKey $apikey
Body = $Values }
if ($PSBoundParameters.ContainsKey('url')) {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
Set-SnipeitPSLegacyUrl -url $url
}
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { process {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey $result = Invoke-SnipeitMethod @Parameters
}
$result
} }
if ($PSBoundParameters.ContainsKey('url')) { end {
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyUrl -url $url if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }

View file

@ -116,39 +116,44 @@ function New-SnipeitUser() {
[parameter(mandatory = $false)] [parameter(mandatory = $false)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($password ) {
$Values['password_confirmation'] = $password
}
if ($password ) { $Parameters = @{
$Values['password_confirmation'] = $password Api = "/api/v1/users"
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
}
} }
$Parameters = @{ process {
Api = "/api/v1/users" if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
Method = 'post' $result = Invoke-SnipeitMethod @Parameters
Body = $Values }
$result
} }
if ($PSBoundParameters.ContainsKey('apiKey')) { end {
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." # reset legacy sessions
Set-SnipeitPSLegacyApiKey -apiKey $apikey if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
} Reset-SnipeitPSLegacyApi
}
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
# reset legacy sessions
if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) {
Reset-SnipeitPSLegacyApi
} }
} }