Merge pull request #152 from snazy2000/develop

Specify default parameter sets and list audits
This commit is contained in:
Petri Asikainen 2021-06-10 00:04:00 +03:00 committed by GitHub
commit 19fb68fc6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 142 additions and 84 deletions

View file

@ -35,6 +35,7 @@ Get-SnipeitAccessory -id 1
#>
function Get-SnipeitAccessory() {
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -14,6 +14,12 @@ Exact asset tag to query
.PARAMETER asset_serial
Exact asset serialnumber to query
.PARAMETER audit_due
Retrieve a list of assets that are due for auditing soon.
.PARAMETER audit_overdue
Retrieve a list of assets that are overdue for auditing.
.PARAMETER order_number
Optionally restrict asset results to this order number
@ -73,6 +79,7 @@ Get-SnipeitAsset -asset_tag "myAssetTag"-url "https://assets.example.com"-token
#>
function Get-SnipeitAsset() {
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,
@ -87,6 +94,12 @@ function Get-SnipeitAsset() {
[Alias('asset_serial')]
[string]$serial,
[parameter(ParameterSetName='Assets due auditing soon')]
[switch]$audit_due,
[parameter(ParameterSetName='Assets overdue for auditing')]
[switch]$audit_overdue,
[parameter(ParameterSetName='Search')]
[string]$order_number,
@ -118,57 +131,52 @@ function Get-SnipeitAsset() {
[int]$status_id,
[parameter(ParameterSetName='Search')]
[string]$sort = "created_at",
[parameter(ParameterSetName='Assets due auditing soon')]
[parameter(ParameterSetName='Assets overdue for auditing')]
[ValidateSet('id','created_at','asset_tag','serial','order_number','model_id','category_id','manufacturer_id','company_id','location_id','status','status_id')]
[string]$sort,
[parameter(ParameterSetName='Search')]
[parameter(ParameterSetName='Assets due auditing soon')]
[parameter(ParameterSetName='Assets overdue for auditing')]
[ValidateSet("asc", "desc")]
[string]$order = "desc",
[string]$order,
[parameter(ParameterSetName='Search')]
[parameter(ParameterSetName='Assets due auditing soon')]
[parameter(ParameterSetName='Assets overdue for auditing')]
[int]$limit = 50,
[parameter(ParameterSetName='Search')]
[parameter(ParameterSetName='Assets due auditing soon')]
[parameter(ParameterSetName='Assets overdue for auditing')]
[int]$offset,
[parameter(ParameterSetName='Search')]
[parameter(ParameterSetName='Assets due auditing soon')]
[parameter(ParameterSetName='Assets overdue for auditing')]
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/hardware"
if ($search -and ($asset_tag -or $asset_serial -or $id)) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
switch ($PsCmdlet.ParameterSetName) {
'Search' { $apiurl = "$url/api/v1/hardware" }
'Get with id' {$apiurl= "$url/api/v1/hardware/$id"}
'Get with asset tag' {$apiurl= "$url/api/v1/hardware/bytag/$asset_tag"}
'Get with serial' { $apiurl= "$url/api/v1/hardware/byserial/$asset_serial"}
'Assets due auditing soon' {$apiurl = "$url/api/v1/hardware/audit/due"}
'Assets overdue for auditing' {$apiurl = "$url/api/v1/hardware/audit/overdue"}
}
if ($id) {
if ( $search -or $asset_serial -or $asset_tag) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
}
$apiurl= "$url/api/v1/hardware/$id"
}
if ($asset_tag) {
if ( $search -or $asset_serial -or $id) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
}
$apiurl= "$url/api/v1/hardware/bytag/$asset_tag"
}
if ($asset_serial) {
if ( $search -or $asset_tag) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of-search , -asset_tag or -asset_serial parameter"
}
$apiurl= "$url/api/v1/hardware/byserial/$asset_serial"
}
$Parameters = @{
Uri = $apiurl
@ -180,6 +188,7 @@ function Get-SnipeitAsset() {
if ($all) {
$offstart = $(if ($offset){$offset} Else {0})
$callargs = $SearchParameter
Write-Verbose "Callargs: $($callargs | convertto-json)"
$callargs.Remove('all')
while ($true) {

View file

@ -33,6 +33,7 @@ Get-SnipeitCategory -search "Laptop"
function Get-SnipeitCategory()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -34,6 +34,7 @@ Gets specific company
function Get-SnipeitCompany()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -36,8 +36,8 @@ Get-SnipeitComponent -id
Returns specific component
#>
function Get-SnipeitComponent() {
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -36,6 +36,7 @@ Get-SnipeitDepartment -id 1
function Get-SnipeitDepartment()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -33,6 +33,7 @@ Get-SnipeitLicense -id 1
#>
function Get-SnipeitLicense() {
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -33,6 +33,7 @@ Get-SnipeitLocation -id 3
function Get-SnipeitLocation()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -1,40 +1,40 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Manufacturers
.SYNOPSIS
# Gets a list of Snipe-it Manufacturers
.PARAMETER search
A text string to search the Manufactures data
.PARAMETER search
A text string to search the Manufactures data
.PARAMETER id
A id of specific Manufactuter
.PARAMETER id
A id of specific Manufactuter
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
Get-SnipeitManufacturer -search HP
Search all manufacturers for string HP
.EXAMPLE
Get-SnipeitManufacturer -search HP
Search all manufacturers for string HP
.EXAMPLE
Get-SnipeitManufacturer -id 3
Returns manufacturer with id 3
.EXAMPLE
Get-SnipeitManufacturer -id 3
Returns manufacturer with id 3
#>
function Get-SnipeitManufacturer()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -33,6 +33,7 @@ Get-SnipeitModel -id 1
function Get-SnipeitModel()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -33,6 +33,7 @@ Get-SnipeitStatus -id 3
function Get-SnipeitStatus()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -30,9 +30,9 @@ Get-SnipeitSupplier -search MySupplier
Get-SnipeitSupplier -id 2
#>
function Get-SnipeitSupplier()
{
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -43,6 +43,7 @@ Get-SnipeitUser -email user@somedomain.com
#>
function Get-SnipeitUser() {
[CmdletBinding(DefaultParameterSetName = 'Search')]
Param(
[parameter(ParameterSetName='Search')]
[string]$search,

View file

@ -17,7 +17,7 @@
.PARAMETER username
Username for user
.PARAMETER active
.PARAMETER activated
Can user log in to snipe-it?
.PARAMETER notes

View file

@ -10,12 +10,11 @@ Input string
.EXAMPLE
Get-Content [your-script.ps1] | Update-SnipeitAlias | Out-File [new-script-name.ps1]
Replaces old command from file "your-script.ps1" and creates new script "new-script-name.ps1"
After testing new file you can replace old file with new.
#>
function Update-SnipeitAlias()
{
[CmdletBinding(

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Accessories
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitAccessory [-search <String>] [-company_id <Int32>] [-category_id <Int32>] [-manufacturer_id <Int32>]
[-supplier_id <Int32>] [-sort <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Categories
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitCategory [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all]
-url <String> -apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Companies
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitCompany [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all] -url <String>
-apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Components
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitComponent [-search <String>] [-category_id <Int32>] [-company_id <Int32>] [-location_id <Int32>]
[-order <String>] [-sort <String>] [-limit <Int32>] [-offset <Int32>] [-all] -url <String> -apiKey <String>

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Departments
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitDepartment [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all]
[-sort <String>] -url <String> -apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Licenses
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitLicense [-search <String>] [-name <String>] [-company_id <Int32>] [-product_key <String>]
[-order_number <String>] [-purchase_order <String>] [-license_name <String>] [-license_email <MailAddress>]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Locations
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitLocation [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all]
-url <String> -apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ schema: 2.0.0
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitManufacturer [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all]
-url <String> -apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Models
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitModel [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all] -url <String>
-apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ Gets a list of Snipe-it Status Labels
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitStatus [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all] -url <String>
-apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ schema: 2.0.0
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitSupplier [-search <String>] [-order <String>] [-limit <Int32>] [-offset <Int32>] [-all]
-url <String> -apiKey <String> [<CommonParameters>]

View file

@ -12,7 +12,7 @@ schema: 2.0.0
## SYNTAX
### Search
### Search (Default)
```
Get-SnipeitUser [-search <String>] [-company_id <Int32>] [-location_id <Int32>] [-group_id <Int32>]
[-department_id <Int32>] [-username <String>] [-email <String>] [-order <String>] [-limit <Int32>]

View file

@ -13,7 +13,7 @@ Set license seat or checkout license seat
## SYNTAX
```
Set-SnipeitLicenseSeat [-id] <Int32[]> [-seat_id] <Int32> [[-assigned_id] <Int32>] [[-asset_id] <Int32>]
Set-SnipeitLicenseSeat [-id] <Int32[]> [-seat_id] <Int32> [[-assigned_to] <Int32>] [[-asset_id] <Int32>]
[[-note] <String>] [-url] <String> [-apiKey] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
```
@ -66,13 +66,13 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -assigned_id
{{ Fill assigned_id Description }}
### -assigned_to
Id of target user
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Aliases: assigned_id
Required: False
Position: 3

View file

@ -34,7 +34,7 @@ Updates user with id 3
## PARAMETERS
### -activated
{{ Fill activated Description }}
Can user log in to snipe-it?
```yaml
Type: Boolean

View file

@ -135,5 +135,5 @@ Updates Model on Snipe-it asset system
Creates a new user
### [Update-SnipeitAlias](Update-SnipeitAlias.md)
{{ Fill in the Synopsis }}
Replaces old SnipeitPS commands with new ones

View file

@ -8,7 +8,7 @@ schema: 2.0.0
# Update-SnipeitAlias
## SYNOPSIS
{{ Fill in the Synopsis }}
Replaces old SnipeitPS commands with new ones
## SYNTAX
@ -17,21 +17,22 @@ Update-SnipeitAlias [-String] <String[]> [-WhatIf] [-Confirm] [<CommonParameters
```
## DESCRIPTION
{{ Fill in the Description }}
Replaces old SnipeitPS commands with new ones
## EXAMPLES
### Example 1
```powershell
PS C:\> {{ Add example code here }}
### EXAMPLE 1
```
Get-Content [your-script.ps1] | Update-SnipeitAlias | Out-File [new-script-name.ps1]
```
{{ Add example description here }}
Replaces old command from file "your-script.ps1" and creates new script "new-script-name.ps1"
After testing new file you can replace old file with new.
## PARAMETERS
### -String
{{ Fill String Description }}
Input string
```yaml
Type: String[]
@ -39,7 +40,7 @@ Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
@ -81,11 +82,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS
### System.String[]
## OUTPUTS
### System.Object
## NOTES
## RELATED LINKS

43
docs/about_SnipeitPS.md Normal file
View file

@ -0,0 +1,43 @@
# About SnipeitPS
## about_SnipeitPS
# SHORT DESCRIPTION
Powershell API Wrapper for Snipe-it.
# LONG DESCRIPTION
Collection of tools that makes interacting with Snipe-it api more pleasant.
# EXAMPLES
Prepare connection Snipe-It with:
Set-SnipeitInfo -url https://your.site -apikey YourVeryLongApiKey....
To search assets use:
Get-SnipeitAsset -search needle
Piping get and new commands results to set commands is supported. Followirg will
set notes for every asset that have model_id 123.
Get-SnipeitAsset -model_id 123 -all | Set-SnipeitAsset
You can get specific items with -id prameter like
Get-SnipeitModel -id 123
# NOTE
Most of commands are using same parameters as in Snipe It api,
but it's always good idea check syntax with Get-Help
# TROUBLESHOOTING NOTE
Check your api key and certificate on server first.
# SEE ALSO
Report any issues to:
[GitHub project page](https://github.com/snazy2000/SnipeitPS/issues)
# KEYWORDS
- Snipe-It
- asset management