From eb60cf8824a8fe3331b8532a6354c2e50cdeb1d1 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Mon, 22 Jan 2018 08:32:04 +0000 Subject: [PATCH] Add more methods as well, detected unauth requests and changed impact levels --- SnipeitPS/Private/Invoke-SnipeitMethod.ps1 | 3 + SnipeitPS/Public/Get-Asset.ps1 | 3 + SnipeitPS/Public/Get-Department.ps1 | 39 +++++++++++ SnipeitPS/Public/Get-Location.ps1 | 39 +++++++++++ SnipeitPS/Public/New-Asset.ps1 | 2 +- SnipeitPS/Public/New-Component.ps1 | 2 +- SnipeitPS/Public/New-Department.ps1 | 77 +++++++++++++++++++++ SnipeitPS/Public/New-Manufacturer.ps1 | 2 +- SnipeitPS/Public/New-Model.ps1 | 2 +- SnipeitPS/Public/Set-Asset.ps1 | 2 +- SnipeitPS/Public/Set-AssetOwner.ps1 | 2 +- SnipeitPS/Public/Set-Components.ps1 | 2 +- SnipeitPS/SnipeItPS.psd1 | Bin 8524 -> 8658 bytes 13 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 SnipeitPS/Public/Get-Department.ps1 create mode 100644 SnipeitPS/Public/Get-Location.ps1 create mode 100644 SnipeitPS/Public/New-Department.ps1 diff --git a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index f340fa6..8400267 100644 --- a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -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 diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 4eb0e2d..2cf5ed6 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -29,6 +29,9 @@ function Get-Asset() $Parameters = @{ Uri = "$url/api/v1/hardware" Method = 'Get' + GetParameters = @{ + limit = 9999 + } Token = $apiKey } diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 new file mode 100644 index 0000000..d28cadf --- /dev/null +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -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 +} + diff --git a/SnipeitPS/Public/Get-Location.ps1 b/SnipeitPS/Public/Get-Location.ps1 new file mode 100644 index 0000000..53218a4 --- /dev/null +++ b/SnipeitPS/Public/Get-Location.ps1 @@ -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 +} + diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index e6a8876..7d1678b 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -37,7 +37,7 @@ function New-Asset() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/New-Component.ps1 b/SnipeitPS/Public/New-Component.ps1 index 7105811..690b1c8 100644 --- a/SnipeitPS/Public/New-Component.ps1 +++ b/SnipeitPS/Public/New-Component.ps1 @@ -31,7 +31,7 @@ function New-Component() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/New-Department.ps1 b/SnipeitPS/Public/New-Department.ps1 new file mode 100644 index 0000000..0fe2536 --- /dev/null +++ b/SnipeitPS/Public/New-Department.ps1 @@ -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 +} + diff --git a/SnipeitPS/Public/New-Manufacturer.ps1 b/SnipeitPS/Public/New-Manufacturer.ps1 index b198a60..d85ee18 100644 --- a/SnipeitPS/Public/New-Manufacturer.ps1 +++ b/SnipeitPS/Public/New-Manufacturer.ps1 @@ -22,7 +22,7 @@ function New-Manufacturer() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/New-Model.ps1 b/SnipeitPS/Public/New-Model.ps1 index c7a5067..af21b76 100644 --- a/SnipeitPS/Public/New-Model.ps1 +++ b/SnipeitPS/Public/New-Model.ps1 @@ -31,7 +31,7 @@ function New-Model() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/Set-Asset.ps1 b/SnipeitPS/Public/Set-Asset.ps1 index a53391a..a7decfb 100644 --- a/SnipeitPS/Public/Set-Asset.ps1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -37,7 +37,7 @@ function Set-Asset() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Medium" )] Param( diff --git a/SnipeitPS/Public/Set-AssetOwner.ps1 b/SnipeitPS/Public/Set-AssetOwner.ps1 index 44d792e..3ecbc1c 100644 --- a/SnipeitPS/Public/Set-AssetOwner.ps1 +++ b/SnipeitPS/Public/Set-AssetOwner.ps1 @@ -2,7 +2,7 @@ function Set-AssetOwner() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Medium" )] Param( diff --git a/SnipeitPS/Public/Set-Components.ps1 b/SnipeitPS/Public/Set-Components.ps1 index 84dd6b8..92f44f8 100644 --- a/SnipeitPS/Public/Set-Components.ps1 +++ b/SnipeitPS/Public/Set-Components.ps1 @@ -2,7 +2,7 @@ function Set-Component() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Medium" )] Param( diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 3b16a4eb52d4db127170a5560f145a1963689ac3..2a45466aa6629aba3cc601ea56b7bbc38365044b 100644 GIT binary patch delta 76 zcmX@(bjf+cGm*(Zgd})f7*ZJu7!nzZ7)ls&Cl?A!PL31iz#^I_#KG^wkk60|R9nK3 N31sDMek_v70|0QU6(s-w delta 12 TcmccQe8y?RGm*_XqG>z;DVGIw