|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Gets and search Snipe-it Activity history |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | +Gets a list of Snipe-it activity history |
| 7 | +
|
| 8 | +.PARAMETER search |
| 9 | +A text string to search the Activity history |
| 10 | +
|
| 11 | +.PARAMETER target_type |
| 12 | +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' |
| 13 | +
|
| 14 | +.PARAMETER target_id |
| 15 | +Needed if target_type is specified |
| 16 | +
|
| 17 | +.PARAMETER item_type |
| 18 | +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' |
| 19 | +
|
| 20 | +.PARAMETER item_id |
| 21 | +Needed if target_type is specified |
| 22 | +
|
| 23 | +.PARAMETER action_type |
| 24 | +Type of action. One from following list "add seats", "checkin from", 'checkout' or 'update' |
| 25 | +
|
| 26 | +.PARAMETER offset |
| 27 | +Result offset to use |
| 28 | +
|
| 29 | +.PARAMETER all |
| 30 | +A return all results, works with -offset and other parameters |
| 31 | +
|
| 32 | +.PARAMETER url |
| 33 | +URL of Snipeit system, can be set using Set-SnipeItInfo command |
| 34 | +
|
| 35 | +.PARAMETER apiKey |
| 36 | +Users API Key for Snipeit, can be set using Set-SnipeItInfo command |
| 37 | +
|
| 38 | +.EXAMPLE |
| 39 | +Get-SnipeItAccessory -search Keyboard |
| 40 | +
|
| 41 | +.EXAMPLE |
| 42 | +Get-SnipeItAccessory -id 1 |
| 43 | +
|
| 44 | +#> |
| 45 | + |
| 46 | +function Get-SnipeItActivity() { |
| 47 | + Param( |
| 48 | + |
| 49 | + [string]$search, |
| 50 | + |
| 51 | + [Parameter(Mandatory=$false)] |
| 52 | + [ValidateSet('Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User')] |
| 53 | + [string]$target_type, |
| 54 | + |
| 55 | + [Parameter(Mandatory=$false)] |
| 56 | + [int]$target_id, |
| 57 | + |
| 58 | + [Parameter(Mandatory=$false)] |
| 59 | + [ValidateSet('Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User')] |
| 60 | + [string]$item_type, |
| 61 | + |
| 62 | + [Parameter(Mandatory=$false)] |
| 63 | + [int]$item_id, |
| 64 | + |
| 65 | + [ValidateSet("add seats", "checkin from", 'checkout','update')] |
| 66 | + [string]$action_type , |
| 67 | + |
| 68 | + [int]$limit = 50, |
| 69 | + |
| 70 | + [int]$offset, |
| 71 | + |
| 72 | + [switch]$all = $false, |
| 73 | + |
| 74 | + [parameter(mandatory = $true)] |
| 75 | + [string]$url, |
| 76 | + |
| 77 | + [parameter(mandatory = $true)] |
| 78 | + [string]$apiKey |
| 79 | + ) |
| 80 | + |
| 81 | + if(($target_type -and -not $target_id) -or |
| 82 | + ($target_id -and -not $target_type)) { |
| 83 | + throw "Please specify both target_type and target_id" |
| 84 | + } |
| 85 | + |
| 86 | + if(($item_type -and -not $item_id) -or |
| 87 | + ($item_id -and -not $item_type)) { |
| 88 | + throw "Please specify both item_type and item_id" |
| 89 | + } |
| 90 | + |
| 91 | + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters |
| 92 | + |
| 93 | + |
| 94 | + $Parameters = @{ |
| 95 | + Uri = "$url/api/v1/reports/activity" |
| 96 | + Method = 'Get' |
| 97 | + GetParameters = $SearchParameter |
| 98 | + Token = $apiKey |
| 99 | + } |
| 100 | + |
| 101 | + if ($all) { |
| 102 | + $offstart = $(if($offset){$offset} Else {0}) |
| 103 | + $callargs = $SearchParameter |
| 104 | + $callargs.Remove('all') |
| 105 | + |
| 106 | + while ($true) { |
| 107 | + $callargs['offset'] = $offstart |
| 108 | + $callargs['limit'] = $limit |
| 109 | + $res=Get-SnipeItActivity @callargs |
| 110 | + $res |
| 111 | + if ($res.count -lt $limit) { |
| 112 | + break |
| 113 | + } |
| 114 | + $offstart = $offstart + $limit |
| 115 | + } |
| 116 | + } else { |
| 117 | + $result = Invoke-SnipeitMethod @Parameters |
| 118 | + $result |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
0 commit comments