From 213386f440835c5c540cbcdac6fe222f1b3c3e35 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sat, 5 Jun 2021 08:10:45 +0300 Subject: [PATCH 1/2] Added Get-SnipeitActivity --- SnipeitPS/Public/Get-SnipeItActivity.ps1 | 126 +++++++++++++ SnipeitPS/SnipeItPS.psd1 | 3 +- docs/Get-SnipeItActivity.md | 215 +++++++++++++++++++++++ docs/Get-SnipeItCompany.md | 6 +- docs/Get-SnipeItComponent.md | 9 +- docs/Get-SnipeItManufacturer.md | 6 +- docs/New-SnipeItAsset.md | 9 +- docs/New-SnipeItUser.md | 3 +- docs/Set-SnipeItLicenseSeat.md | 6 +- docs/Set-SnipeItUser.md | 3 +- docs/SnipeItPS.md | 3 + 11 files changed, 360 insertions(+), 29 deletions(-) create mode 100644 SnipeitPS/Public/Get-SnipeItActivity.ps1 create mode 100644 docs/Get-SnipeItActivity.md diff --git a/SnipeitPS/Public/Get-SnipeItActivity.ps1 b/SnipeitPS/Public/Get-SnipeItActivity.ps1 new file mode 100644 index 0000000..1169b4d --- /dev/null +++ b/SnipeitPS/Public/Get-SnipeItActivity.ps1 @@ -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 + } +} + + + + + + diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index d96d5d8..e08f7d0 100644 --- a/SnipeitPS/SnipeItPS.psd1 +++ b/SnipeitPS/SnipeItPS.psd1 @@ -114,7 +114,8 @@ FunctionsToExport = @( 'Update-SnipeItAlias', 'Set-SnipeItAccessoryOwner', 'Get-SnipeItAccessoryOwner', - 'Reset-SnipeItAccessoryOwner' + 'Reset-SnipeItAccessoryOwner', + 'Get-SnipeItActivity' ) diff --git a/docs/Get-SnipeItActivity.md b/docs/Get-SnipeItActivity.md new file mode 100644 index 0000000..a31980b --- /dev/null +++ b/docs/Get-SnipeItActivity.md @@ -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] ] [[-target_type] ] [[-target_id] ] + [[-item_type] ] [[-item_id] ] [[-action_type] ] [[-limit] ] [[-offset] ] + [-all] [-url] [-apiKey] [] +``` + +## 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 diff --git a/docs/Get-SnipeItCompany.md b/docs/Get-SnipeItCompany.md index e7f9d6b..661a24f 100644 --- a/docs/Get-SnipeItCompany.md +++ b/docs/Get-SnipeItCompany.md @@ -25,16 +25,14 @@ Get-SnipeItCompany [[-search] ] [[-id] ] [[-order] ] [[-l ### EXAMPLE 1 ``` Get-SnipeItCompany -``` - Gets all companies +``` ### EXAMPLE 2 ``` Get-SnipeItCompany -id 1 -``` - Gets specific company +``` ## PARAMETERS diff --git a/docs/Get-SnipeItComponent.md b/docs/Get-SnipeItComponent.md index 1e8405a..81dcfbc 100644 --- a/docs/Get-SnipeItComponent.md +++ b/docs/Get-SnipeItComponent.md @@ -26,23 +26,20 @@ Get-SnipeItComponent [[-search] ] [[-id] ] [[-category_id] ] [[-id] ] [[-order] ] ### EXAMPLE 1 ``` Get-SnipeItManufacturer -search HP -``` - Search all manufacturers for string HP +``` ### EXAMPLE 2 ``` Get-SnipeItManufacturer -id 3 -``` - Returns manufacturer with id 3 +``` ## PARAMETERS diff --git a/docs/New-SnipeItAsset.md b/docs/New-SnipeItAsset.md index a9ebd08..a515dd6 100644 --- a/docs/New-SnipeItAsset.md +++ b/docs/New-SnipeItAsset.md @@ -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 diff --git a/docs/New-SnipeItUser.md b/docs/New-SnipeItUser.md index dd563e9..3600cd0 100644 --- a/docs/New-SnipeItUser.md +++ b/docs/New-SnipeItUser.md @@ -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 diff --git a/docs/Set-SnipeItLicenseSeat.md b/docs/Set-SnipeItLicenseSeat.md index 0bbca1a..305ef41 100644 --- a/docs/Set-SnipeItLicenseSeat.md +++ b/docs/Set-SnipeItLicenseSeat.md @@ -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 diff --git a/docs/Set-SnipeItUser.md b/docs/Set-SnipeItUser.md index 1b2f9e1..4fb2642 100644 --- a/docs/Set-SnipeItUser.md +++ b/docs/Set-SnipeItUser.md @@ -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 diff --git a/docs/SnipeItPS.md b/docs/SnipeItPS.md index dbc6cf3..faa0b8d 100644 --- a/docs/SnipeItPS.md +++ b/docs/SnipeItPS.md @@ -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 From 0d832f07ccb3279e7eb1d89fc9c062222a8d2215 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sat, 5 Jun 2021 08:28:37 +0300 Subject: [PATCH 2/2] Version to 1.4 --- CHANGELOG.md | 17 +++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | 2 +- appveyor.yml | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58673ee..c4bc84c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index e08f7d0..ac66eb1 100644 --- a/SnipeitPS/SnipeItPS.psd1 +++ b/SnipeitPS/SnipeItPS.psd1 @@ -12,7 +12,7 @@ RootModule = 'SnipeItPS' # Version number of this module. -ModuleVersion = '1.3' +ModuleVersion = '1.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/appveyor.yml b/appveyor.yml index 14a5ce6..78cc948 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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