Skip to content

Commit 987091e

Browse files
authored
Merge branch 'master' into patch-1
2 parents 33917da + ffba5b8 commit 987091e

File tree

56 files changed

+3409
-2339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3409
-2339
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Bug report
3+
about: Report errors or unexpected behavior
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
**Important: Please be sure to provide complete code samples, leaving in as much detail as posible.
12+
-->
13+
14+
# Environment
15+
16+
```
17+
Operating System:
18+
ServiceNow module version:
19+
PowerShell version:
20+
```
21+
22+
# Steps to reproduce
23+
24+
<!-- A description of how to trigger this bug. -->
25+
26+
# Expected behavior
27+
28+
<!-- A description of what you're expecting, possibly containing screenshots or reference material. -->
29+
30+
# Actual behavior
31+
32+
<!-- What's actually happening? -->
33+
34+
# Screenshots
35+
36+
<!-- If applicable, add screenshots to help explain your problem. -->

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Documentation Issue
3+
about: Report issues in the documentation
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Briefly describe which document/function needs to be corrected and why. -->
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
# Summary of the new feature/enhancement
11+
12+
<!--
13+
A clear and concise description of what the problem is that the new feature would solve.
14+
Describe why and how a user would use this new functionality (if applicable).
15+
-->
16+
17+
# Proposed technical implementation details (optional)
18+
19+
<!--
20+
A clear and concise description of what you want to happen.
21+
-->

CHANGELOG.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## 3.0
2+
- New functionality in `Get-ServiceNowRecord`
3+
- Add `Id` property to easily retrieve a record by either number or sysid.
4+
- Add `ParentId` property to easily retrieve records based on the parent number or sysid. For example, to retrieve catalog tasks associated with a requested item execute `Get-ServiceNowRecord -Table 'Catalog Task' -ParentId RITM01234567`.
5+
- Add `Description` property to retrieve records based on a table specific description field. For many tables this field will be short_description, but will be different for others. For example, when performing this against the 'User' table, the description field is 'Name'.
6+
- Add ability to provide a known prefixed `Id` without providing `Table`, `Get-ServiceNowRecord -Id inc0010001`. To see the list of known prefixes, execute `$ServiceNowTable.NumberPrefix` after importing the module.
7+
- Add alias `gsnr`. With the above change, a Get can be as simple as `gsnr inc0010001`.
8+
- Add autocomplete for `Table` parameter in `Add-ServiceNowAttachment` and `Get-ServiceNowAttachment`.
9+
- Add `Id` parameter to `Add-ServiceNowAttachment` and `Update-ServiceNowRecord` which accepts either number or sysid. Just as with `Get-ServiceNowRecord` you can now provide just `Id` if it has a known prefix.
10+
- Add ability to `Get-ServiceNowAttachment` to get attachments either via associated record or directly from the attachments table when you want to search all attachments.
11+
- Add advanced filtering and sorting functionality to `Get-ServiceNowAttachment` which can be really useful when searching across the attachments table.
12+
- Convert access and refresh tokens in $ServiceNowSession from plain text to a credential for added security.
13+
- Pipeline enhancements added in many places.
14+
- Add Change Task and Attachments to formats.
15+
- `Update-ServiceNowNumber` has been deprecated and the functionality has been added to `Update-ServiceNowRecord`. An alias has also been added so existing scripts do not break.
16+
- Prep for removal of all `Get-` functions except for `Get-ServiceNowRecord` and `Get-ServiceNowAttachment`. Table specific Get functions have been deprecated. `Get-ServiceNowRecordInterim` has been created and all table specific Get functions have been aliased so existing scripts do not break. Please start to migrate to `Get-ServiceNowRecord` as these functions will all be deprecated in the near future.
17+
- As communicated in v2.0, authentication cleanup has occurred. This involves removal of Credential/Url authentication in each function in favor of `ServiceNowSession`. You can still authenticate with Credential/Url, but must use `New-ServiceNowSession`. `Set-ServiceNowAuth`, `Remove-ServiceNowAuth`, and `Test-ServiceNowAuthIsSet` have been deprecated.
18+
- ***Breaking change:*** rename `Get-ServiceNowAttachmentDetail` to `Get-ServiceNowAttachment`.
19+
- ***Breaking change:*** rename `Get-ServiceNowAttachment` to `Export-ServiceNowAttachment`.
20+
- ***Breaking change:*** `Get-ServiceNowTable` and `Get-ServiceNowTableEntry` have been deprecated. Use `Get-ServiceNowRecord`.
21+
22+
## 2.4.2
23+
- Fix [#141](https://github.com/Snow-Shell/servicenow-powershell/issues/141), add `UseBasicParsing` to all API calls to keep AA from failing when IE hasn't been initialized
24+
25+
## 2.4.1
26+
- Add `-IncludeCustomVariable` to `Get-ServiceNowRecord` to retrieve custom variables, eg. ritm form values, in addition to the standard fields. [#138](https://github.com/Snow-Shell/servicenow-powershell/discussions/138)
27+
28+
## 2.4
29+
- Add `New-ServiceNowConfigurationItem`, [#109](https://github.com/Snow-Shell/servicenow-powershell/issues/109)
30+
- Add grouping operators -and and -group as well as comparison operators -startwith and -endswith to `Get-ServiceNowRecord -Filter` to keep with the -operator standard
31+
- Add tab ahead/completion for the `-Table` property in `Get-ServiceNowRecord`. This will allow you to cycle through the different tables the module is aware of. The values are the 'common' names, not table names so it's easier to understand for beginners. You can also provide any other table name ad hoc.
32+
- Add Change Task to formatter and tab ahead
33+
- Fix null index error when executing `New-ServiceNowQuery` without providing a value for `-Sort`
34+
- Fix [#136](https://github.com/Snow-Shell/servicenow-powershell/issues/136) to account for PS v7.x Invoke-WebRequest response headers all being arrays
35+
36+
## 2.3.2
37+
- Added ability to pipe to `Add-ServiceNowAttachment` and `Get-ServiceNowAttachmentDetail`. For example, `New-ServiceNowIncident @params -PassThru | Add-ServiceNowAttachment -File MyFile.txt`. This will create an incident and add an attachment in one step.
38+
39+
## 2.3.1
40+
- Fix query operator -notin and -notlike which had a missing space
41+
- Move verbose logging message in `Invoke-ServiceNowRestMethod` for number of records so it always shows. This is helpful when you change a filter and can see how many records would be returned without actually returning them.
42+
43+
## v2.3
44+
- Add paging support to all `Get-` functions. Use `-First`, `-Skip`, and `-IncludeTotalCount` parameters. In support of this, api calls have been changed from Invoke-RestMethod to Invoke-WebRequest.
45+
- Additional pipline support added for Table and SysId parameters to pipe `Get-` functions to `Update-` and `Remove-`.
46+
- ***Breaking change:*** deprecate `-Limit` parameter. The warning regarding deprecation went out over 2 years ago and now that paging has been implemented, it's a good time for this cleanup. Use `-First` instead.
47+
- 'TableEntry' renamed to 'Record' for `New-`, `Update-`, and `Remove-` functions. Aliases added.
48+
49+
## v2.2
50+
- Add advanced filtering and sorting. Initially implemented with `New-ServiceNowQuery` and `Get-ServiceNowRecord`. Filter with many different comparison operators as well as 'and', 'or', and 'group'ing. Sort ascending or descending against multiple fields. Comparison operators are the same as PowerShell for ease of use. Please use the GitHub Discussions section to provide feedback, thoughts, etc.
51+
- Add `Get-ServiceNowRecord`. This function implements the new advanced filtering and sorting. As long as you know your table name, this can replace all other Get functions.
52+
- Enumerate implemented tables and advanced filtering operators in a json config to easily manage going forward; make available via script scoped variables.
53+
Be able to reference types from this config per table, removing the need to have separate Get functions for every table.
54+
- Add type for catalog task
55+
- Fix error when getting an empty result from the api and performing a type lookup
56+
- Rename `RequestItem` to `RequestedItem` which is the actual name. Function aliases created.
57+
58+
## v2.1
59+
- Add proxy support to `New-ServiceNowSession`, [#97](https://github.com/Snow-Shell/servicenow-powershell/issues/97).
60+
61+
## v2.0
62+
- Although still in the module for backward compatibility, `Set-ServiceNowAuth` is being replaced with `New-ServiceNowSession`. With this comes OAuth support, removal of global variables, and much more folks have asked for. The ability to provide credentials directly to functions has been retained for this release, but will be deprecated in a future release in favor of using `New-ServiceNowSession`.
63+
- Support for different api versions. `Set-ServiceNowAuth` will continue to use v1 of the api, but `New-ServiceNowSession` defaults to the latest. Check out the `-ApiVersion` parameter of `New-ServiceNowSession`.
64+
- `Remove-ServiceNowAuth` has been retained for this release, but as global variables have been removed, there is no longer a need for it; it will always return `$true`. It will be removed in a future release.
65+
- `-PassThru` added to remaining `Update-` and `New-` functions. Depending on your code, this may be a ***breaking change*** if you expected the result to be returned.
66+
- Pipeline support added to many functions
67+
- Standardizing on coding between all functions
68+
69+
## v1.8.1
70+
- Update links to reference the new GitHub organization this project will be moved to. Module functionality unchanged.
71+
72+
## v1.8.0
73+
- Add Update-ServiceNowRequestItem
74+
- Fix switch statements by adding breaks to each condition
75+
76+
## v1.7.0
77+
- Add New-ServiceNowChangeRequest
78+
79+
## v1.6.0
80+
- Add Update-ServiceNowDateTimeField
81+
- Add Add-ServiceNowAttachment
82+
- Add Get-ServiceNowAttachment
83+
- Add Get-ServiceNowAttachmentDetail
84+
- Add Remove-ServiceNowAttachment

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2015-2021 Snow-Shell
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

RELEASE.md

Whitespace-only changes.

Readme.md

Lines changed: 51 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
# ServiceNow
22

3-
[![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-75%25-yellow.svg)
3+
[![PowerShell Gallery Version](https://img.shields.io/powershellgallery/v/ServiceNow?style=plastic)](https://www.powershellgallery.com/packages/ServiceNow)
4+
![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/ServiceNow?style=plastic)
5+
[![GitHub license](https://img.shields.io/github/license/Snow-Shell/servicenow-powershell.svg?style=plastic)](LICENSE)
46

5-
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.
7+
This PowerShell module provides a series of cmdlets for interacting with the [ServiceNow REST API](https://docs.servicenow.com/bundle/quebec-application-development/page/integrate/inbound-rest/concept/c_RESTAPI.html).
68

79
**IMPORTANT:** Neither this module nor its creator are in any way affiliated with ServiceNow.
810

9-
## Version 1
11+
## Version 2
1012

11-
The module has been renamed from PSServiceNow to ServiceNow for version 1. This change moves us away from the reserved "PS" prefix. Since the name change is a major change for the user base and the project was never incremented to v1 we've taken the opportunity to label it such.
13+
Building on the great work the community has done thus far, a lot of new updates with this release.
14+
- Although still in the module for backward compatibility, `Set-ServiceNowAuth` is being replaced with `New-ServiceNowSession`. With this comes OAuth support, removal of global variables, and much more folks have asked for. The ability to provide credentials directly to functions has been retained for this release, but will be deprecated in a future release in favor of using `New-ServiceNowSession`.
15+
- Support for different api versions. `Set-ServiceNowAuth` will continue to use v1 of the api, but `New-ServiceNowSession` defaults to the latest. Check out the `-ApiVersion` parameter of `New-ServiceNowSession`.
16+
- `Remove-ServiceNowAuth` has been retained for this release, but as global variables have been removed, there is no longer a need for it; it will always return `$true`. It will be removed in a future release.
17+
- `-PassThru` added to remaining `Update-` and `New-` functions. Depending on your code, this may be a ***breaking change*** if you expected the result to be returned.
18+
- Pipeline support added to many functions
19+
- Standardizing on coding between all functions
1220

13-
In addition to the name change the following high level changes have been made:
14-
15-
Back End:
16-
17-
* The module structure has been updated to individual files for each function.
18-
* The build process has been migrated from MAKE to psake with support of the BuildHelpers module.
19-
* Pester testing has been expanded to cover more scenarios.
20-
* Improved code formatting, removed aliases, fixed file encoding.
21-
22-
The gains are marginal in some aspects, but intended to allow for better management in the future.
23-
24-
Front End:
25-
26-
* The following fields are now returned in the DateTime format instead of string: 'closed_at','expected_start','follow_up','opened_at','sys_created_on','sys_updated_on','work_end','work_start' [v1.0.1 Update: This process now attempts to format the property as DateTime based off your local culture settings, a universal `yyyy-MM-dd HH:mm:ss` format, and finally leaves the property as a string if those two convert attempts fail].
27-
* The formatting of returned data has been updated across all the `Get` functions except `Get-ServiceNowTable`. This means you'll see a handful of default properties returned and can use `Format-List` or `Select-Object` to view all other properties associated with the object.
28-
29-
These changes should improve your ability to filter on the right, especially by DateTime, as well as return more information in general.
21+
***It is recommended to use `Get-ServiceNowRecord` instead of the other 'Get' functions.***
3022

3123
## Requirements
3224

33-
Requires PowerShell 3.0 or above as this is when `Invoke-RestMethod` was introduced.
25+
Requires PowerShell 5.1 or above.
3426

3527
Requires authorization in your ServiceNow tenant. Due to the custom nature of ServiceNow your organization may have REST access restricted. The following are some tips to ask for if you're having to go to your admin for access:
3628

@@ -40,46 +32,57 @@ Requires authorization in your ServiceNow tenant. Due to the custom nature of S
4032

4133
## Usage
4234

43-
Download the [latest release](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) and extract the .psm1 and .psd1 files to your PowerShell profile directory (i.e. the `Modules` directory under wherever `$profile` points to in your PS console) and run:
44-
`Import-Module ServiceNow`
45-
Once you've done this, all the cmdlets will be at your disposal, you can see a full list using `Get-Command -Module ServiceNow`.
35+
The ServiceNow module should be installed from the PowerShell Gallery with `install-module ServiceNow`.
36+
37+
### Creating a new session
4638

47-
### Example - Using Set-ServiceNowAuth
39+
Creating a new session will create a script scoped variable `$ServiceNowSession` which will be used by default in other functions.
4840

41+
Basic authentication with just a credential...
4942
```PowerShell
50-
Set-ServiceNowAuth -url InstanceName.service-now.com -Credentials (Get-Credential)
43+
$params @{
44+
Url = 'instance.service-now.com'
45+
Credential = $userCred
46+
}
47+
New-ServiceNowSession @params
5148
```
5249

53-
The URL should be the instance name portion of the FQDN for your instance. If you browse to `https://yourinstance.service-now.com` the URL required for the module is `yourinstance.service-now.com`.
50+
Oauth authentication with user credential as well as application/client credential. The application/client credential can be found in the System OAuth->Application Registry section of ServiceNow.
51+
```PowerShell
52+
$params @{
53+
Url = 'instance.service-now.com'
54+
Credential = $userCred
55+
ClientCredential = $clientCred
56+
}
57+
New-ServiceNowSession @params
58+
```
5459

55-
### Example - Retrieving an Incident Containing the Word 'PowerShell'
60+
All examples below assume a new session has already been created.
5661

62+
### Getting incidents opened in the last 30 days
5763
```PowerShell
58-
Import-Module ServiceNow
59-
Set-ServiceNowAuth
60-
Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'}
64+
$filter = @('opened_at', '-ge', 'javascript:gs.daysAgoEnd(30)')
65+
Get-ServiceNowRecord -Table incident -Filter $filter
6166
```
6267

63-
### Example - Retrieving an Incident Containing the Word 'PowerShell' While Passing Authentication
68+
### Retrieving an Incident Containing the Word 'PowerShell'
6469

6570
```PowerShell
66-
Import-Module ServiceNow
67-
Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'} -ServiceNowCredential $PSCredential -ServiceNowURL $ServiceNowURL
71+
Get-ServiceNowRecord -Table incident -Filter @('short_description','-like','PowerShell')
6872
```
6973

70-
### Example - Update a Ticket
74+
### Update a Ticket
7175

7276
```PowerShell
73-
$Incident = Get-ServiceNowIncident -Limit 1 -MatchContains @{short_description='PowerShell'}
74-
Update-ServiceNowIncident -SysID $Incident.Sys_ID -Values @{comments='Updated via PowerShell'}
77+
Get-ServiceNowRecord -First 1 -Filter @('short_description','-eq','PowerShell') | Update-ServiceNowIncident -Values @{comments='Updated via PowerShell'}
7578
```
7679

77-
### Example - Creating a Incident with custom table entries
80+
### Creating an Incident with custom table entries
7881

7982
```PowerShell
80-
$IncidentParams = @{Caller = "UserName"
81-
ShortDescription = "New PS Incident"
82-
Description = "This incident was created from Powershell"
83+
$IncidentParams = @{Caller = "UserName"
84+
ShortDescription = "New PS Incident"
85+
Description = "This incident was created from Powershell"
8386
CustomFields = @{u_service = "MyService"
8487
u_incident_type = "Request"}
8588
}
@@ -92,43 +95,16 @@ The module can use the `Connection` parameter in conjunction with the included `
9295

9396
The `Connection` parameter accepts a hashtable object that requires a username, password, and ServiceNowURL.
9497

95-
## Functions
96-
97-
* Add-ServiceNowAttachment
98-
* Get-ServiceNowAttachment
99-
* Get-ServiceNowAttachmentDetail
100-
* Get-ServiceNowChangeRequest
101-
* Get-ServiceNowConfigurationItem
102-
* Get-ServiceNowIncident
103-
* Get-ServiceNowRequest
104-
* Get-ServiceNowRequestItem
105-
* Get-ServiceNowTable
106-
* Get-ServiceNowTableEntry
107-
* Get-ServiceNowUser
108-
* Get-ServiceNowUserGroup
109-
* New-ServiceNowChangeRequest
110-
* New-ServiceNowIncident
111-
* New-ServiceNowQuery
112-
* New-ServiceNowTableEntry
113-
* Remove-ServiceNowAttachment
114-
* Remove-ServiceNowAuth
115-
* Remove-ServiceNowTableEntry
116-
* Set-ServiceNowAuth
117-
* Test-ServiceNowAuthIsSet
118-
* Update-ServiceNowChangeRequest
119-
* Update-ServiceNowIncident
120-
* Update-ServiceNowNumber
121-
* Update-ServiceNowRequestItem
122-
* Update-ServiceNowTableEntry
123-
12498
## Tests
12599

126-
This module comes with [Pester](https://github.com/pester/Pester/) tests for unit testing.
100+
This module comes with limited [Pester](https://github.com/pester/Pester/) tests for unit testing.
127101

128102
## Scope & Contributing
129103

130-
This module has been created as an abstraction layer to suit my immediate requirements. Contributions are gratefully received however, so please feel free to submit a pull request with additional features or amendments.
104+
Contributions are gratefully received, so please feel free to submit a pull request with additional features or amendments.
131105

132-
## Author
106+
## Authors
133107

134-
Author:: Sam Martin
108+
- [Sam Martin](https://github.com/Sam-Martin)
109+
- [Rick Arroues](https://github.com/Rick-2CA)
110+
- [Greg Brownstein](https://github.com/gdbarron)

0 commit comments

Comments
 (0)