mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
Merge pull request #150 from PetriAsi/feature/get-snipeitasset-audits
Feature/get snipeitasset audits
This commit is contained in:
commit
18192e9eb0
1 changed files with 36 additions and 27 deletions
|
|
@ -14,6 +14,12 @@ Exact asset tag to query
|
||||||
.PARAMETER asset_serial
|
.PARAMETER asset_serial
|
||||||
Exact asset serialnumber to query
|
Exact asset serialnumber to query
|
||||||
|
|
||||||
|
.PARAMETER audit_due
|
||||||
|
Retrieve a list of assets that are due for auditing soon.
|
||||||
|
|
||||||
|
.PARAMETER audit_overdue
|
||||||
|
Retrieve a list of assets that are overdue for auditing.
|
||||||
|
|
||||||
.PARAMETER order_number
|
.PARAMETER order_number
|
||||||
Optionally restrict asset results to this order number
|
Optionally restrict asset results to this order number
|
||||||
|
|
||||||
|
|
@ -73,6 +79,7 @@ Get-SnipeitAsset -asset_tag "myAssetTag"-url "https://assets.example.com"-token
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function Get-SnipeitAsset() {
|
function Get-SnipeitAsset() {
|
||||||
|
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||||
Param(
|
Param(
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
[string]$search,
|
[string]$search,
|
||||||
|
|
@ -87,6 +94,12 @@ function Get-SnipeitAsset() {
|
||||||
[Alias('asset_serial')]
|
[Alias('asset_serial')]
|
||||||
[string]$serial,
|
[string]$serial,
|
||||||
|
|
||||||
|
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||||
|
[switch]$audit_due,
|
||||||
|
|
||||||
|
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||||
|
[switch]$audit_overdue,
|
||||||
|
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
[string]$order_number,
|
[string]$order_number,
|
||||||
|
|
||||||
|
|
@ -118,57 +131,52 @@ function Get-SnipeitAsset() {
|
||||||
[int]$status_id,
|
[int]$status_id,
|
||||||
|
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
[string]$sort = "created_at",
|
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||||
|
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||||
|
[ValidateSet('id','created_at','asset_tag','serial','order_number','model_id','category_id','manufacturer_id','company_id','location_id','status','status_id')]
|
||||||
|
[string]$sort,
|
||||||
|
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
|
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||||
|
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||||
[ValidateSet("asc", "desc")]
|
[ValidateSet("asc", "desc")]
|
||||||
[string]$order = "desc",
|
[string]$order,
|
||||||
|
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
|
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||||
|
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||||
[int]$limit = 50,
|
[int]$limit = 50,
|
||||||
|
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
|
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||||
|
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||||
[int]$offset,
|
[int]$offset,
|
||||||
|
|
||||||
[parameter(ParameterSetName='Search')]
|
[parameter(ParameterSetName='Search')]
|
||||||
|
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||||
|
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||||
[switch]$all = $false,
|
[switch]$all = $false,
|
||||||
|
|
||||||
[parameter(mandatory = $true)]
|
[parameter(mandatory = $true)]
|
||||||
[string]$url,
|
[string]$url,
|
||||||
|
|
||||||
[parameter(mandatory = $true)]
|
[parameter(mandatory = $true)]
|
||||||
[string]$apiKey
|
[string]$apiKey
|
||||||
)
|
)
|
||||||
|
|
||||||
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) {
|
||||||
$apiurl = "$url/api/v1/hardware"
|
'Search' { $apiurl = "$url/api/v1/hardware" }
|
||||||
|
'Get with id' {$apiurl= "$url/api/v1/hardware/$id"}
|
||||||
if ($search -and ($asset_tag -or $asset_serial -or $id)) {
|
'Get with asset tag' {$apiurl= "$url/api/v1/hardware/bytag/$asset_tag"}
|
||||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
|
'Get with serial' { $apiurl= "$url/api/v1/hardware/byserial/$asset_serial"}
|
||||||
|
'Assets due auditing soon' {$apiurl = "$url/api/v1/hardware/audit/due"}
|
||||||
|
'Assets overdue for auditing' {$apiurl = "$url/api/v1/hardware/audit/overdue"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($id) {
|
|
||||||
if ( $search -or $asset_serial -or $asset_tag) {
|
|
||||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
|
|
||||||
}
|
|
||||||
$apiurl= "$url/api/v1/hardware/$id"
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($asset_tag) {
|
|
||||||
if ( $search -or $asset_serial -or $id) {
|
|
||||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
|
|
||||||
}
|
|
||||||
$apiurl= "$url/api/v1/hardware/bytag/$asset_tag"
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($asset_serial) {
|
|
||||||
if ( $search -or $asset_tag) {
|
|
||||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of-search , -asset_tag or -asset_serial parameter"
|
|
||||||
}
|
|
||||||
$apiurl= "$url/api/v1/hardware/byserial/$asset_serial"
|
|
||||||
}
|
|
||||||
|
|
||||||
$Parameters = @{
|
$Parameters = @{
|
||||||
Uri = $apiurl
|
Uri = $apiurl
|
||||||
|
|
@ -180,6 +188,7 @@ function Get-SnipeitAsset() {
|
||||||
if ($all) {
|
if ($all) {
|
||||||
$offstart = $(if ($offset){$offset} Else {0})
|
$offstart = $(if ($offset){$offset} Else {0})
|
||||||
$callargs = $SearchParameter
|
$callargs = $SearchParameter
|
||||||
|
Write-Verbose "Callargs: $($callargs | convertto-json)"
|
||||||
$callargs.Remove('all')
|
$callargs.Remove('all')
|
||||||
|
|
||||||
while ($true) {
|
while ($true) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue