├── .github
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── Build.ps1
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── appveyor.yml
├── docs
├── UserGuide.MD
├── functionBuilder.MD
├── functions
│ ├── Get-SNOWApprovalGroup.md
│ ├── Get-SNOWApprover.md
│ ├── Get-SNOWAttachment.md
│ ├── Get-SNOWAuth.md
│ ├── Get-SNOWCMDBCI.md
│ ├── Get-SNOWChangeRequest.md
│ ├── Get-SNOWDepartment.md
│ ├── Get-SNOWIncident.md
│ ├── Get-SNOWLocation.md
│ ├── Get-SNOWObject.md
│ ├── Get-SNOWRITMVariableSet.md
│ ├── Get-SNOWSCCart.md
│ ├── Get-SNOWSCItem.md
│ ├── Get-SNOWSCOrderGuide.md
│ ├── Get-SNOWSCRequest.md
│ ├── Get-SNOWSCRequestedItem.md
│ ├── Get-SNOWSCTask.md
│ ├── Get-SNOWStatistic.md
│ ├── Get-SNOWTask.md
│ ├── Get-SNOWUser.md
│ ├── Get-SNOWUserGroup.md
│ ├── Invoke-SNOWBatch.md
│ ├── Invoke-SNOWRestMethod.md
│ ├── Invoke-SNOWSCCart.md
│ ├── Invoke-SNOWWebRequest.md
│ ├── New-SNOWAttachment.md
│ ├── New-SNOWCMDBCI.md
│ ├── New-SNOWChangeRequest.md
│ ├── New-SNOWDepartment.md
│ ├── New-SNOWImport.md
│ ├── New-SNOWIncident.md
│ ├── New-SNOWLocation.md
│ ├── New-SNOWObject.md
│ ├── New-SNOWSCCartItem.md
│ ├── New-SNOWSCRequest.md
│ ├── New-SNOWSCRequestedItem.md
│ ├── New-SNOWSCTask.md
│ ├── New-SNOWTask.md
│ ├── New-SNOWUser.md
│ ├── New-SNOWUserGroup.md
│ ├── Remove-SNOWAttachment.md
│ ├── Remove-SNOWDepartment.md
│ ├── Remove-SNOWLocation.md
│ ├── Remove-SNOWObject.md
│ ├── Remove-SNOWUserGroup.md
│ ├── Set-SNOWApprovalGroup.md
│ ├── Set-SNOWApprover.md
│ ├── Set-SNOWAuth.md
│ ├── Set-SNOWCMDBCI.md
│ ├── Set-SNOWChangeRequest.md
│ ├── Set-SNOWDepartment.md
│ ├── Set-SNOWIncident.md
│ ├── Set-SNOWLocation.md
│ ├── Set-SNOWObject.md
│ ├── Set-SNOWRITMVariable.md
│ ├── Set-SNOWSCRequest.md
│ ├── Set-SNOWSCRequestedItem.md
│ ├── Set-SNOWSCTask.md
│ ├── Set-SNOWTask.md
│ ├── Set-SNOWUser.md
│ ├── Set-SNOWUserGroup.md
│ └── Set-SNOWUserPhoto.md
└── images
│ ├── ProxyBypass.png
│ └── copy_paste_queries.gif
├── functionBuilder
├── Boilerplate_Table_GET.txt
├── Boilerplate_Table_NEW.txt
├── Boilerplate_Table_REMOVE.txt
├── Boilerplate_Table_SET.txt
└── New-SNOWTableFunction.ps1
├── src
├── PSSnow.psd1
├── PSSnow.psm1
├── Private
│ ├── Assert-SNOWAuth.ps1
│ ├── Confirm-SysID.ps1
│ ├── ConvertTo-BatchRequest.ps1
│ ├── ConvertTo-QueryString.ps1
│ ├── Format-Hashtable.ps1
│ ├── Get-AuthHeader.ps1
│ ├── Import-DefaultParamSet.ps1
│ ├── Invoke-Parallel.ps1
│ ├── Invoke-SNOWTableCREATE.ps1
│ ├── Invoke-SNOWTableDELETE.ps1
│ ├── Invoke-SNOWTableREAD.ps1
│ └── Invoke-SNOWTableUPDATE.ps1
└── Public
│ ├── Get-SNOWAuth.ps1
│ ├── Get-SNOWRITMVariableSet.ps1
│ ├── Invoke-SNOWRestMethod.ps1
│ ├── Invoke-SNOWWebRequest.ps1
│ ├── Set-SNOWAuth.ps1
│ ├── Set-SNOWRITMVariable.ps1
│ ├── attachment
│ ├── Get-SNOWAttachment.ps1
│ ├── New-SNOWAttachment.ps1
│ ├── Remove-SNOWAttachment.ps1
│ └── Set-SNOWUserPhoto.ps1
│ ├── batch
│ └── Invoke-SNOWBatch.ps1
│ ├── import
│ └── New-SNOWImport.ps1
│ ├── sn_sc
│ ├── Get-SNOWSCCart.ps1
│ ├── Invoke-SNOWSCCart.ps1
│ └── New-SNOWSCCartItem.ps1
│ ├── stats
│ └── Get-SNOWStatistic.ps1
│ └── table
│ ├── Get-SNOWApprovalGroup.ps1
│ ├── Get-SNOWApprover.ps1
│ ├── Get-SNOWCMDBCI.ps1
│ ├── Get-SNOWChangeRequest.ps1
│ ├── Get-SNOWDepartment.ps1
│ ├── Get-SNOWIncident.ps1
│ ├── Get-SNOWLocation.ps1
│ ├── Get-SNOWObject.ps1
│ ├── Get-SNOWSCItem.ps1
│ ├── Get-SNOWSCOrderGuide.ps1
│ ├── Get-SNOWSCRequest.ps1
│ ├── Get-SNOWSCRequestedItem.ps1
│ ├── Get-SNOWSCTask.ps1
│ ├── Get-SNOWTask.ps1
│ ├── Get-SNOWUser.ps1
│ ├── Get-SNOWUserGroup.ps1
│ ├── New-SNOWCMDBCI.ps1
│ ├── New-SNOWChangeRequest.ps1
│ ├── New-SNOWDepartment.ps1
│ ├── New-SNOWIncident.ps1
│ ├── New-SNOWLocation.ps1
│ ├── New-SNOWObject.ps1
│ ├── New-SNOWSCRequest.ps1
│ ├── New-SNOWSCRequestedItem.ps1
│ ├── New-SNOWSCTask.ps1
│ ├── New-SNOWTask.ps1
│ ├── New-SNOWUser.ps1
│ ├── New-SNOWUserGroup.ps1
│ ├── Remove-SNOWDepartment.ps1
│ ├── Remove-SNOWLocation.ps1
│ ├── Remove-SNOWObject.ps1
│ ├── Remove-SNOWUserGroup.ps1
│ ├── Set-SNOWApprovalGroup.ps1
│ ├── Set-SNOWApprover.ps1
│ ├── Set-SNOWCMDBCI.ps1
│ ├── Set-SNOWChangeRequest.ps1
│ ├── Set-SNOWDepartment.ps1
│ ├── Set-SNOWIncident.ps1
│ ├── Set-SNOWLocation.ps1
│ ├── Set-SNOWObject.ps1
│ ├── Set-SNOWSCRequest.ps1
│ ├── Set-SNOWSCRequestedItem.ps1
│ ├── Set-SNOWSCTask.ps1
│ ├── Set-SNOWTask.ps1
│ ├── Set-SNOWUser.ps1
│ └── Set-SNOWUserGroup.ps1
└── tests
├── AggregateAPI.Tests.ps1
├── AttachmentAPI.Tests.ps1
├── Authentication.Tests.ps1
├── BatchAPI.Tests.ps1
├── ImportAPI.Tests.ps1
├── MockedResponses
├── Get-SNOWAttachment_RestMethod.xml
├── Get-SNOWAttachment_WebRequest.xml
├── Get-SNOWRITMVariableSet.xml
├── Get-SNOWRITMVariableSet_Number_GetRITM.xml
├── Get-SNOWSCCart_Empty.xml
├── Get-SNOWSCCart_WithItem.xml
├── Invoke-BatchRequest.xml
├── Invoke-RestMethod.xml
├── Invoke-SNOWSCCart.xml
├── Invoke-SNOWSCCart_CheckedOut.xml
├── Invoke-WebRequest_NotPaged.xml
├── Invoke-WebRequest_Paged.xml
├── New-SNOWAttachment.xml
├── New-SNOWImport.xml
├── Set-SNOWAuth_oauth.xml
└── Set-SNOWRITMVariable_ReturnedVariable.xml
├── RITMVariables.Tests.ps1
├── ServiceCatalogAPI.Tests.ps1
└── TableAPI.Tests.ps1
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Import-Module
16 | 2. Set-SNOWAuth -Instance "dev123456" -Credential (get-credential)
17 | 3. Get-SNOWUser -limit 5 -offset 5
18 | 4. See error as per below:
19 | xxxxxxxxxxxxxx
20 |
21 | **Expected behavior**
22 | A clear and concise description of what you expected to happen.
23 |
24 | **Environment (please complete the following information):**
25 | - Module Version: [e.g 0.0.1]
26 | - Powershell Version: [e.g 5.1 or 7.3.3]
27 | - OS: [e.g Windows10, Ubuntu etc]
28 | - Servicenow Version: [e.g. Tokyo]
29 |
30 | **Additional context**
31 | Add any other context about the problem here.
32 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | .VSCodeCounter
--------------------------------------------------------------------------------
/Build.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [switch]
3 | $Test,
4 | [switch]
5 | $Documentation,
6 | [ValidateSet('Major','Minor','Patch')]
7 | [string]
8 | $BumpVersion = "Patch",
9 | [version]
10 | $SpecificVersion
11 | )
12 |
13 | $Scriptpath = $PSScriptRoot
14 | $ModulePath = $Scriptpath + "\src"
15 | $ProjectName = $Scriptpath | Split-Path -leaf
16 | #Import-Module "$ModulePath\$ProjectName.psd1" -Force -ErrorAction Stop
17 |
18 | if($Test.IsPresent){
19 | if($PSVersionTable.PSVersion.ToString() -ge 5.2){
20 | Write-Warning "These Pester tests currently are only written for & functional in 5.1, expect errors in PS Core."
21 | }
22 |
23 | Write-Host "Running PSScriptAnalyzer tests"
24 | $AnalyzerResults = Invoke-ScriptAnalyzer -Path $ModulePath -Recurse -Profile @{Severity = @('Error', 'Warning')} -ReportSummary
25 | if($AnalyzerResults){
26 | $AnalyzerResults
27 | Throw "ScriptAnalyzer found rules with Warning/Error that need to be addressed"
28 | }else{
29 | Write-Host "ScriptAnalyzer checks passed" -f Green
30 | }
31 |
32 | Write-Host "Running Pester tests"
33 | try{
34 | $MinimumVersion = 5.0.0
35 | Import-Module Pester -MinimumVersion $MinimumVersion -ErrorAction Stop
36 | }catch{
37 | Throw "Pester is not installed. Required minimum version: $MinimumVersion"
38 | }
39 |
40 | $PesterResults = Invoke-Pester -PassThru
41 | if($PesterResults.FailedCount -gt 0){
42 | Throw "$($PesterResults.FailedCount) Pester tests failed"
43 | }
44 | }
45 |
46 | if($Documentation.IsPresent){
47 | try{
48 | Import-Module -Name platyPS -ErrorAction Stop
49 | }catch{
50 | Throw "platyPS module is required. Please use 'Install-Module platyPS'"
51 | }
52 |
53 | if(test-path "$Scriptpath\docs\functions"){
54 | Get-ChildItem -Path "docs\functions" -Recurse | Remove-Item -Recurse -Force
55 | }else{
56 | New-Item "$Scriptpath\docs\functions" -ItemType Directory -Force | out-null
57 | }
58 |
59 | # Create docs with platyPS.
60 | $Markdown = ForEach($Command in (Get-Command -Module $ProjectName -CommandType Function)){
61 | $Link = "docs/functions/$($Command.Name).md" #repo relative path
62 | $NewMarkdownSplat = @{
63 | Command = $Command.Name
64 | OutputFolder = "docs/functions/"
65 | Encoding = [System.Text.Encoding]::UTF8
66 | OnlineVersionUrl = $Link
67 | UseFullTypeName = $true
68 | Force = $true
69 | }
70 | New-MarkdownHelp @NewMarkdownSplat
71 | }
72 |
73 |
74 | # Make some minor adjustments to the output, input/output header fix & synatx highlighting
75 | Get-ChildItem -Path "$scriptpath\docs\functions" -Filter "*.md" -Recurse | Foreach-Object {
76 | $DocPath = $_.FullName
77 | $DocTitle = $_.Name.TrimEnd(".md")
78 | $StringDoc = Get-Content -Path $DocPath -Raw
79 |
80 | #Fix input/output
81 | $StringDoc = $StringDoc -replace "(## .*PUTS\r\n\r\n)### ", "`$1"
82 |
83 | #Powershell syntax highlighting
84 | $StringDoc = $StringDoc -replace "(### EXAMPLE \d)\r\n``````", "`$1`r`n``````powershell" | Set-Content `
85 | -Path $DocPath -Encoding utf8 -Force
86 | }
87 | }
88 |
89 | if($PSCmdlet.ParameterSetName -in @('Bump','Specific')){
90 | $ManifestPath = "$ModulePath\$ProjectName.psd1"
91 | $Manifest = Test-ModuleManifest $ManifestPath -ErrorAction Stop
92 | [System.Version]$version = $Manifest.Version
93 |
94 | if($PSCmdlet.ParameterSetName -eq "Bump"){
95 | [String]$NewVersion = switch ($BumpVersion){
96 | "Major" {
97 | New-Object -TypeName System.Version -ArgumentList ($version.Major, 0, 0)
98 | }
99 | "Minor" {
100 | New-Object -TypeName System.Version -ArgumentList ($version.Major, ($version.Minor+1), 0)
101 | }
102 | "Patch" {
103 | New-Object -TypeName System.Version -ArgumentList ($version.Major, $version.Minor, ($version.Build+1))
104 | }
105 | }
106 | }elseif($PSCmdlet.ParameterSetName -eq "Specific"){
107 | [String]$NewVersion = $SpecificVersion
108 | }
109 |
110 | Update-ModuleManifest -Path $ManifestPath -ModuleVersion $NewVersion
111 | }
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | ## [Unreleased]
8 |
9 | ## [1.3.2] - 2024-05-26
10 | ### Fixed
11 | - fixed issued with TimeoutSec on Invoke-SNOWWebRequest in PS 7.3
12 |
13 | ## [1.3.1] - 2024-04-20
14 | ### Fixed
15 | - fixed issued with utf-8 character encoding on update and create table API functions
16 |
17 | ## [1.3.0] - 2024-03-31
18 | ### Added
19 | - -BypassDefaultProxy added to Set-SNOWAuth
20 |
21 | ### Fixed
22 | - Fixed Content-Type errors on table SET commands
23 |
24 | ## [1.2.0] - 2023-08-23
25 | ### Added
26 | - Added Invoke-SNOWWebRequest as a wrapper for Invoke-WebRequest/RestMethod, which handles rate limiting, auth & proxy auth.
27 | - Proxy auth support added to Set-SNOWAuth and all relevant commands
28 | - WebCallTimeoutSeconds added to Set-SNOWAuth
29 |
30 | ## [1.1.0] - 2023-04-06
31 | ### Added
32 | - Invoke-SNOWRestMethod
33 | - Get/New/Remove/Set-SNOWUserGroup
34 | - Get-SNOWSCOrderGuide
35 | - Get-SNOWSCItem
36 | - Get/New/Remove/Set-SNOWLocation
37 | - Get/New/Remove/Set-SNOWDepartment
38 | - Get/New/Set-SNOWCMDBCI
39 | - Get/Set-SNOWApprovalGroup
40 | - Set-SNOWRITMVariable
41 | - Improved error handling on Set-SNOWAuth
42 | - Get-SNOWAuth
43 |
44 | ### Fixed
45 | - Get-SNOWRITMVariableSet removed RITM lookup by LIKE and replaced with =
46 | - Get-SNOWRITMVariableSet parameter sets fixed
47 |
48 | ## [1.0.1] - 2023-03-28
49 | ### Added
50 | - Set-SNOWAuth Aliveness check for developer instances
51 |
52 | ### Removed
53 | - Defunct -Number param from Set/New table commands
54 |
55 | ## [1.0.0] - 2023-03-24
56 | ### Fixed
57 | - Oauth auto refresh
58 |
59 | ## [0.0.4] - 2023-03-22
60 | ### Added
61 | - PsScriptAnalyzer rule suppression for known exceptions
62 | - ServiceCatalog API: New-SNOWSCCartItem
63 | - ServiceCatalog API: Invoke-SNOWSCCart
64 | - ServiceCatalog API: Get-SNOWSCCart
65 |
66 | ### Fixed
67 | - Issue with Set-SNOWUserPhoto posting to a static record
68 | - Get-SNOWAttachment Oauth issue for -PassThru requests
69 |
70 | ## [0.0.3] - 2023-03-21
71 | ### Fixed
72 | - Oauth token auto refresh issue
73 |
74 | ## [0.0.2] - 2023-03-20
75 | ### Added
76 | - Import API support: New-SNOWImport
77 | - Oauth support (auto refreshes token)
78 | - number/sys_id added to Get-SNOWRITMVariableSet output
79 |
80 | ### Changed
81 | - Renamed Get-SNOWRITMVariable to Get-SNOWRITMVariableSet
82 |
83 | ## [0.0.1] - 2023-03-18
84 | ### Added
85 | - Get-SNOWRITMVariable
86 | - New/Get/Set Table functions: *-SNOWApprover, *-SNOWChangeRequest, *-SNOWIncident, *-SNOWSCRequest, *-SNOWSCRequestedItem, *-SNOWSCTask, *-SNOWTask
87 | - Function Builder to auto generate TableAPI functions based on metadata from SNOW
88 | - Attachment API support with Get/New/Remove-SNOWAttachment
89 | - Aggregate API support with Get-SNOWStats
90 | - New-SNOWUserPhoto with batch support
91 | - Batch API support with Invoke-SNOWBatch (Can be used as a wrapper function around supporting commands)
92 | - TABLE API support with Get/New/Set/Remove-SNOWObject (these core functions provide the template for all other table functions)
93 | - TABLE API framework with private functions supporting CRUD operations.
94 |
95 | [Unreleased]: https://github.com/insomniacc/PSSnow/compare/v1.3.2..HEAD
96 | [1.3.2]: https://github.com/insomniacc/PSSnow/compare/v1.3.1..v1.3.2
97 | [1.3.1]: https://github.com/insomniacc/PSSnow/compare/v1.3.0..v1.3.1
98 | [1.3.0]: https://github.com/insomniacc/PSSnow/compare/v1.2.0..v1.3.0
99 | [1.2.0]: https://github.com/insomniacc/PSSnow/compare/v1.1.0..v1.2.0
100 | [1.1.0]: https://github.com/insomniacc/PSSnow/compare/v1.0.1..v1.1.0
101 | [1.0.1]: https://github.com/insomniacc/PSSnow/compare/v1.0.0..v1.0.1
102 | [1.0.0]: https://github.com/insomniacc/PSSnow/compare/v0.0.4..v1.0.0
103 | [0.0.4]: https://github.com/insomniacc/PSSnow/compare/v0.0.3..v0.0.4
104 | [0.0.3]: https://github.com/insomniacc/PSSnow/compare/v0.0.2..v0.0.3
105 | [0.0.2]: https://github.com/insomniacc/PSSnow/releases/tag/v0.0.2
106 | [0.0.1]: https://github.com/insomniacc/PSSnow/releases/tag/v0.0.2
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | #Contributing
2 | ## References & External Documentation
3 | ### ServiceNow
4 | [REST API reference](https://docs.servicenow.com/bundle/tokyo-application-development/page/build/applications/concept/api-rest.html)
5 | ### VSCode
6 | [Better comments](https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments) is used throughout this repo, it is recommended to install this extension.
7 |
8 | ## Authentication
9 | All commands initiating either an `Invoke-WebRequest` or `Invoke-RestMethod` against servicenow must have `Assert-SNOWAuth`.
10 | ## Testing
11 | Please ensure pester tests pass and correct any flagged error/warning rules by script analyzer.
12 | All TableAPI functions have pester tests already, but any new functionality out side the normal framework will also need to be tested separately.
13 |
14 | ## Commits & Versioning
15 | The module is released following [Semantic Versioning](https://semver.org/). E.g Major.Minor.Patch
16 | [KeepAChangelog](https://keepachangelog.com/en/1.0.0/) standard is used for commits & changelog entries.
17 | Also please see [ChangeLogManagement](https://github.com/natescherer/ChangelogManagement).
18 |
19 | ## Pull Requests / Merging
20 | Currently I don't have any formal process in place, until I've ironed out tests, build, ci/cd etc.
21 | If you do want to contribute before that's all setup, I'll be happy to review any requests.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PSSnow
2 | [](https://ci.appveyor.com/project/insomniacc/pssnow/branch/main)
3 | [](https://www.powershellgallery.com/packages/PSSnow/)
4 | 
5 | [](https://github.com/insomniacc/PSSnow/blob/main/LICENSE)
6 |
7 |
8 |
9 |
10 | ## Summary
11 | A powershell module for interacting with the various ServiceNow REST API's.
12 |
13 | This module has a framework built around the Table API allowing it to support any Service-Now instance.
14 | Focusing on the Table API initially for CRUD operations, this module also supports batch, attachment, import, service catalog and aggregate API's with more to come in future.
15 | I've built this in my spare time, if you do find it useful I would greatly appreciate any [feedback](https://github.com/insomniacc/PSSnow/issues/new/choose) or [support](https://www.buymeacoffee.com/insomniacc).
16 |
17 |
18 | A bit more...
19 | This is the first public module I've released so please go easy 😀.
20 | As always, ensure you understand any scripts before you run them and make sure to do your own testing.
21 | If you do find any bugs, it's still early days, so please help me improve and log an issue.
22 |
23 | I've worked for a few large orgs with vastly different implementations of Service-Now, some more out of the box, others heavily modified. Finding a suitable 'one size fits all' module was quite hard and I ended up building from scratch or improving existing modules in each case. Either way it was very time consuming. Some of the gallery modules out there I found either 1. very lacking in functionality or 2. locked behind a paywall. This repo is hopefully my solution to fill the gap.
24 |
25 |
26 | ## Key Features
27 |
28 | - Handles rate limited requests
29 | - Handles OAuth auto token renewal
30 | - Supports using proxies
31 | - Auto paginated calls
32 | - Provides generic 'template' functions to interact with all tables
33 | - Provides table specific functions with auto-complete
34 | - Batching calls is as easy as wrapping your existing code with a scriptblock
35 | - Attachments can be passed through without the need to interact with the filesystem
36 | - Service Catalog requests and incidents can be automated
37 | - Filters/Queries can be copied directly from ServiceNow and used in table GET commands
38 | - Dot walking across tables is possible
39 | - Get the variables for a specified RITM
40 | (values for all fields logged in a request form)
41 |
42 | Currently supports following APIs:
43 | - Table
44 | - Batch
45 | - Import
46 | - Attachment
47 | - Aggregate
48 | - ServiceCatalog
49 |
50 | ## Installation
51 | ```powershell
52 | Install-Module -Name PSSnow -Repository PSGallery -Force
53 | ```
54 | ## Usage
55 | - [User Guide](docs/UserGuide.MD)
56 | - [Function documentation](docs/functions)
57 | - [Function builder](docs/functionBuilder.MD)
58 |
59 | ## Reporting Issues and Feedback
60 | - [File a bug report](https://github.com/insomniacc/PSSnow/issues/new?assignees=&labels=bug&template=bug_report.md)
61 | - [Raise a feature request](https://github.com/insomniacc/PSSnow/issues/new?assignees=&labels=enhancement&template=feature_request.md)
62 | - [Something else](https://github.com/insomniacc/PSSnow/issues/new/choose)
63 |
64 | ## Contributing
65 | - [Contributing](/CONTRIBUTING.md)
66 |
67 | ## Changelog
68 | - [Changelog](/CHANGELOG.md)
69 |
70 | ## Roadmap
71 | - [Milestones](https://github.com/insomniacc/PSSnow/milestones)
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | os: WMF 5
2 |
3 | skip_non_tags: true
4 |
5 | skip_commits:
6 | files:
7 | - README.md
8 | - CHANGELOG.md
9 | message: /updated readme.*|update readme.*s|updated docs.*|updated documentation.*|updated version.*|updated appveyor.*/
10 |
11 | install:
12 | - cinst pester
13 | - ps: Install-PackageProvider -Name NuGet -Force
14 | - ps: Install-Module PsScriptAnalyzer -Force
15 |
16 | build: false
17 |
18 | test_script:
19 | - ps: |
20 | $ErrorActionPreference = 'Stop'
21 |
22 | Write-Host 'Adding PsScriptAnalyzer test'
23 | Add-AppveyorTest -Name 'PsScriptAnalyzer' -Filename 'PsScriptAnalyzer' -Outcome Running
24 | Write-Host 'Performing PSScriptAnalyzer tests'
25 | $stopwatch = [system.diagnostics.stopwatch]::StartNew()
26 | $Results = Invoke-ScriptAnalyzer -Path ".\src" -Recurse -Profile @{Severity = @('Error', 'Warning')}
27 | $stopwatch.Stop()
28 |
29 | $AppveyorTestSplat = @{
30 | Name = 'PsScriptAnalyzer'
31 | Filename = 'PsScriptAnalyzer'
32 | Duration = [int]$stopwatch.elapsed.TotalMilliseconds
33 | }
34 |
35 |
36 | if ($Results) {
37 | Write-Host 'PSScriptAnalyzer returned errors/warnings that need to be addressed.'
38 | $ResultString = $Results | Out-String
39 | Write-Warning $ResultString
40 | Add-AppveyorMessage -Message "PSScriptAnalyzer output contained one or more result(s) with 'Error/Warning' severity. Check the 'Tests' tab of this build for more details." -Category Error
41 | Update-AppveyorTest @AppveyorTestSplat -Outcome Failed -ErrorMessage $ResultString
42 |
43 | throw 'Build failed'
44 | } else {
45 | Write-Host 'PSScriptAnalyzer returned nothing that needs to be addressed.'
46 | Update-AppveyorTest @AppveyorTestSplat -Outcome Passed
47 | }
48 |
49 | Write-Host 'Performing Pester tests'
50 | $res = Invoke-Pester -Path ".\Tests" -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
51 | (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml))
52 | if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed."}
53 | Write-Host 'All tests complete'
--------------------------------------------------------------------------------
/docs/functionBuilder.MD:
--------------------------------------------------------------------------------
1 | # Function Builder
2 | The function builder was designed to help generate **Table API** functions easily.
3 | It can be used for those wishing to generate functions for tables that are not listed in the module at present, custom tables, or to recreate existing functions if they are missing modified or custom properties.
4 | The idea is to input a table name and it will generate the PS function automatically based on a template file in this repo & metadata pulled from ServiceNow.
5 | The script itself is a bit rough and ready in it's current state ([#29](https://github.com/insomniacc/PSSnow/issues/29)), but it works.
6 |
7 |
8 | The legacy manual process
9 |
10 | All Table API functions in this module follow the same framework, as such to create a new one the following manual steps would normally be required:
11 | 1. Duplicate an existing Table API function of the same verb type. Example: Get-SNOWIncident
12 | 2. Rename the file & function name reflective of the new table name
13 | 3. Remove all existing parameters and add new parameters that match the relevant table
14 | 4. Change the table name in the `Begin{}` block
15 | 5. Add the function to the module manifest
16 |
17 | While relatively simple, this process still takes time, working out the properties of the target table, the types, mandatory values, display labels/aliases and so on.
18 |
19 |
20 | ## How-To
21 |
22 | ### Video Demo
23 | [](https://www.youtube.com/watch?v=-KzV9Ao9Hsc)
24 |
25 | ### Steps
26 |
27 | 1. Clone this repo and navigate to `\PSSnow\functionBuilder`
28 | 2. `Import-Module "..\src\PSSnow.psd1" -Force`
29 | 3. `Set-SNOWAuth` with either credentials or OAuth
30 | 4. If you are using a developer instance, ensure its spun up!
31 | 5. Run the command shown below these steps
32 | add `-Force` if you wish to replace an existing function of the same name.
33 | 6. Repeat the above step using the verbs `Set-` and `New-` if required.
34 | Typically `Remove-` is not used as `Remove-SNOWObject` can be used against any returned record.
35 | 7. Your new functions will be generated under the `src\Public\table\` folder and added to the module manifest.
36 | 8. Edit the newly generated .ps1 function files, scan through the parameters and validate.
37 | Remove any parameters that you feel are unnecessary and save.
38 | Add any additional functionality to the begin or process blocks where required.
39 | 9. Run pester tests to ensure everything passes
40 | 10. Re-import the module, set authentication and try the new functions
41 |
42 | ```powershell
43 | .\New-SNOWTableFunction -TableName "sys_user" -FunctionName "Get-SNOWUser" -AddToManifest -Verbose
44 | ```
45 |
46 | ## Notes
47 | ### Parameter Length Validation
48 | > ⚠️ If a value is too long and provided to the ServiceNow Table API during New/Set functions it will be automatically cut without warning.
49 |
50 | Currently parameter length validation is omitted by default.
51 | The reasoning is that this likely varies from instance to instance depending on configuration and cannot be easily accounted for out of the box.
52 | It is therefore available as a switch on the function builder (for individuals generating more customized versions of this module) but not included in the base module functions.
53 |
54 | ### Testing
55 | Existing pester tests should cover any newly added TableAPI functions.
56 | Additional functionality added on top of the function builder generation will need to be accounted for in separate tests.
57 |
--------------------------------------------------------------------------------
/docs/functions/Get-SNOWAuth.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: PSSnow-help.xml
3 | Module Name: PSSnow
4 | online version: docs/functions/Get-SNOWAuth.md
5 | schema: 2.0.0
6 | ---
7 |
8 | # Get-SNOWAuth
9 |
10 | ## SYNOPSIS
11 | Returns the currently set SNOWAuth
12 |
13 | ## SYNTAX
14 |
15 | ```
16 | Get-SNOWAuth
17 | ```
18 |
19 | ## DESCRIPTION
20 | Returns the module scope authentication for PSSnow
21 |
22 | ## EXAMPLES
23 |
24 | ### EXAMPLE 1
25 | ```powershell
26 | Get-SNOWAuth
27 | ```
28 |
29 | ## PARAMETERS
30 |
31 | ## INPUTS
32 |
33 | ## OUTPUTS
34 |
35 | ## NOTES
36 |
37 | ## RELATED LINKS
38 |
39 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWAuth.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWAuth.md)
40 |
41 | [https://docs.servicenow.com/csh?topicname=c_RESTAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_RESTAPI.html&version=latest)
42 |
43 |
44 |
--------------------------------------------------------------------------------
/docs/functions/Get-SNOWRITMVariableSet.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: PSSnow-help.xml
3 | Module Name: PSSnow
4 | online version: docs/functions/Get-SNOWRITMVariableSet.md
5 | schema: 2.0.0
6 | ---
7 |
8 | # Get-SNOWRITMVariableSet
9 |
10 | ## SYNOPSIS
11 | Gets all associated variables for a RITM
12 |
13 | ## SYNTAX
14 |
15 | ### sys_id (Default)
16 | ```
17 | Get-SNOWRITMVariableSet -Sys_Id [-IncludeLabels] [-ProgressAction ]
18 | []
19 | ```
20 |
21 | ### number
22 | ```
23 | Get-SNOWRITMVariableSet -Number [-IncludeLabels] [-ProgressAction ]
24 | []
25 | ```
26 |
27 | ## DESCRIPTION
28 | Returns all the RITM variables and display labels
29 |
30 | ## EXAMPLES
31 |
32 | ### EXAMPLE 1
33 | ```powershell
34 | Get-SNOWRITMVariableSet -number "RITM0010001"
35 | Returns RITM Variables for RITM0010001
36 | ```
37 |
38 | ### EXAMPLE 2
39 | ```powershell
40 | Get-SNOWRITMVariableSet -Sys_id a07e6bd947616110d3e5fa8bd36d4339
41 | Returns RITM Variables for the RITM with a sys_id of a07e6bd947616110d3e5fa8bd36d4339
42 | ```
43 |
44 | ### EXAMPLE 3
45 | ```powershell
46 | Get-SNOWRITMVariableSet -number "RITM0010001" -IncludeLabels
47 | Returns RITM Variables for RITM0010001, adding the display label to the output object
48 | ```
49 |
50 | ### EXAMPLE 4
51 | ```powershell
52 | Get-SNOWSCRequestedItem -Number "RITM0010001" | Get-SNOWRITMVariableSet
53 | Returns RITM Variables for RITM0010001
54 | ```
55 |
56 | ## PARAMETERS
57 |
58 | ### -Number
59 | {{ Fill Number Description }}
60 |
61 | ```yaml
62 | Type: System.String
63 | Parameter Sets: number
64 | Aliases:
65 |
66 | Required: True
67 | Position: Named
68 | Default value: None
69 | Accept pipeline input: True (ByPropertyName)
70 | Accept wildcard characters: False
71 | ```
72 |
73 | ### -Sys_Id
74 | {{ Fill Sys_Id Description }}
75 |
76 | ```yaml
77 | Type: System.String
78 | Parameter Sets: sys_id
79 | Aliases: sysid
80 |
81 | Required: True
82 | Position: Named
83 | Default value: None
84 | Accept pipeline input: True (ByPropertyName)
85 | Accept wildcard characters: False
86 | ```
87 |
88 | ### -IncludeLabels
89 | {{ Fill IncludeLabels Description }}
90 |
91 | ```yaml
92 | Type: System.Management.Automation.SwitchParameter
93 | Parameter Sets: (All)
94 | Aliases:
95 |
96 | Required: False
97 | Position: Named
98 | Default value: False
99 | Accept pipeline input: False
100 | Accept wildcard characters: False
101 | ```
102 |
103 | ### -ProgressAction
104 | {{ Fill ProgressAction Description }}
105 |
106 | ```yaml
107 | Type: System.Management.Automation.ActionPreference
108 | Parameter Sets: (All)
109 | Aliases: proga
110 |
111 | Required: False
112 | Position: Named
113 | Default value: None
114 | Accept pipeline input: False
115 | Accept wildcard characters: False
116 | ```
117 |
118 | ### CommonParameters
119 | 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).
120 |
121 | ## INPUTS
122 |
123 | ## OUTPUTS
124 |
125 | ## NOTES
126 |
127 | ## RELATED LINKS
128 |
129 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWRITMVariableSet.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWRITMVariableSet.md)
130 |
131 |
132 |
--------------------------------------------------------------------------------
/docs/functions/Get-SNOWSCCart.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: PSSnow-help.xml
3 | Module Name: PSSnow
4 | online version: docs/functions/Get-SNOWSCCart.md
5 | schema: 2.0.0
6 | ---
7 |
8 | # Get-SNOWSCCart
9 |
10 | ## SYNOPSIS
11 | Gets the current cart
12 |
13 | ## SYNTAX
14 |
15 | ```
16 | Get-SNOWSCCart [-ProgressAction ] []
17 | ```
18 |
19 | ## DESCRIPTION
20 | returns the current cart properties
21 |
22 | ## EXAMPLES
23 |
24 | ### EXAMPLE 1
25 | ```powershell
26 | Get-SNOWSCCart
27 | returns the cart object, no parameters required.
28 | ```
29 |
30 | ## PARAMETERS
31 |
32 | ### -ProgressAction
33 | {{ Fill ProgressAction Description }}
34 |
35 | ```yaml
36 | Type: System.Management.Automation.ActionPreference
37 | Parameter Sets: (All)
38 | Aliases: proga
39 |
40 | Required: False
41 | Position: Named
42 | Default value: None
43 | Accept pipeline input: False
44 | Accept wildcard characters: False
45 | ```
46 |
47 | ### CommonParameters
48 | 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).
49 |
50 | ## INPUTS
51 |
52 | ## OUTPUTS
53 |
54 | ## NOTES
55 |
56 | ## RELATED LINKS
57 |
58 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCCart.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCCart.md)
59 |
60 | [https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest)
61 |
62 |
63 |
--------------------------------------------------------------------------------
/docs/functions/Invoke-SNOWRestMethod.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: PSSnow-help.xml
3 | Module Name: PSSnow
4 | online version: docs/functions/Invoke-SNOWRestMethod.md
5 | schema: 2.0.0
6 | ---
7 |
8 | # Invoke-SNOWRestMethod
9 |
10 | ## SYNOPSIS
11 | A generic way to make rest calls to servicenow API's \[deprecated\]
12 |
13 | ## SYNTAX
14 |
15 | ```
16 | Invoke-SNOWRestMethod [-Uri] [[-Method] ] [[-Body]