mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
Add more methods as well, detected unauth requests and changed impact levels
This commit is contained in:
parent
14fc468937
commit
eb60cf8824
13 changed files with 168 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ function Get-Asset()
|
|||
$Parameters = @{
|
||||
Uri = "$url/api/v1/hardware"
|
||||
Method = 'Get'
|
||||
GetParameters = @{
|
||||
limit = 9999
|
||||
}
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
|
|
|
|||
39
SnipeitPS/Public/Get-Department.ps1
Normal file
39
SnipeitPS/Public/Get-Department.ps1
Normal 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
|
||||
}
|
||||
|
||||
39
SnipeitPS/Public/Get-Location.ps1
Normal file
39
SnipeitPS/Public/Get-Location.ps1
Normal 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
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ function New-Asset()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function New-Component()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
77
SnipeitPS/Public/New-Department.ps1
Normal file
77
SnipeitPS/Public/New-Department.ps1
Normal 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
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ function New-Manufacturer()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function New-Model()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ function Set-Asset()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ function Set-AssetOwner()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ function Set-Component()
|
|||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "High"
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue