Skip to content

Commit

Permalink
Merge pull request #133 from snazy2000/develop
Browse files Browse the repository at this point in the history
Version to 1.4
  • Loading branch information
PetriAsi authored Jun 5, 2021
2 parents 1742db7 + b062072 commit 0b1d7f9
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 31 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/),
and this project adheres to [Semantic Versioning](http://semver.org/).

# [v1.4.x] - 2021-05-27

## More Activity

### New features
SnipeIt activity history is now searchable. So finding out checked out the
assest its easy. Api support many different target or item types that can
be uses as filter. Searchable types are 'Accessory','Asset','AssetMaintenance'
,'AssetModel','Category','Company','Component','Consumable','CustomField',
,'Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel',
'Supplier','User'


### New Functions
- Get-SnipeItActivity Get and search Snipe-It change history.


# [v1.3.x] - 2021-05-27

## Checking out accessories
Expand Down
126 changes: 126 additions & 0 deletions SnipeitPS/Public/Get-SnipeItActivity.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}






5 changes: 3 additions & 2 deletions SnipeitPS/SnipeItPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'SnipeItPS'

# Version number of this module.
ModuleVersion = '1.3'
ModuleVersion = '1.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -114,7 +114,8 @@ FunctionsToExport = @(
'Update-SnipeItAlias',
'Set-SnipeItAccessoryOwner',
'Get-SnipeItAccessoryOwner',
'Reset-SnipeItAccessoryOwner'
'Reset-SnipeItAccessoryOwner',
'Get-SnipeItActivity'

)

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ environment:
PSGalleryAPIKey:
secure: UdM6qhf5B0G8liHhUrwWERCZr44iSqmg4jUq0lwlTjZs4KyeoiwnBzdej0phqIAm

version: 1.3.{build}
version: 1.4.{build}

# Don't rebuild when I tag a release on GitHub
skip_tags: true
Expand Down
215 changes: 215 additions & 0 deletions docs/Get-SnipeItActivity.md
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 0b1d7f9

Please sign in to comment.