Update all Get commands with all avaliable search options, Added CheckIn Asset

This commit is contained in:
Stephen Maunder 2018-04-28 19:45:38 +01:00
parent 55bd578ef7
commit 522704e403
16 changed files with 453 additions and 75 deletions

9
.vscode/tasks.json vendored
View file

@ -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"
}
]
}
}

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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,

View file

@ -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
}

View file

@ -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
}