Add more methods as well, detected unauth requests and changed impact levels

This commit is contained in:
Stephen Maunder 2018-01-22 08:32:04 +00:00
parent 14fc468937
commit eb60cf8824
13 changed files with 168 additions and 7 deletions

View file

@ -106,6 +106,9 @@
$result
}
}
elseif ($webResponse.StatusCode -eq "Unauthorized") {
Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your token is correct"
}
else {
# No content, although statusCode < 400
# This could be wanted behavior of the API

View file

@ -29,6 +29,9 @@ function Get-Asset()
$Parameters = @{
Uri = "$url/api/v1/hardware"
Method = 'Get'
GetParameters = @{
limit = 9999
}
Token = $apiKey
}

View file

@ -0,0 +1,39 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Departments
.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-Department -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Department -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Department1" }
#>
function Get-Department()
{
Param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$Parameters = @{
Uri = "$url/api/v1/departments"
Method = 'Get'
Token = $apiKey
}
$result = Invoke-SnipeitMethod @Parameters
$result
}

View file

@ -0,0 +1,39 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Locations
.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-Location -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Location -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Location1" }
#>
function Get-Location()
{
Param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$Parameters = @{
Uri = "$url/api/v1/locations"
Method = 'Get'
Token = $apiKey
}
$result = Invoke-SnipeitMethod @Parameters
$result
}

View file

@ -37,7 +37,7 @@ function New-Asset()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Low"
)]
Param(

View file

@ -31,7 +31,7 @@ function New-Component()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Low"
)]
Param(

View file

@ -0,0 +1,77 @@
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER name
Parameter description
.PARAMETER category_id
Parameter description
.PARAMETER qty
Parameter description
.PARAMETER url
Parameter description
.PARAMETER apiKey
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
function New-Department()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[string]$company_id,
[string]$location_id,
[string]$manager_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
"name" = $name
"company_id" = $company_id
"location_id" = $location_id
"manager_id" = $manager_id
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/departments"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -22,7 +22,7 @@ function New-Manufacturer()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Low"
)]
Param(

View file

@ -31,7 +31,7 @@ function New-Model()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Low"
)]
Param(

View file

@ -37,7 +37,7 @@ function Set-Asset()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Medium"
)]
Param(

View file

@ -2,7 +2,7 @@ function Set-AssetOwner()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Medium"
)]
Param(

View file

@ -2,7 +2,7 @@ function Set-Component()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
ConfirmImpact = "Medium"
)]
Param(

Binary file not shown.