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/Public/Get-ServiceNowRequestItem.ps1 b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 new file mode 100644 index 0000000..fdb929a --- /dev/null +++ b/ServiceNow/Public/Get-ServiceNowRequestItem.ps1 @@ -0,0 +1,91 @@ +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)] + [string]$OrderBy = 'opened_at', + + # Direction of ordering (Desc/Asc) + [parameter(Mandatory = $false)] + [ValidateSet('Desc', 'Asc')] + [string]$OrderDirection = 'Desc', + + # Maximum number of records to return + [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)] + [hashtable]$MatchExact = @{}, + + # Hashtable containing machine field names and values returned rows must contain (will be combined with AND) + [parameter(Mandatory = $false)] + [hashtable]$MatchContains = @{}, + + # Whether or not to show human readable display values instead of machine values + [parameter(Mandatory = $false)] + [ValidateSet('true', 'false', 'all')] + [string]$DisplayValues = 'true', + + [Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)] + [ValidateNotNullOrEmpty()] + [Alias('ServiceNowCredential')] + [PSCredential]$Credential, + + [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..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' @@ -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 = @() @@ -107,3 +107,7 @@ PrivateData = @{ + + + + 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 }