From 522704e403d8648287355d6d371812dda8734c36 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 28 Apr 2018 19:45:38 +0100 Subject: [PATCH] Update all Get commands with all avaliable search options, Added CheckIn Asset --- .vscode/tasks.json | 9 ++- SnipeitPS/Public/Get-Asset.ps1 | 55 ++++++++++++++--- SnipeitPS/Public/Get-Category.ps1 | 25 ++++++-- SnipeitPS/Public/Get-Company.ps1 | 21 +++++-- SnipeitPS/Public/Get-Component.ps1 | 34 ++++++++--- SnipeitPS/Public/Get-Department.ps1 | 25 ++++++-- SnipeitPS/Public/Get-License.ps1 | 87 +++++++++++++++++++++++++++ SnipeitPS/Public/Get-Location.ps1 | 25 ++++++-- SnipeitPS/Public/Get-Manufacturer.ps1 | 25 ++++++-- SnipeitPS/Public/Get-Model.ps1 | 21 +++++-- SnipeitPS/Public/Get-Status.ps1 | 25 ++++++-- SnipeitPS/Public/Get-Supplier.ps1 | 25 ++++++-- SnipeitPS/Public/Get-User.ps1 | 40 +++++++++--- SnipeitPS/Public/New-Asset.ps1 | 4 +- SnipeitPS/Public/New-Company.ps1 | 62 +++++++++++++++++++ SnipeitPS/Public/Reset-AssetOwner.ps1 | 45 ++++++++++++++ 16 files changed, 453 insertions(+), 75 deletions(-) create mode 100644 SnipeitPS/Public/Get-License.ps1 create mode 100644 SnipeitPS/Public/New-Company.ps1 create mode 100644 SnipeitPS/Public/Reset-AssetOwner.ps1 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 602228b..1158310 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -35,15 +35,14 @@ "showOutput": "always", // Associate with test task runner "tasks": [{ - "taskName": "Build Help", - "suppressTaskName": true, + "label": "Build Help", "args": [ - "Write-Host 'Invoking platyPS'; New-ExternalHelp -Path .\\docs\\en-US -OutputPath .\\ConfluencePS\\en-US -Force;", + "Write-Host 'Invoking platyPS'; New-ExternalHelp -Path .\\docs\\en-US -OutputPath .\\SnipeitPS\\en-US -Force;", "Invoke-Command { Write-Host 'Completed Build task in task runner.' }" ] }, { - "taskName": "Test", + "label": "Test", "suppressTaskName": true, "isTestCommand": true, "args": [ @@ -53,4 +52,4 @@ "problemMatcher": "$pester" } ] -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 7531ce4..51ddb64 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -16,25 +16,64 @@ Get-Asset -url "https://assets.example.com" -token "token..." | Where-Object {$_ #> -function Get-Asset() -{ +function Get-Asset() { Param( [string]$search, - [parameter(mandatory=$true)] + [int]$order_number, + + [int]$model_id, + + [int]$category_id, + + [int]$manufacturer_id, + + [int]$company_id, + + [int]$location_id, + + [string]$status, + + [int]$status_id, + + [string]$sort = "created_at", + + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) } + if ($PSBoundParameters.ContainsKey('model_id')) { $SearchParameter.Add("model_id", $model_id) } + if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) } + if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) } + if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } + if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) } + if ($PSBoundParameters.ContainsKey('status_id')) { $SearchParameter.Add("status_id", $order_number) } + if ($PSBoundParameters.ContainsKey('status')) { $SearchParameter.Add("status", $order_number) } + if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) } + $Parameters = @{ Uri = "$url/api/v1/hardware" Method = 'Get' - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter Token = $apiKey } diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index 86dd34c..391b9a9 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -21,21 +21,34 @@ function Get-Category() Param( [string]$search, - [parameter(mandatory=$true)] + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/categories" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index c42360a..46860c2 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -21,6 +21,13 @@ function Get-Company() Param( [string]$search, + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + [parameter(mandatory=$true)] [string]$url, @@ -28,14 +35,20 @@ function Get-Company() [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/companies" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index 8d130d4..39c14e9 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -16,26 +16,44 @@ Get-Component -url "https://assets.example.com" -token "token..." | Where-Object #> -function Get-Component() -{ +function Get-Component() { Param( [string]$search, - [parameter(mandatory=$true)] + [int]$category_id, + + [int]$company_id, + + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) } + if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } + $Parameters = @{ Uri = "$url/api/v1/components" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index 2c2fe4c..eeec2a2 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -21,21 +21,34 @@ function Get-Department() Param( [string]$search, - [parameter(mandatory=$true)] + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/departments" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 new file mode 100644 index 0000000..2adb5a4 --- /dev/null +++ b/SnipeitPS/Public/Get-License.ps1 @@ -0,0 +1,87 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Licenses + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-License -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-License -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "License" } + +#> + +function Get-License() { + Param( + [string]$search, + + [string]$name, + + [int] $company_id, + + [string]$product_key, + + [int]$order_number, + + [string]$purchase_order, + + [string]$license_name, + + [string]$license_email, + + [int]$manufacturer_id, + + [int]$supplier_id, + + [int]$depreciation_id, + + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + if ($PSBoundParameters.ContainsKey('name')) { $SearchParameter.Add("name", $name) } + if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } + if ($PSBoundParameters.ContainsKey('product_key')) { $SearchParameter.Add("product_key", $product_key) } + if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) } + if ($PSBoundParameters.ContainsKey('purchase_order')) { $SearchParameter.Add("purchase_order", $purchase_order) } + if ($PSBoundParameters.ContainsKey('license_name')) { $SearchParameter.Add("license_name", $license_name) } + if ($PSBoundParameters.ContainsKey('license_email')) { $SearchParameter.Add("license_email", $license_email) } + if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) } + if ($PSBoundParameters.ContainsKey('supplier_id')) { $SearchParameter.Add("supplier_id", $supplier_id) } + if ($PSBoundParameters.ContainsKey('depreciation_id')) { $SearchParameter.Add("depreciation_id", $depreciation_id) } + + $Parameters = @{ + Uri = "$url/api/v1/licenses" + Method = 'Get' + Token = $apiKey + GetParameters = $SearchParameter + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} + diff --git a/SnipeitPS/Public/Get-Location.ps1 b/SnipeitPS/Public/Get-Location.ps1 index 0f65214..f4090e8 100644 --- a/SnipeitPS/Public/Get-Location.ps1 +++ b/SnipeitPS/Public/Get-Location.ps1 @@ -21,21 +21,34 @@ function Get-Location() Param( [string]$search, - [parameter(mandatory=$true)] + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/locations" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index 2f28468..cf07026 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -21,21 +21,34 @@ function Get-Manufacturer() Param( [string]$search, - [parameter(mandatory=$true)] + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/manufacturers" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index f729c84..8b2b581 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -21,6 +21,13 @@ function Get-Model() Param( [string]$search, + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + [parameter(mandatory = $true)] [string]$url, @@ -28,14 +35,20 @@ function Get-Model() [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/models" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index 73d1f89..4b3eea5 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -21,21 +21,34 @@ function Get-Status() Param( [string]$search, - [parameter(mandatory=$true)] + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/statuslabels" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index d330471..91a5dd2 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -21,21 +21,34 @@ function Get-Supplier() Param( [string]$search, - [parameter(mandatory=$true)] + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $Parameters = @{ Uri = "$url/api/v1/suppliers" Method = 'Get' Token = $apiKey - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index 2f23d50..3cd71d1 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -15,25 +15,49 @@ Get-User -url "https://assets.example.com" -token "token..." Get-User -url "https://assets.example.com" -token "token..." | Where-Object {$_.username -eq "stephenm" } #> -function Get-User() -{ +function Get-User() { Param( [string]$search, - [parameter(mandatory=$true)] + [int]$company_id, + + [int]$location_id, + + [int]$group_id, + + [int]$department_id, + + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory = $true)] [string]$apiKey ) + $SearchParameter = @{ + sort = $sort + order = $order + limit = $limit + offset = $offset + } + + if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } + if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) } + if ($PSBoundParameters.ContainsKey('group_id')) { $SearchParameter.Add("group_id", $group_id) } + if ($PSBoundParameters.ContainsKey('department_id')) { $SearchParameter.Add("department_id", $department_id) } + $Parameters = @{ Uri = "$url/api/v1/users" Method = 'Get' - GetParameters = @{ - search = $search - limit = 999 - } + GetParameters = $SearchParameter Token = $apiKey } diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index 7d1678b..1362770 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -47,10 +47,10 @@ function New-Asset() [string]$Name, [parameter(mandatory = $true)] - [string]$Status_id, + [int]$Status_id, [parameter(mandatory = $true)] - [string]$Model_id, + [int]$Model_id, [parameter(mandatory = $true)] [string]$url, diff --git a/SnipeitPS/Public/New-Company.ps1 b/SnipeitPS/Public/New-Company.ps1 new file mode 100644 index 0000000..aa3d2e5 --- /dev/null +++ b/SnipeitPS/Public/New-Company.ps1 @@ -0,0 +1,62 @@ +<# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .PARAMETER name + Parameter description + + .PARAMETER url + Parameter description + + .PARAMETER apiKey + Parameter description + + .EXAMPLE + An example + + .NOTES + General notes +#> + +function New-Company() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "name" = $name + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/companies" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/Reset-AssetOwner.ps1 b/SnipeitPS/Public/Reset-AssetOwner.ps1 new file mode 100644 index 0000000..20090c9 --- /dev/null +++ b/SnipeitPS/Public/Reset-AssetOwner.ps1 @@ -0,0 +1,45 @@ +function Reset-AssetOwner() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Medium" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [int]$status_id, + + [int]$location_id, + + [string]$notes, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "notes" = $notes + } + + if ($PSBoundParameters.ContainsKey('location_id')) { $Values.Add("location_id", $location_id) } + if ($PSBoundParameters.ContainsKey('status_id')) { $Values.Add("status_id", $status_id) } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id/checkin" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + return $result +}