Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
91 changes: 91 additions & 0 deletions ServiceNow/Public/Get-ServiceNowRequestItem.ps1
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 6 additions & 2 deletions ServiceNow/ServiceNow.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = @()
Expand Down Expand Up @@ -107,3 +107,7 @@ PrivateData = @{







4 changes: 4 additions & 0 deletions Tests/ServiceNow.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down