Merge pull request #131 from PetriAsi/feature/get-snipeitactivity

Added Get-SnipeitActivity
This commit is contained in:
Petri Asikainen 2021-06-05 08:15:05 +03:00 committed by GitHub
commit 4744e6c8fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 360 additions and 29 deletions

View file

@ -0,0 +1,126 @@
<#
.SYNOPSIS
Gets and search Snipe-it Activity history
.DESCRIPTION
Gets a list of Snipe-it activity history
.PARAMETER search
A text string to search the Activity history
.PARAMETER target_type
Type of target. One from following list 'Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User'
.PARAMETER target_id
Needed if target_type is specified
.PARAMETER item_type
Type of target. One from following list 'Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User'
.PARAMETER item_id
Needed if target_type is specified
.PARAMETER action_type
Type of action. One from following list "add seats", "checkin from", 'checkout' or 'update'
.PARAMETER offset
Result offset to use
.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 apiKey
Users API Key for Snipeit, can be set using Set-SnipeItInfo command
.EXAMPLE
Get-SnipeItAccessory -search Keyboard
.EXAMPLE
Get-SnipeItAccessory -id 1
#>
function Get-SnipeItActivity() {
Param(
[string]$search,
[Parameter(Mandatory=$false)]
[ValidateSet('Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User')]
[string]$target_type,
[Parameter(Mandatory=$false)]
[int]$target_id,
[Parameter(Mandatory=$false)]
[ValidateSet('Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User')]
[string]$item_type,
[Parameter(Mandatory=$false)]
[int]$item_id,
[ValidateSet("add seats", "checkin from", 'checkout','update')]
[string]$action_type ,
[int]$limit = 50,
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
if(($target_type -and -not $target_id) -or
($target_id -and -not $target_type)) {
throw "Please specify both target_type and target_id"
}
if(($item_type -and -not $item_id) -or
($item_id -and -not $item_type)) {
throw "Please specify both item_type and item_id"
}
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Parameters = @{
Uri = "$url/api/v1/reports/activity"
Method = 'Get'
GetParameters = $SearchParameter
Token = $apiKey
}
if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while ($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-SnipeItActivity @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -114,7 +114,8 @@ FunctionsToExport = @(
'Update-SnipeItAlias',
'Set-SnipeItAccessoryOwner',
'Get-SnipeItAccessoryOwner',
'Reset-SnipeItAccessoryOwner'
'Reset-SnipeItAccessoryOwner',
'Get-SnipeItActivity'
)

215
docs/Get-SnipeItActivity.md Normal file
View file

@ -0,0 +1,215 @@
---
external help file: SnipeItPS-help.xml
Module Name: SnipeitPS
online version:
schema: 2.0.0
---
# Get-SnipeItActivity
## SYNOPSIS
Gets and search Snipe-it Activity history
## SYNTAX
```
Get-SnipeItActivity [[-search] <String>] [[-target_type] <String>] [[-target_id] <Int32>]
[[-item_type] <String>] [[-item_id] <Int32>] [[-action_type] <String>] [[-limit] <Int32>] [[-offset] <Int32>]
[-all] [-url] <String> [-apiKey] <String> [<CommonParameters>]
```
## DESCRIPTION
Gets a list of Snipe-it activity history
## EXAMPLES
### EXAMPLE 1
```
Get-SnipeItAccessory -search Keyboard
```
### EXAMPLE 2
```
Get-SnipeItAccessory -id 1
```
## PARAMETERS
### -action_type
Type of action.
One from following list "add seats", "checkin from", 'checkout' or 'update'
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -all
A return all results, works with -offset and other parameters
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -apiKey
Users API Key for Snipeit, can be set using Set-SnipeItInfo command
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 10
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -item_id
Needed if target_type is specified
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
```
### -item_type
Type of target.
One from following list 'Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User'
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -limit
{{ Fill limit Description }}
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 7
Default value: 50
Accept pipeline input: False
Accept wildcard characters: False
```
### -offset
Result offset to use
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 8
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
```
### -search
A text string to search the Activity history
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -target_id
Needed if target_type is specified
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
```
### -target_type
Type of target.
One from following list 'Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User'
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -url
URL of Snipeit system, can be set using Set-SnipeItInfo command
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 9
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
## NOTES
## RELATED LINKS

View file

@ -25,16 +25,14 @@ Get-SnipeItCompany [[-search] <String>] [[-id] <Int32>] [[-order] <String>] [[-l
### EXAMPLE 1
```
Get-SnipeItCompany
```
Gets all companies
```
### EXAMPLE 2
```
Get-SnipeItCompany -id 1
```
Gets specific company
```
## PARAMETERS

View file

@ -26,23 +26,20 @@ Get-SnipeItComponent [[-search] <String>] [[-id] <Int32>] [[-category_id] <Int32
### EXAMPLE 1
```
Get-SnipeItComponent
```
Returns all components
```
### EXAMPLE 2
```
Get-SnipeItComponent -search display
```
Returns search results containeing string display
```
### EXAMPLE 3
```
Get-SnipeItComponent -id
```
Returns specific component
```
## PARAMETERS

View file

@ -25,16 +25,14 @@ Get-SnipeItManufacturer [[-search] <String>] [[-id] <Int32>] [[-order] <String>]
### EXAMPLE 1
```
Get-SnipeItManufacturer -search HP
```
Search all manufacturers for string HP
```
### EXAMPLE 2
```
Get-SnipeItManufacturer -id 3
```
Returns manufacturer with id 3
```
## PARAMETERS

View file

@ -28,23 +28,20 @@ Long description
### EXAMPLE 1
```
New-SnipeItAsset -status_id 1 -model_id 1 -name "Machine1"
```
Create asset with automatic tag if tag genaration is enabled on snipe-it, other wise without tag
```
### EXAMPLE 2
```
New-SnipeItAsset -status_id 1 -model_id 1 -name "Machine1" -asset_tag "DEV123"
```
Specifying asset tag when creating asset
```
### EXAMPLE 3
```
New-SnipeItAsset -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5" = "Windows 10 Pro" }
```
Using customfields when creating asset.
```
## PARAMETERS

View file

@ -28,9 +28,8 @@ Creates a new user to Snipe-IT system
### EXAMPLE 1
```
New-SnipeItuser -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1
```
Creates new a new user who can't login to system
```
## PARAMETERS

View file

@ -25,16 +25,14 @@ Checkout specific license seat to user, asset or both
### EXAMPLE 1
```
Set-SnipeItLicenceSeat -ID 1 -seat_id 1 -assigned_id 3 -Verbose
```
Checkout licence to user id 3
```
### EXAMPLE 2
```
Set-SnipeItLicenceSeat -ID 1 -seat_id 1 -asset_id 3 -Verbose
```
Checkout licence to asset id 3
```
## PARAMETERS

View file

@ -28,9 +28,8 @@ Creates a new user to Snipe-IT system
### EXAMPLE 1
```
Update-SnipeItUser -id 3 -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1
```
Updates user with id 3
```
## PARAMETERS

View file

@ -17,6 +17,9 @@ Gets a list of Snipe-it Accessories
### [Get-SnipeItAccessoryOwner](Get-SnipeItAccessoryOwner.md)
Get list of checked out accessories
### [Get-SnipeItActivity](Get-SnipeItActivity.md)
Gets and search Snipe-it Activity history
### [Get-SnipeItAsset](Get-SnipeItAsset.md)
Gets a list of Snipe-it Assets or specific asset