From 30991c04c749f22b4aaa874ad559b44fffe86474 Mon Sep 17 00:00:00 2001 From: Joshua T Date: Mon, 17 Dec 2018 11:27:50 -0600 Subject: [PATCH 1/4] Create function Get-ServiceNowRequestItem This function is copied from the Get-ServiceNowRequest function. The only real difference is the table it queries. I copied and pasted a simple test for this function from the Get-ServiceNowRequest function, but I can't access the test environment it's querying in order to validate that the test works. --- .../Public/Get-ServiceNowRequestItem.ps1 | 93 +++++++++++++++++++ ServiceNow/ServiceNow.psd1 | 2 +- Tests/ServiceNow.Tests.ps1 | 4 + 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 ServiceNow/Public/Get-ServiceNowRequestItem.ps1 diff --git a/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 new file mode 100644 index 0000000..da28683 --- /dev/null +++ b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 @@ -0,0 +1,93 @@ +function Get-ServiceNowRequestItem { + param( + # Machine name of the field to order by + [parameter(mandatory = $false)] + [parameter(ParameterSetName = 'SpecifyConnectionFields')] + [parameter(ParameterSetName = 'UseConnectionObject')] + [parameter(ParameterSetName = 'SetGlobalAuth')] + [string]$OrderBy = 'opened_at', + + # Direction of ordering (Desc/Asc) + [parameter(mandatory = $false)] + [parameter(ParameterSetName = 'SpecifyConnectionFields')] + [parameter(ParameterSetName = 'UseConnectionObject')] + [parameter(ParameterSetName = 'SetGlobalAuth')] + [ValidateSet("Desc", "Asc")] + [string]$OrderDirection = 'Desc', + + # Maximum number of records to return + [parameter(mandatory = $false)] + [parameter(ParameterSetName = 'SpecifyConnectionFields')] + [parameter(ParameterSetName = 'UseConnectionObject')] + [parameter(ParameterSetName = 'SetGlobalAuth')] + [int]$Limit = 10, + + # Hashtable containing machine field names and values returned must match exactly (will be combined with AND) + [parameter(mandatory = $false)] + [parameter(ParameterSetName = 'SpecifyConnectionFields')] + [parameter(ParameterSetName = 'UseConnectionObject')] + [parameter(ParameterSetName = 'SetGlobalAuth')] + [hashtable]$MatchExact = @{}, + + # Hashtable containing machine field names and values returned rows must contain (will be combined with AND) + [parameter(mandatory = $false)] + [parameter(ParameterSetName = 'SpecifyConnectionFields')] + [parameter(ParameterSetName = 'UseConnectionObject')] + [parameter(ParameterSetName = 'SetGlobalAuth')] + [hashtable]$MatchContains = @{}, + + # Whether or not to show human readable display values instead of machine values + [parameter(mandatory = $false)] + [parameter(ParameterSetName = 'SpecifyConnectionFields')] + [parameter(ParameterSetName = 'UseConnectionObject')] + [parameter(ParameterSetName = 'SetGlobalAuth')] + [ValidateSet("true", "false", "all")] + [string]$DisplayValues = 'true', + + [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] + [ValidateNotNullOrEmpty()] + [PSCredential] + $ServiceNowCredential, + + [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] + [ValidateNotNullOrEmpty()] + [string] + $ServiceNowURL, + + [Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $True)] + [ValidateNotNullOrEmpty()] + [Hashtable] + $Connection + ) + + # Query Splat + $newServiceNowQuerySplat = @{ + OrderBy = $OrderBy + MatchExact = $MatchExact + OrderDirection = $OrderDirection + MatchContains = $MatchContains + } + $Query = New-ServiceNowQuery @newServiceNowQuerySplat + + # Table Splat + $getServiceNowTableSplat = @{ + Table = 'sc_req_item' + Query = $Query + Limit = $Limit + DisplayValues = $DisplayValues + } + + # Update the Table Splat if the parameters have values + if ($null -ne $PSBoundParameters.Connection) { + $getServiceNowTableSplat.Add('Connection', $Connection) + } + elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL) { + $getServiceNowTableSplat.Add('ServiceNowCredential', $ServiceNowCredential) + $getServiceNowTableSplat.Add('ServiceNowURL', $ServiceNowURL) + } + + # Perform query and return each object in the format.ps1xml format + $Result = Get-ServiceNowTable @getServiceNowTableSplat + $Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0, "ServiceNow.Request")} + $Result +} diff --git a/ServiceNow/ServiceNow.psd1 b/ServiceNow/ServiceNow.psd1 index b5f22b5..d7a2279 100644 --- a/ServiceNow/ServiceNow.psd1 +++ b/ServiceNow/ServiceNow.psd1 @@ -66,7 +66,7 @@ FormatsToProcess = @('ServiceNow.format.ps1xml') NestedModules = @() # Functions to export from this module -FunctionsToExport = @('Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowTable','Get-ServiceNowTableEntry','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowTableEntry','Remove-ServiceNowAuth','Remove-ServiceNowTableEntry','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowNumber','Update-ServiceNowTableEntry') +FunctionsToExport = @('Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowRequestItem','Get-ServiceNowTable','Get-ServiceNowTableEntry','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowTableEntry','Remove-ServiceNowAuth','Remove-ServiceNowTableEntry','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowNumber','Update-ServiceNowTableEntry') # List of all modules packaged with this module # ModuleList = @() diff --git a/Tests/ServiceNow.Tests.ps1 b/Tests/ServiceNow.Tests.ps1 index ea18a8c..42b04fe 100644 --- a/Tests/ServiceNow.Tests.ps1 +++ b/Tests/ServiceNow.Tests.ps1 @@ -79,6 +79,10 @@ Describe "ServiceNow-Module" { ([array](Get-ServiceNowRequest)).count -gt 0 | Should -Match $true } + It "Get-ServiceNowRequestItem returns records" { + ([array](Get-ServiceNowRequestItem)).count -gt 0 | Should -Match $true + } + It "Get-ServiceNowUserGroup works" { (Get-ServiceNowUserGroup).Count -gt 0 | Should -Match $true } From d0f05b219f86856655d156559caa5d410f9bfa76 Mon Sep 17 00:00:00 2001 From: Joshua T Date: Mon, 17 Dec 2018 12:05:32 -0600 Subject: [PATCH 2/4] Fix type name (copy/paste error) --- ServiceNow/Public/Get-ServiceNowRequestItem.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 index da28683..227a5f5 100644 --- a/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 +++ b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 @@ -88,6 +88,6 @@ function Get-ServiceNowRequestItem { # Perform query and return each object in the format.ps1xml format $Result = Get-ServiceNowTable @getServiceNowTableSplat - $Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0, "ServiceNow.Request")} + $Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0, "ServiceNow.RequestItem")} $Result } From 2c6b836f0fe44cbe051e3fa8a8bad557ed65f732 Mon Sep 17 00:00:00 2001 From: Rick-2CA Date: Thu, 27 Dec 2018 15:07:09 -0600 Subject: [PATCH 3/4] Added help, used lean params, set format to existing option --- .../Public/Get-ServiceNowRequestItem.ps1 | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 index 227a5f5..fdb929a 100644 --- a/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 +++ b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 @@ -1,63 +1,61 @@ function Get-ServiceNowRequestItem { +<# + .SYNOPSIS + Query for Request Item (RITM) tickets. + + .DESCRIPTION + Query for Request Item (RITM) tickets from the sc_req_item table. + + .EXAMPLE + Get-ServiceNowRequestItem -MatchExact @{number='RITM0000001'} + + Return the details for RITM0000001 + + .OUTPUTS + System.Management.Automation.PSCustomObject +#> + + [OutputType([System.Management.Automation.PSCustomObject])] + [CmdletBinding(DefaultParameterSetName)] param( # Machine name of the field to order by - [parameter(mandatory = $false)] - [parameter(ParameterSetName = 'SpecifyConnectionFields')] - [parameter(ParameterSetName = 'UseConnectionObject')] - [parameter(ParameterSetName = 'SetGlobalAuth')] + [parameter(Mandatory = $false)] [string]$OrderBy = 'opened_at', # Direction of ordering (Desc/Asc) - [parameter(mandatory = $false)] - [parameter(ParameterSetName = 'SpecifyConnectionFields')] - [parameter(ParameterSetName = 'UseConnectionObject')] - [parameter(ParameterSetName = 'SetGlobalAuth')] - [ValidateSet("Desc", "Asc")] + [parameter(Mandatory = $false)] + [ValidateSet('Desc', 'Asc')] [string]$OrderDirection = 'Desc', # Maximum number of records to return - [parameter(mandatory = $false)] - [parameter(ParameterSetName = 'SpecifyConnectionFields')] - [parameter(ParameterSetName = 'UseConnectionObject')] - [parameter(ParameterSetName = 'SetGlobalAuth')] + [parameter(Mandatory = $false)] [int]$Limit = 10, # Hashtable containing machine field names and values returned must match exactly (will be combined with AND) - [parameter(mandatory = $false)] - [parameter(ParameterSetName = 'SpecifyConnectionFields')] - [parameter(ParameterSetName = 'UseConnectionObject')] - [parameter(ParameterSetName = 'SetGlobalAuth')] + [parameter(Mandatory = $false)] [hashtable]$MatchExact = @{}, # Hashtable containing machine field names and values returned rows must contain (will be combined with AND) - [parameter(mandatory = $false)] - [parameter(ParameterSetName = 'SpecifyConnectionFields')] - [parameter(ParameterSetName = 'UseConnectionObject')] - [parameter(ParameterSetName = 'SetGlobalAuth')] + [parameter(Mandatory = $false)] [hashtable]$MatchContains = @{}, # Whether or not to show human readable display values instead of machine values - [parameter(mandatory = $false)] - [parameter(ParameterSetName = 'SpecifyConnectionFields')] - [parameter(ParameterSetName = 'UseConnectionObject')] - [parameter(ParameterSetName = 'SetGlobalAuth')] - [ValidateSet("true", "false", "all")] + [parameter(Mandatory = $false)] + [ValidateSet('true', 'false', 'all')] [string]$DisplayValues = 'true', [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] [ValidateNotNullOrEmpty()] - [PSCredential] - $ServiceNowCredential, + [Alias('ServiceNowCredential')] + [PSCredential]$Credential, [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] [ValidateNotNullOrEmpty()] - [string] - $ServiceNowURL, + [string]$ServiceNowURL, [Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $True)] [ValidateNotNullOrEmpty()] - [Hashtable] - $Connection + [hashtable]$Connection ) # Query Splat @@ -88,6 +86,6 @@ function Get-ServiceNowRequestItem { # Perform query and return each object in the format.ps1xml format $Result = Get-ServiceNowTable @getServiceNowTableSplat - $Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0, "ServiceNow.RequestItem")} + $Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0,'ServiceNow.Request')} $Result } From 75ce655ef09f044f75a34279bba3c84a2190c9df Mon Sep 17 00:00:00 2001 From: Rick-2CA Date: Thu, 27 Dec 2018 15:14:37 -0600 Subject: [PATCH 4/4] v1.3.5 --- Readme.md | 2 +- ServiceNow/ServiceNow.psd1 | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 6545d4a..1327209 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ # ServiceNow -[![GitHub release](https://img.shields.io/github/release/Sam-Martin/servicenow-powershell.svg)](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) [![GitHub license](https://img.shields.io/github/license/Sam-Martin/servicenow-powershell.svg)](LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-79%25-yellow.svg) +[![GitHub release](https://img.shields.io/github/release/Sam-Martin/servicenow-powershell.svg)](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) [![GitHub license](https://img.shields.io/github/license/Sam-Martin/servicenow-powershell.svg)](LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-80%25-yellow.svg) This PowerShell module provides a series of cmdlets for interacting with the [ServiceNow REST API](http://wiki.servicenow.com/index.php?title=REST_API), performed by wrapping `Invoke-RestMethod` for the API calls. diff --git a/ServiceNow/ServiceNow.psd1 b/ServiceNow/ServiceNow.psd1 index d7a2279..1cede23 100644 --- a/ServiceNow/ServiceNow.psd1 +++ b/ServiceNow/ServiceNow.psd1 @@ -12,7 +12,7 @@ RootModule = 'ServiceNow.psm1' # Version number of this module. -ModuleVersion = '1.2.4' +ModuleVersion = '1.3.5' # ID used to uniquely identify this module GUID = 'b90d67da-f8d0-4406-ad74-89d169cd0633' @@ -107,3 +107,7 @@ PrivateData = @{ + + + +