├── .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 | [![Build](https://ci.appveyor.com/api/projects/status/60udsra4fombbq7g/branch/main?svg=true)](https://ci.appveyor.com/project/insomniacc/pssnow/branch/main) 3 | [![PSSnow](https://img.shields.io/powershellgallery/v/PSSnow.svg?style=flat-square&label=Powershell%20Gallery)](https://www.powershellgallery.com/packages/PSSnow/) 4 | ![powershell gallery](https://img.shields.io/powershellgallery/dt/PSSnow) 5 | [![License](https://img.shields.io/badge/license-GPL–3.0-blue.svg)](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 | [![Function Builder Demo](https://img.youtube.com/vi/-KzV9Ao9Hsc/0.jpg)](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] ] [[-Headers] ] 17 | [-ProgressAction ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | A wrapper for Invoke-RestMethod that utilizes authentication set with Set-SNOWAuth \[deprecated\] 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | $Response = Invoke-SNOWRestMethod -uri "api/now/v2/table/sys_user?sysparm_limit=1" 28 | ``` 29 | 30 | ### EXAMPLE 2 31 | ```powershell 32 | $Body = @{first_name="john";last_name="smith"} | ConvertTo-json 33 | $Headers = @{"Content-Type"="Application/Json"} 34 | $Response = Invoke-SNOWRestMethod -uri "api/now/v2/table/sys_user" -Method "POST" -Body $Body -Headers $Headers 35 | ``` 36 | 37 | ## PARAMETERS 38 | 39 | ### -Uri 40 | {{ Fill Uri Description }} 41 | 42 | ```yaml 43 | Type: System.String 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: None 50 | Accept pipeline input: False 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -Method 55 | {{ Fill Method Description }} 56 | 57 | ```yaml 58 | Type: System.String 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: None 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -Body 70 | {{ Fill Body Description }} 71 | 72 | ```yaml 73 | Type: System.Object 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: None 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### -Headers 85 | {{ Fill Headers Description }} 86 | 87 | ```yaml 88 | Type: System.Collections.Hashtable 89 | Parameter Sets: (All) 90 | Aliases: 91 | 92 | Required: False 93 | Position: 4 94 | Default value: None 95 | Accept pipeline input: False 96 | Accept wildcard characters: False 97 | ``` 98 | 99 | ### -ProgressAction 100 | {{ Fill ProgressAction Description }} 101 | 102 | ```yaml 103 | Type: System.Management.Automation.ActionPreference 104 | Parameter Sets: (All) 105 | Aliases: proga 106 | 107 | Required: False 108 | Position: Named 109 | Default value: None 110 | Accept pipeline input: False 111 | Accept wildcard characters: False 112 | ``` 113 | 114 | ### CommonParameters 115 | 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). 116 | 117 | ## INPUTS 118 | 119 | ## OUTPUTS 120 | 121 | ## NOTES 122 | !This function is deprecated and has been left in for backward compatibility. 123 | Please use Invoke-SNOWWebRequest instead. 124 | 125 | ## RELATED LINKS 126 | 127 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Invoke-SNOWRestMethod.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Invoke-SNOWRestMethod.md) 128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/functions/Invoke-SNOWSCCart.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Invoke-SNOWSCCart.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Invoke-SNOWSCCart 9 | 10 | ## SYNOPSIS 11 | Can be used to checkout or empty a cart 12 | 13 | ## SYNTAX 14 | 15 | ### checkout (Default) 16 | ``` 17 | Invoke-SNOWSCCart [-Checkout] [-PassThru] [-ProgressAction ] [-WhatIf] [-Confirm] 18 | [] 19 | ``` 20 | 21 | ### empty 22 | ``` 23 | Invoke-SNOWSCCart [-Sys_id ] [-Empty] [-ProgressAction ] [-WhatIf] [-Confirm] 24 | [] 25 | ``` 26 | 27 | ## DESCRIPTION 28 | either processes a cart or clears the contents depending on paramters 29 | 30 | ## EXAMPLES 31 | 32 | ### EXAMPLE 1 33 | ```powershell 34 | New-SNOWSCCartItem -Sys_ID "e91336da4fff0200086eeed18110c7a3" -Properties @{ 35 | primary_contact = "a8f98bb0eb32010045e1a5115206fe3a" 36 | cost_center = "a581ab703710200044e0bfc8bcbe5de8" 37 | ip_range = "127.0.0.1" 38 | business_purpose = "testing" 39 | } 40 | Invoke-SNOWSCCart -Checkout -PassThru 41 | ``` 42 | 43 | ### EXAMPLE 2 44 | ```powershell 45 | New-SNOWSCCartItem -Sys_ID "e91336da4fff0200086eeed18110c7a3" -Properties @{ 46 | primary_contact = "a8f98bb0eb32010045e1a5115206fe3a" 47 | cost_center = "a581ab703710200044e0bfc8bcbe5de8" 48 | ip_range = "127.0.0.1" 49 | business_purpose = "testing" 50 | } 51 | Invoke-SNOWSCCart -Empty 52 | ``` 53 | 54 | ## PARAMETERS 55 | 56 | ### -Sys_id 57 | {{ Fill Sys_id Description }} 58 | 59 | ```yaml 60 | Type: System.String 61 | Parameter Sets: empty 62 | Aliases: 63 | 64 | Required: False 65 | Position: Named 66 | Default value: None 67 | Accept pipeline input: False 68 | Accept wildcard characters: False 69 | ``` 70 | 71 | ### -Empty 72 | {{ Fill Empty Description }} 73 | 74 | ```yaml 75 | Type: System.Management.Automation.SwitchParameter 76 | Parameter Sets: empty 77 | Aliases: 78 | 79 | Required: False 80 | Position: Named 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ### -Checkout 87 | {{ Fill Checkout Description }} 88 | 89 | ```yaml 90 | Type: System.Management.Automation.SwitchParameter 91 | Parameter Sets: checkout 92 | Aliases: 93 | 94 | Required: False 95 | Position: Named 96 | Default value: False 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -PassThru 102 | {{ Fill PassThru Description }} 103 | 104 | ```yaml 105 | Type: System.Management.Automation.SwitchParameter 106 | Parameter Sets: checkout 107 | Aliases: 108 | 109 | Required: False 110 | Position: Named 111 | Default value: False 112 | Accept pipeline input: False 113 | Accept wildcard characters: False 114 | ``` 115 | 116 | ### -WhatIf 117 | Shows what would happen if the cmdlet runs. 118 | The cmdlet is not run. 119 | 120 | ```yaml 121 | Type: System.Management.Automation.SwitchParameter 122 | Parameter Sets: (All) 123 | Aliases: wi 124 | 125 | Required: False 126 | Position: Named 127 | Default value: None 128 | Accept pipeline input: False 129 | Accept wildcard characters: False 130 | ``` 131 | 132 | ### -Confirm 133 | Prompts you for confirmation before running the cmdlet. 134 | 135 | ```yaml 136 | Type: System.Management.Automation.SwitchParameter 137 | Parameter Sets: (All) 138 | Aliases: cf 139 | 140 | Required: False 141 | Position: Named 142 | Default value: None 143 | Accept pipeline input: False 144 | Accept wildcard characters: False 145 | ``` 146 | 147 | ### -ProgressAction 148 | {{ Fill ProgressAction Description }} 149 | 150 | ```yaml 151 | Type: System.Management.Automation.ActionPreference 152 | Parameter Sets: (All) 153 | Aliases: proga 154 | 155 | Required: False 156 | Position: Named 157 | Default value: None 158 | Accept pipeline input: False 159 | Accept wildcard characters: False 160 | ``` 161 | 162 | ### CommonParameters 163 | 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). 164 | 165 | ## INPUTS 166 | 167 | ## OUTPUTS 168 | 169 | ## NOTES 170 | If one-step checkout, the method checks out (saves) the cart and returns the request number and the request order ID. 171 | If two-step checkout, the method returns the cart order status and all the information required for two-step checkout. 172 | 173 | ## RELATED LINKS 174 | 175 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Invoke-SNOWSCCart.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Invoke-SNOWSCCart.md) 176 | 177 | [https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest) 178 | 179 | 180 | -------------------------------------------------------------------------------- /docs/functions/New-SNOWImport.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/New-SNOWImport.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-SNOWImport 9 | 10 | ## SYNOPSIS 11 | Sends a new record to the import API 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | New-SNOWImport [-Table] [-Properties] [-AsBatchRequest] 17 | [-ProgressAction ] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | The import API can be used to push data into staging tables with transform maps 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | $Movies = import-csv -Path "C:\temp\movies.csv" 28 | $Imports = ForEach($Movie in $Movies){ 29 | $MovieProperties = @{ 30 | u_title = $Movie."Movie Title" 31 | u_director = $Movie.Director 32 | u_actor = $Movie."Lead Actor" 33 | u_genre = $Movie.Genre 34 | } 35 | New-SNOWImport -table "u_moviesimport" -properties $MovieProperties 36 | } 37 | $Imports.result | Group-Object status | Select Count,Name 38 | ``` 39 | 40 | ## PARAMETERS 41 | 42 | ### -Table 43 | {{ Fill Table Description }} 44 | 45 | ```yaml 46 | Type: System.String 47 | Parameter Sets: (All) 48 | Aliases: 49 | 50 | Required: True 51 | Position: 1 52 | Default value: None 53 | Accept pipeline input: False 54 | Accept wildcard characters: False 55 | ``` 56 | 57 | ### -Properties 58 | {{ Fill Properties Description }} 59 | 60 | ```yaml 61 | Type: System.Collections.Hashtable 62 | Parameter Sets: (All) 63 | Aliases: 64 | 65 | Required: True 66 | Position: 2 67 | Default value: None 68 | Accept pipeline input: True (ByValue) 69 | Accept wildcard characters: False 70 | ``` 71 | 72 | ### -AsBatchRequest 73 | {{ Fill AsBatchRequest Description }} 74 | 75 | ```yaml 76 | Type: System.Management.Automation.SwitchParameter 77 | Parameter Sets: (All) 78 | Aliases: 79 | 80 | Required: False 81 | Position: Named 82 | Default value: False 83 | Accept pipeline input: False 84 | Accept wildcard characters: False 85 | ``` 86 | 87 | ### -WhatIf 88 | Shows what would happen if the cmdlet runs. 89 | The cmdlet is not run. 90 | 91 | ```yaml 92 | Type: System.Management.Automation.SwitchParameter 93 | Parameter Sets: (All) 94 | Aliases: wi 95 | 96 | Required: False 97 | Position: Named 98 | Default value: None 99 | Accept pipeline input: False 100 | Accept wildcard characters: False 101 | ``` 102 | 103 | ### -Confirm 104 | Prompts you for confirmation before running the cmdlet. 105 | 106 | ```yaml 107 | Type: System.Management.Automation.SwitchParameter 108 | Parameter Sets: (All) 109 | Aliases: cf 110 | 111 | Required: False 112 | Position: Named 113 | Default value: None 114 | Accept pipeline input: False 115 | Accept wildcard characters: False 116 | ``` 117 | 118 | ### -ProgressAction 119 | {{ Fill ProgressAction Description }} 120 | 121 | ```yaml 122 | Type: System.Management.Automation.ActionPreference 123 | Parameter Sets: (All) 124 | Aliases: proga 125 | 126 | Required: False 127 | Position: Named 128 | Default value: None 129 | Accept pipeline input: False 130 | Accept wildcard characters: False 131 | ``` 132 | 133 | ### CommonParameters 134 | 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). 135 | 136 | ## INPUTS 137 | 138 | ## OUTPUTS 139 | 140 | ## NOTES 141 | 142 | ## RELATED LINKS 143 | 144 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWImport.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWImport.md) 145 | 146 | [https://docs.servicenow.com/csh?topicname=c_ImportSetAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_ImportSetAPI.html&version=latest) 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/functions/New-SNOWObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/New-SNOWObject.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-SNOWObject 9 | 10 | ## SYNOPSIS 11 | Creates a new servicenow table record 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | New-SNOWObject [-Table] [[-Properties] ] [-InputDisplayValue] [-PassThru] [-AsBatchRequest] 17 | [-ProgressAction ] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Creates a record in the specified table 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | $Properties = @{ 28 | user_name = "bruce.wayne" 29 | title = "Director" 30 | first_name = "Bruce" 31 | last_name = "Wayne" 32 | department = "Finance" 33 | email = "Bruce@WayneIndustries.com" 34 | } 35 | New-SNOWObject -Table 'sys_user' -Properties $Properties -PassThru 36 | Creates a new user called bruce wayne in the sys_user table 37 | ``` 38 | 39 | ## PARAMETERS 40 | 41 | ### -Table 42 | {{ Fill Table Description }} 43 | 44 | ```yaml 45 | Type: System.String 46 | Parameter Sets: (All) 47 | Aliases: 48 | 49 | Required: True 50 | Position: 1 51 | Default value: None 52 | Accept pipeline input: False 53 | Accept wildcard characters: False 54 | ``` 55 | 56 | ### -Properties 57 | Keys must exactly match the names in the snow table. 58 | Not the display values in the web front end. 59 | Case sensitive. 60 | 61 | ```yaml 62 | Type: System.Collections.Hashtable 63 | Parameter Sets: (All) 64 | Aliases: 65 | 66 | Required: False 67 | Position: 2 68 | Default value: None 69 | Accept pipeline input: False 70 | Accept wildcard characters: False 71 | ``` 72 | 73 | ### -InputDisplayValue 74 | This flag is required when setting encrypted fields (e.g user_password) 75 | 76 | ```yaml 77 | Type: System.Management.Automation.SwitchParameter 78 | Parameter Sets: (All) 79 | Aliases: 80 | 81 | Required: False 82 | Position: Named 83 | Default value: False 84 | Accept pipeline input: False 85 | Accept wildcard characters: False 86 | ``` 87 | 88 | ### -PassThru 89 | {{ Fill PassThru 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 | ### -AsBatchRequest 104 | {{ Fill AsBatchRequest Description }} 105 | 106 | ```yaml 107 | Type: System.Management.Automation.SwitchParameter 108 | Parameter Sets: (All) 109 | Aliases: 110 | 111 | Required: False 112 | Position: Named 113 | Default value: False 114 | Accept pipeline input: False 115 | Accept wildcard characters: False 116 | ``` 117 | 118 | ### -WhatIf 119 | Shows what would happen if the cmdlet runs. 120 | The cmdlet is not run. 121 | 122 | ```yaml 123 | Type: System.Management.Automation.SwitchParameter 124 | Parameter Sets: (All) 125 | Aliases: wi 126 | 127 | Required: False 128 | Position: Named 129 | Default value: None 130 | Accept pipeline input: False 131 | Accept wildcard characters: False 132 | ``` 133 | 134 | ### -Confirm 135 | Prompts you for confirmation before running the cmdlet. 136 | 137 | ```yaml 138 | Type: System.Management.Automation.SwitchParameter 139 | Parameter Sets: (All) 140 | Aliases: cf 141 | 142 | Required: False 143 | Position: Named 144 | Default value: None 145 | Accept pipeline input: False 146 | Accept wildcard characters: False 147 | ``` 148 | 149 | ### -ProgressAction 150 | {{ Fill ProgressAction Description }} 151 | 152 | ```yaml 153 | Type: System.Management.Automation.ActionPreference 154 | Parameter Sets: (All) 155 | Aliases: proga 156 | 157 | Required: False 158 | Position: Named 159 | Default value: None 160 | Accept pipeline input: False 161 | Accept wildcard characters: False 162 | ``` 163 | 164 | ### CommonParameters 165 | 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). 166 | 167 | ## INPUTS 168 | 169 | ## OUTPUTS 170 | 171 | PSCustomObject. The full table record (requires -PassThru). 172 | ## NOTES 173 | 174 | ## RELATED LINKS 175 | 176 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWObject.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWObject.md) 177 | 178 | [https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest) 179 | 180 | 181 | -------------------------------------------------------------------------------- /docs/functions/Remove-SNOWAttachment.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Remove-SNOWAttachment.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-SNOWAttachment 9 | 10 | ## SYNOPSIS 11 | Removes attachments from servicenow. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-SNOWAttachment [-Sys_ID] [[-file_name] ] [-ProgressAction ] [-WhatIf] 17 | [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Deletes an attachment from servicenow. 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | Remove-SNOWAttachment -Sys_ID a73f6d2447292110d3e5fa8bd36d4304 28 | Removes a single attachment by sys_id 29 | ``` 30 | 31 | ### EXAMPLE 2 32 | ```powershell 33 | Get-SNOWUser -user_name "bruce.wayne" | Get-SNOWAttachment | Remove-SNOWAttachment -Verbose 34 | Removes all attachments on the associated parent object 35 | ``` 36 | 37 | ## PARAMETERS 38 | 39 | ### -Sys_ID 40 | The SysID of the attachment record to be deleted 41 | 42 | ```yaml 43 | Type: System.String 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: None 50 | Accept pipeline input: True (ByPropertyName) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -file_name 55 | {{ Fill file_name Description }} 56 | 57 | ```yaml 58 | Type: System.String 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -WhatIf 70 | Shows what would happen if the cmdlet runs. 71 | The cmdlet is not run. 72 | 73 | ```yaml 74 | Type: System.Management.Automation.SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: wi 77 | 78 | Required: False 79 | Position: Named 80 | Default value: None 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ### -Confirm 86 | Prompts you for confirmation before running the cmdlet. 87 | 88 | ```yaml 89 | Type: System.Management.Automation.SwitchParameter 90 | Parameter Sets: (All) 91 | Aliases: cf 92 | 93 | Required: False 94 | Position: Named 95 | Default value: None 96 | Accept pipeline input: False 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### -ProgressAction 101 | {{ Fill ProgressAction Description }} 102 | 103 | ```yaml 104 | Type: System.Management.Automation.ActionPreference 105 | Parameter Sets: (All) 106 | Aliases: proga 107 | 108 | Required: False 109 | Position: Named 110 | Default value: None 111 | Accept pipeline input: False 112 | Accept wildcard characters: False 113 | ``` 114 | 115 | ### CommonParameters 116 | 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). 117 | 118 | ## INPUTS 119 | 120 | ## OUTPUTS 121 | 122 | ## NOTES 123 | 124 | ## RELATED LINKS 125 | 126 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWAttachment.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWAttachment.md) 127 | 128 | [https://docs.servicenow.com/csh?topicname=c_AttachmentAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_AttachmentAPI.html&version=latest) 129 | 130 | 131 | -------------------------------------------------------------------------------- /docs/functions/Remove-SNOWDepartment.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Remove-SNOWDepartment.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-SNOWDepartment 9 | 10 | ## SYNOPSIS 11 | Removes a cmn_department record in SNOW 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-SNOWDepartment [-ProgressAction ] [-WhatIf] [-Confirm] -Sys_ID 17 | [-RestrictDomain] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Removes a record from the cmn_department table 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | " 28 | Removes a specific record in the table cmn_department 29 | ``` 30 | 31 | ## PARAMETERS 32 | 33 | ### -WhatIf 34 | Shows what would happen if the cmdlet runs. 35 | The cmdlet is not run. 36 | 37 | ```yaml 38 | Type: System.Management.Automation.SwitchParameter 39 | Parameter Sets: (All) 40 | Aliases: wi 41 | 42 | Required: False 43 | Position: Named 44 | Default value: None 45 | Accept pipeline input: False 46 | Accept wildcard characters: False 47 | ``` 48 | 49 | ### -Confirm 50 | Prompts you for confirmation before running the cmdlet. 51 | 52 | ```yaml 53 | Type: System.Management.Automation.SwitchParameter 54 | Parameter Sets: (All) 55 | Aliases: cf 56 | 57 | Required: False 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### -ProgressAction 65 | {{ Fill ProgressAction Description }} 66 | 67 | ```yaml 68 | Type: System.Management.Automation.ActionPreference 69 | Parameter Sets: (All) 70 | Aliases: proga 71 | 72 | Required: False 73 | Position: Named 74 | Default value: None 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### -RestrictDomain 80 | {{ Fill RestrictDomain Description }} 81 | 82 | ```yaml 83 | Type: System.Management.Automation.SwitchParameter 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: False 88 | Position: Named 89 | Default value: None 90 | Accept pipeline input: False 91 | Accept wildcard characters: False 92 | ``` 93 | 94 | ### -Sys_ID 95 | {{ Fill Sys_ID Description }} 96 | 97 | ```yaml 98 | Type: System.String 99 | Parameter Sets: (All) 100 | Aliases: 101 | 102 | Required: True 103 | Position: Named 104 | Default value: None 105 | Accept pipeline input: True (ByPropertyName) 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | 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). 111 | 112 | ## INPUTS 113 | 114 | ## OUTPUTS 115 | 116 | PSCustomObject. The full table record/s. 117 | ## NOTES 118 | Uses Remove-SNOWObject as a template function. 119 | 120 | ## RELATED LINKS 121 | 122 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWDepartment.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWDepartment.md) 123 | 124 | [https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest) 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/functions/Remove-SNOWLocation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Remove-SNOWLocation.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-SNOWLocation 9 | 10 | ## SYNOPSIS 11 | Removes a cmn_location record in SNOW 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-SNOWLocation [-ProgressAction ] [-WhatIf] [-Confirm] -Sys_ID 17 | [-RestrictDomain] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Removes a record from the cmn_location table 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | " 28 | Removes a specific record in the table cmn_location 29 | ``` 30 | 31 | ## PARAMETERS 32 | 33 | ### -WhatIf 34 | Shows what would happen if the cmdlet runs. 35 | The cmdlet is not run. 36 | 37 | ```yaml 38 | Type: System.Management.Automation.SwitchParameter 39 | Parameter Sets: (All) 40 | Aliases: wi 41 | 42 | Required: False 43 | Position: Named 44 | Default value: None 45 | Accept pipeline input: False 46 | Accept wildcard characters: False 47 | ``` 48 | 49 | ### -Confirm 50 | Prompts you for confirmation before running the cmdlet. 51 | 52 | ```yaml 53 | Type: System.Management.Automation.SwitchParameter 54 | Parameter Sets: (All) 55 | Aliases: cf 56 | 57 | Required: False 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### -ProgressAction 65 | {{ Fill ProgressAction Description }} 66 | 67 | ```yaml 68 | Type: System.Management.Automation.ActionPreference 69 | Parameter Sets: (All) 70 | Aliases: proga 71 | 72 | Required: False 73 | Position: Named 74 | Default value: None 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### -RestrictDomain 80 | {{ Fill RestrictDomain Description }} 81 | 82 | ```yaml 83 | Type: System.Management.Automation.SwitchParameter 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: False 88 | Position: Named 89 | Default value: None 90 | Accept pipeline input: False 91 | Accept wildcard characters: False 92 | ``` 93 | 94 | ### -Sys_ID 95 | {{ Fill Sys_ID Description }} 96 | 97 | ```yaml 98 | Type: System.String 99 | Parameter Sets: (All) 100 | Aliases: 101 | 102 | Required: True 103 | Position: Named 104 | Default value: None 105 | Accept pipeline input: True (ByPropertyName) 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | 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). 111 | 112 | ## INPUTS 113 | 114 | ## OUTPUTS 115 | 116 | PSCustomObject. The full table record/s. 117 | ## NOTES 118 | Uses Remove-SNOWObject as a template function. 119 | 120 | ## RELATED LINKS 121 | 122 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWLocation.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWLocation.md) 123 | 124 | [https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest) 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/functions/Remove-SNOWObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Remove-SNOWObject.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-SNOWObject 9 | 10 | ## SYNOPSIS 11 | Removes a new servicenow record in the specified table 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-SNOWObject [-Sys_ID] [-Table] [-RestrictDomain] [-ProgressAction ] 17 | [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Removes a new servicenow record in the specified table 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | Remove-SNOWObject -table "sys_user" -sys_id "02826bf03710200044e0bfc8bcbe5d3f" -confirm:$false 28 | Removes the specified user with the matching sys_id from the sys_user table and bypasses confirmation 29 | ``` 30 | 31 | ### EXAMPLE 2 32 | ```powershell 33 | Get-SNOWUser -user_name 'bruce.wayne9' -limit 1 | Remove-SNOWObject -table 'sys_user' 34 | Removes the specified user with the matching sys_id from the sys_user table, after prompt confirmation 35 | ``` 36 | 37 | ## PARAMETERS 38 | 39 | ### -Sys_ID 40 | {{ Fill Sys_ID Description }} 41 | 42 | ```yaml 43 | Type: System.String 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: None 50 | Accept pipeline input: True (ByPropertyName) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -Table 55 | {{ Fill Table Description }} 56 | 57 | ```yaml 58 | Type: System.String 59 | Parameter Sets: (All) 60 | Aliases: sys_class_name 61 | 62 | Required: True 63 | Position: 2 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -RestrictDomain 70 | {{ Fill RestrictDomain Description }} 71 | 72 | ```yaml 73 | Type: System.Management.Automation.SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: Named 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### -WhatIf 85 | Shows what would happen if the cmdlet runs. 86 | The cmdlet is not run. 87 | 88 | ```yaml 89 | Type: System.Management.Automation.SwitchParameter 90 | Parameter Sets: (All) 91 | Aliases: wi 92 | 93 | Required: False 94 | Position: Named 95 | Default value: None 96 | Accept pipeline input: False 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### -Confirm 101 | Prompts you for confirmation before running the cmdlet. 102 | 103 | ```yaml 104 | Type: System.Management.Automation.SwitchParameter 105 | Parameter Sets: (All) 106 | Aliases: cf 107 | 108 | Required: False 109 | Position: Named 110 | Default value: None 111 | Accept pipeline input: False 112 | Accept wildcard characters: False 113 | ``` 114 | 115 | ### -ProgressAction 116 | {{ Fill ProgressAction Description }} 117 | 118 | ```yaml 119 | Type: System.Management.Automation.ActionPreference 120 | Parameter Sets: (All) 121 | Aliases: proga 122 | 123 | Required: False 124 | Position: Named 125 | Default value: None 126 | Accept pipeline input: False 127 | Accept wildcard characters: False 128 | ``` 129 | 130 | ### CommonParameters 131 | 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). 132 | 133 | ## INPUTS 134 | 135 | ## OUTPUTS 136 | 137 | ## NOTES 138 | 139 | ## RELATED LINKS 140 | 141 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWObject.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWObject.md) 142 | 143 | [https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest) 144 | 145 | 146 | -------------------------------------------------------------------------------- /docs/functions/Remove-SNOWUserGroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Remove-SNOWUserGroup.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-SNOWUserGroup 9 | 10 | ## SYNOPSIS 11 | Removes a sys_user_group record in SNOW 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Remove-SNOWUserGroup [-ProgressAction ] [-WhatIf] [-Confirm] -Sys_ID 17 | [-RestrictDomain] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Removes a record from the sys_user_group table 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | " 28 | Removes a specific record in the table sys_user_group 29 | ``` 30 | 31 | ## PARAMETERS 32 | 33 | ### -WhatIf 34 | Shows what would happen if the cmdlet runs. 35 | The cmdlet is not run. 36 | 37 | ```yaml 38 | Type: System.Management.Automation.SwitchParameter 39 | Parameter Sets: (All) 40 | Aliases: wi 41 | 42 | Required: False 43 | Position: Named 44 | Default value: None 45 | Accept pipeline input: False 46 | Accept wildcard characters: False 47 | ``` 48 | 49 | ### -Confirm 50 | Prompts you for confirmation before running the cmdlet. 51 | 52 | ```yaml 53 | Type: System.Management.Automation.SwitchParameter 54 | Parameter Sets: (All) 55 | Aliases: cf 56 | 57 | Required: False 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### -ProgressAction 65 | {{ Fill ProgressAction Description }} 66 | 67 | ```yaml 68 | Type: System.Management.Automation.ActionPreference 69 | Parameter Sets: (All) 70 | Aliases: proga 71 | 72 | Required: False 73 | Position: Named 74 | Default value: None 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### -RestrictDomain 80 | {{ Fill RestrictDomain Description }} 81 | 82 | ```yaml 83 | Type: System.Management.Automation.SwitchParameter 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: False 88 | Position: Named 89 | Default value: None 90 | Accept pipeline input: False 91 | Accept wildcard characters: False 92 | ``` 93 | 94 | ### -Sys_ID 95 | {{ Fill Sys_ID Description }} 96 | 97 | ```yaml 98 | Type: System.String 99 | Parameter Sets: (All) 100 | Aliases: 101 | 102 | Required: True 103 | Position: Named 104 | Default value: None 105 | Accept pipeline input: True (ByPropertyName) 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | 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). 111 | 112 | ## INPUTS 113 | 114 | ## OUTPUTS 115 | 116 | PSCustomObject. The full table record/s. 117 | ## NOTES 118 | Uses Remove-SNOWObject as a template function. 119 | 120 | ## RELATED LINKS 121 | 122 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWUserGroup.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWUserGroup.md) 123 | 124 | [https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest) 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/functions/Set-SNOWObject.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Set-SNOWObject.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-SNOWObject 9 | 10 | ## SYNOPSIS 11 | Updates a new servicenow record 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Set-SNOWObject [-Table] [-Sys_ID] [[-Properties] ] [-InputDisplayValue] 17 | [-PassThru] [-AsBatchRequest] [-ProgressAction ] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Updates a record in the specified table 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | Get-SNOWObject -table "sys_user" -query "user_name=bruce.wayne^active=true" | Set-SNOWObject -table "sys_user" -middle_name "Thomas" 28 | Updates the middle_name of the user record bruce.wayne in the sys_user table 29 | ``` 30 | 31 | ### EXAMPLE 2 32 | ```powershell 33 | Set-SNOWObject -table "sys_user" -sys_id '02826bf03710200044e0bfc8bcbe5d3f' -properties @{middle_name="Thomas"} 34 | Updates the middle_name of the user record bruce.wayne in the sys_user table 35 | ``` 36 | 37 | ## PARAMETERS 38 | 39 | ### -Table 40 | {{ Fill Table Description }} 41 | 42 | ```yaml 43 | Type: System.String 44 | Parameter Sets: (All) 45 | Aliases: sys_class_name 46 | 47 | Required: True 48 | Position: 1 49 | Default value: None 50 | Accept pipeline input: True (ByPropertyName) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -Sys_ID 55 | {{ Fill Sys_ID Description }} 56 | 57 | ```yaml 58 | Type: System.String 59 | Parameter Sets: (All) 60 | Aliases: SysID 61 | 62 | Required: True 63 | Position: 2 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -Properties 70 | {{ Fill Properties Description }} 71 | 72 | ```yaml 73 | Type: System.Collections.Hashtable 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: None 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### -InputDisplayValue 85 | {{ Fill InputDisplayValue Description }} 86 | 87 | ```yaml 88 | Type: System.Management.Automation.SwitchParameter 89 | Parameter Sets: (All) 90 | Aliases: 91 | 92 | Required: False 93 | Position: Named 94 | Default value: False 95 | Accept pipeline input: False 96 | Accept wildcard characters: False 97 | ``` 98 | 99 | ### -PassThru 100 | {{ Fill PassThru Description }} 101 | 102 | ```yaml 103 | Type: System.Management.Automation.SwitchParameter 104 | Parameter Sets: (All) 105 | Aliases: 106 | 107 | Required: False 108 | Position: Named 109 | Default value: False 110 | Accept pipeline input: False 111 | Accept wildcard characters: False 112 | ``` 113 | 114 | ### -AsBatchRequest 115 | {{ Fill AsBatchRequest Description }} 116 | 117 | ```yaml 118 | Type: System.Management.Automation.SwitchParameter 119 | Parameter Sets: (All) 120 | Aliases: 121 | 122 | Required: False 123 | Position: Named 124 | Default value: False 125 | Accept pipeline input: False 126 | Accept wildcard characters: False 127 | ``` 128 | 129 | ### -WhatIf 130 | Shows what would happen if the cmdlet runs. 131 | The cmdlet is not run. 132 | 133 | ```yaml 134 | Type: System.Management.Automation.SwitchParameter 135 | Parameter Sets: (All) 136 | Aliases: wi 137 | 138 | Required: False 139 | Position: Named 140 | Default value: None 141 | Accept pipeline input: False 142 | Accept wildcard characters: False 143 | ``` 144 | 145 | ### -Confirm 146 | Prompts you for confirmation before running the cmdlet. 147 | 148 | ```yaml 149 | Type: System.Management.Automation.SwitchParameter 150 | Parameter Sets: (All) 151 | Aliases: cf 152 | 153 | Required: False 154 | Position: Named 155 | Default value: None 156 | Accept pipeline input: False 157 | Accept wildcard characters: False 158 | ``` 159 | 160 | ### -ProgressAction 161 | {{ Fill ProgressAction Description }} 162 | 163 | ```yaml 164 | Type: System.Management.Automation.ActionPreference 165 | Parameter Sets: (All) 166 | Aliases: proga 167 | 168 | Required: False 169 | Position: Named 170 | Default value: None 171 | Accept pipeline input: False 172 | Accept wildcard characters: False 173 | ``` 174 | 175 | ### CommonParameters 176 | 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). 177 | 178 | ## INPUTS 179 | 180 | ## OUTPUTS 181 | 182 | PSCustomObject. The full table record (requires -PassThru). 183 | ## NOTES 184 | 185 | ## RELATED LINKS 186 | 187 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWObject.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWObject.md) 188 | 189 | [https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest) 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/functions/Set-SNOWRITMVariable.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Set-SNOWRITMVariable.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-SNOWRITMVariable 9 | 10 | ## SYNOPSIS 11 | Set the value of a variable associated with a RITM 12 | 13 | ## SYNTAX 14 | 15 | ### sys_id (Default) 16 | ``` 17 | Set-SNOWRITMVariable -Sys_Id -Name -Value [-ProgressAction ] 18 | [-WhatIf] [-Confirm] [] 19 | ``` 20 | 21 | ### number 22 | ``` 23 | Set-SNOWRITMVariable -Number -Name -Value [-ProgressAction ] 24 | [-WhatIf] [-Confirm] [] 25 | ``` 26 | 27 | ## DESCRIPTION 28 | Updates the value of a variable in the sc_item_option table 29 | 30 | ## EXAMPLES 31 | 32 | ### EXAMPLE 1 33 | ```powershell 34 | Set-SNOWRITMVariable -Sys_id "a07e6bd947616110d3e5fa8bd36d4339" -Name "business_purpose" -Value "Hello World" 35 | Sets the value of business_purpose on a RITM with the sys_id of 'a07e6bd947616110d3e5fa8bd36d4339' to 'Hello World' 36 | ``` 37 | 38 | ### EXAMPLE 2 39 | ```powershell 40 | Set-SNOWRITMVariable -Number "RITM0010001" -Name "business_purpose" -Value "Hello World" 41 | Sets the value of business_purpose on RITM00100001 to 'Hello World' 42 | ``` 43 | 44 | ### EXAMPLE 3 45 | ```powershell 46 | Get-SNOWSCRequestedItem -number "RITM00100001" | Set-SNOWRITMVariable -Name "business_purpose" -Value "Hello World" 47 | Sets the value of business_purpose on RITM00100001 to 'Hello World' 48 | ``` 49 | 50 | ## PARAMETERS 51 | 52 | ### -Sys_Id 53 | {{ Fill Sys_Id Description }} 54 | 55 | ```yaml 56 | Type: System.String 57 | Parameter Sets: sys_id 58 | Aliases: sysid 59 | 60 | Required: True 61 | Position: Named 62 | Default value: None 63 | Accept pipeline input: True (ByPropertyName) 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -Number 68 | {{ Fill Number Description }} 69 | 70 | ```yaml 71 | Type: System.String 72 | Parameter Sets: number 73 | Aliases: 74 | 75 | Required: True 76 | Position: Named 77 | Default value: None 78 | Accept pipeline input: True (ByPropertyName) 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ### -Name 83 | {{ Fill Name Description }} 84 | 85 | ```yaml 86 | Type: System.String 87 | Parameter Sets: (All) 88 | Aliases: 89 | 90 | Required: True 91 | Position: Named 92 | Default value: None 93 | Accept pipeline input: False 94 | Accept wildcard characters: False 95 | ``` 96 | 97 | ### -Value 98 | {{ Fill Value Description }} 99 | 100 | ```yaml 101 | Type: System.String 102 | Parameter Sets: (All) 103 | Aliases: 104 | 105 | Required: True 106 | Position: Named 107 | Default value: None 108 | Accept pipeline input: False 109 | Accept wildcard characters: False 110 | ``` 111 | 112 | ### -WhatIf 113 | Shows what would happen if the cmdlet runs. 114 | The cmdlet is not run. 115 | 116 | ```yaml 117 | Type: System.Management.Automation.SwitchParameter 118 | Parameter Sets: (All) 119 | Aliases: wi 120 | 121 | Required: False 122 | Position: Named 123 | Default value: None 124 | Accept pipeline input: False 125 | Accept wildcard characters: False 126 | ``` 127 | 128 | ### -Confirm 129 | Prompts you for confirmation before running the cmdlet. 130 | 131 | ```yaml 132 | Type: System.Management.Automation.SwitchParameter 133 | Parameter Sets: (All) 134 | Aliases: cf 135 | 136 | Required: False 137 | Position: Named 138 | Default value: None 139 | Accept pipeline input: False 140 | Accept wildcard characters: False 141 | ``` 142 | 143 | ### -ProgressAction 144 | {{ Fill ProgressAction Description }} 145 | 146 | ```yaml 147 | Type: System.Management.Automation.ActionPreference 148 | Parameter Sets: (All) 149 | Aliases: proga 150 | 151 | Required: False 152 | Position: Named 153 | Default value: None 154 | Accept pipeline input: False 155 | Accept wildcard characters: False 156 | ``` 157 | 158 | ### CommonParameters 159 | 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). 160 | 161 | ## INPUTS 162 | 163 | ## OUTPUTS 164 | 165 | ## NOTES 166 | 167 | ## RELATED LINKS 168 | 169 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWRITMVariable.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWRITMVariable.md) 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/functions/Set-SNOWUserPhoto.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSSnow-help.xml 3 | Module Name: PSSnow 4 | online version: docs/functions/Set-SNOWUserPhoto.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-SNOWUserPhoto 9 | 10 | ## SYNOPSIS 11 | Attaches a picture to a user record and updates the photo property 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Set-SNOWUserPhoto -Filepath -Sys_ID [-PassThru] [-AsBatchRequest] 17 | [-ProgressAction ] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | This function uses the Attachment API to upload a photo to a user record as a hidden attachment 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ```powershell 27 | $User | Set-SNOWUserPhoto -filepath "C:\Temp\Bruce.jpg" 28 | Updates a user photo 29 | ``` 30 | 31 | ## PARAMETERS 32 | 33 | ### -Filepath 34 | {{ Fill Filepath Description }} 35 | 36 | ```yaml 37 | Type: System.IO.FileInfo 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: True 42 | Position: Named 43 | Default value: None 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -Sys_ID 49 | The sys_id of the user record in the sys_user table 50 | 51 | ```yaml 52 | Type: System.String 53 | Parameter Sets: (All) 54 | Aliases: SysID 55 | 56 | Required: True 57 | Position: Named 58 | Default value: None 59 | Accept pipeline input: True (ByPropertyName) 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### -PassThru 64 | {{ Fill PassThru Description }} 65 | 66 | ```yaml 67 | Type: System.Management.Automation.SwitchParameter 68 | Parameter Sets: (All) 69 | Aliases: 70 | 71 | Required: False 72 | Position: Named 73 | Default value: False 74 | Accept pipeline input: False 75 | Accept wildcard characters: False 76 | ``` 77 | 78 | ### -AsBatchRequest 79 | {{ Fill AsBatchRequest Description }} 80 | 81 | ```yaml 82 | Type: System.Management.Automation.SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: Named 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ### -WhatIf 94 | Shows what would happen if the cmdlet runs. 95 | The cmdlet is not run. 96 | 97 | ```yaml 98 | Type: System.Management.Automation.SwitchParameter 99 | Parameter Sets: (All) 100 | Aliases: wi 101 | 102 | Required: False 103 | Position: Named 104 | Default value: None 105 | Accept pipeline input: False 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### -Confirm 110 | Prompts you for confirmation before running the cmdlet. 111 | 112 | ```yaml 113 | Type: System.Management.Automation.SwitchParameter 114 | Parameter Sets: (All) 115 | Aliases: cf 116 | 117 | Required: False 118 | Position: Named 119 | Default value: None 120 | Accept pipeline input: False 121 | Accept wildcard characters: False 122 | ``` 123 | 124 | ### -ProgressAction 125 | {{ Fill ProgressAction Description }} 126 | 127 | ```yaml 128 | Type: System.Management.Automation.ActionPreference 129 | Parameter Sets: (All) 130 | Aliases: proga 131 | 132 | Required: False 133 | Position: Named 134 | Default value: None 135 | Accept pipeline input: False 136 | Accept wildcard characters: False 137 | ``` 138 | 139 | ### CommonParameters 140 | 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). 141 | 142 | ## INPUTS 143 | 144 | ## OUTPUTS 145 | 146 | PSCustomObject. The full table record (requires -PassThru). 147 | ## NOTES 148 | 149 | ## RELATED LINKS 150 | 151 | [https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWUserPhoto.md](https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWUserPhoto.md) 152 | 153 | [https://docs.servicenow.com/csh?topicname=c_AttachmentAPI.html&version=latest](https://docs.servicenow.com/csh?topicname=c_AttachmentAPI.html&version=latest) 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/images/ProxyBypass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/docs/images/ProxyBypass.png -------------------------------------------------------------------------------- /docs/images/copy_paste_queries.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/docs/images/copy_paste_queries.gif -------------------------------------------------------------------------------- /functionBuilder/Boilerplate_Table_GET.txt: -------------------------------------------------------------------------------- 1 | function {{functionname}} { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a {{tablename}} record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the {{tablename}} table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/{{functionname}}.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | {{functionname}} -limit 1 -verbose 17 | Returns a single record from {{tablename}} 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ({{params}}) 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 23 | 24 | Begin { 25 | $table = "{{tablename}}" 26 | } 27 | Process { 28 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 29 | } 30 | } -------------------------------------------------------------------------------- /functionBuilder/Boilerplate_Table_NEW.txt: -------------------------------------------------------------------------------- 1 | function {{functionname}} { 2 | <# 3 | .SYNOPSIS 4 | Creates a {{tablename}} record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the {{tablename}} table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/{{functionname}}.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | {{functionname}} -Properties @{""=""} -PassThru 17 | Creates a single record in {{tablename}} and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ({{params}}) 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 23 | 24 | Begin { 25 | $table = "{{tablename}}" 26 | } 27 | Process { 28 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 29 | } 30 | } -------------------------------------------------------------------------------- /functionBuilder/Boilerplate_Table_REMOVE.txt: -------------------------------------------------------------------------------- 1 | function {{functionname}} { 2 | <# 3 | .SYNOPSIS 4 | Removes a {{tablename}} record in SNOW 5 | .DESCRIPTION 6 | Removes a record from the {{tablename}} table 7 | .NOTES 8 | Uses Remove-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/{{functionname}}.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | {{functionname}} -Sys_ID "" 17 | Removes a specific record in the table {{tablename}} 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] 21 | param () 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Remove-SNOWObject" } 23 | 24 | Begin { 25 | $table = "{{tablename}}" 26 | } 27 | Process { 28 | Invoke-SNOWTableDELETE -table $table -Parameters $PSBoundParameters 29 | } 30 | } -------------------------------------------------------------------------------- /functionBuilder/Boilerplate_Table_SET.txt: -------------------------------------------------------------------------------- 1 | function {{functionname}} { 2 | <# 3 | .SYNOPSIS 4 | Updates a {{tablename}} record in SNOW 5 | .DESCRIPTION 6 | Updates a record from the {{tablename}} table 7 | .NOTES 8 | Uses Set-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/{{functionname}}.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | {{functionname}} -Sys_ID "" -Properties @{""=""} -verbose 17 | Updates a specific record in the table {{tablename}} 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ({{params}}) 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" } 23 | 24 | Begin { 25 | $table = "{{tablename}}" 26 | } 27 | Process { 28 | Invoke-SNOWTableUPDATE -table $table -Parameters $PSBoundParameters 29 | } 30 | } -------------------------------------------------------------------------------- /src/PSSnow.psm1: -------------------------------------------------------------------------------- 1 | using namespace System.Management.Automation 2 | using namespace System.Management.Automation.Internal 3 | 4 | $ErrorActionPreference = "Stop" 5 | 6 | $ModulePath = $PSScriptRoot 7 | 8 | $Private = Get-ChildItem (Join-Path $ModulePath Private) -Recurse -Filter *.ps1 9 | $Public = Get-ChildItem (Join-Path $ModulePath Public) -Recurse -Filter *.ps1 10 | 11 | #Dot source the functions 12 | $Functions = @($Private;$Public).Foreach({ 13 | [System.IO.File]::ReadAllText($_.FullName, [System.Text.Encoding]::UTF8) + [System.Environment]::NewLine 14 | }) 15 | . ([System.Management.Automation.ScriptBlock]::Create($Functions)) 16 | 17 | # Export public functions 18 | Export-ModuleMember -Function $Public.BaseName -Alias * -------------------------------------------------------------------------------- /src/Private/Assert-SNOWAuth.ps1: -------------------------------------------------------------------------------- 1 | function Assert-SNOWAuth() { 2 | [CmdletBinding()] 3 | param ( 4 | [Parameter()] 5 | [int] 6 | # Expressed in seconds 7 | $OauthExpiryBuffer = 180 8 | ) 9 | 10 | if($null -eq $script:SNOWAuth){ 11 | Write-Error "Please set ServiceNow authentication with Set-SNOWAuth" -ErrorAction Stop 12 | } 13 | 14 | if($script:SNOWAuth.Type -eq "OAuth"){ 15 | $CurrentTime = Get-Date 16 | $ExpiryTime = $script:SNOWAuth.Expires.AddSeconds(-$OauthExpiryBuffer) 17 | if($ExpiryTime -le $CurrentTime){ 18 | $ProxyAuth = $script:SNOWAuth.ProxyAuth 19 | #? Get a new token 20 | $Body = @{ 21 | grant_type="refresh_token" 22 | client_id = $script:SNOWAuth.ClientID 23 | client_secret = [System.Net.NetworkCredential]::new('dummy', $script:SNOWAuth.ClientSecret).Password 24 | refresh_token = $script:SNOWAuth.token.refresh_token 25 | } 26 | $Token = Invoke-RestMethod -Method POST -uri "https://$($Script:SNOWAuth.Instance).service-now.com/oauth_token.do" -Body $Body -Verbose:$false @ProxyAuth 27 | 28 | $script:SNOWAuth.token = $token 29 | $script:SNOWAuth.Expires = (get-date).AddSeconds($Token.expires_in) 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Private/Confirm-SysID.ps1: -------------------------------------------------------------------------------- 1 | function Confirm-SysID { 2 | param( 3 | [Parameter(Mandatory,ValueFromPipeline)] 4 | [alias('SysID')] 5 | [string] 6 | $sys_id, 7 | [Parameter()] 8 | [switch] 9 | $ValidateScript 10 | ) 11 | 12 | process { 13 | $IsSysID = $sys_id -match "^[0-9a-f]{32}$" 14 | 15 | if($ValidateScript.IsPresent -and -not $IsSysID){ 16 | Throw "A valid sys_id was not provided" 17 | }else{ 18 | $IsSysID 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/Private/ConvertTo-BatchRequest.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-BatchRequest { 2 | param( 3 | [Parameter()] 4 | [string] 5 | $URI, 6 | [Parameter()] 7 | [string] 8 | [ValidateSet('POST','PATCH')] 9 | $Method, 10 | [Parameter()] 11 | [string] 12 | $Body, 13 | [Parameter()] 14 | [Switch] 15 | $ExcludeResponseHeaders 16 | ) 17 | 18 | if($URI -notmatch "(?<=service-now.com).*"){ 19 | Throw "URI did not match https://*.service-now.com* format." 20 | } 21 | 22 | $BatchRequest = @{ 23 | id = (new-guid).guid 24 | url = $Matches[0] 25 | method = $Method 26 | headers = @( 27 | @{ 28 | 'name' = 'Content-Type' 29 | 'value' = 'application/json' 30 | }, 31 | @{ 32 | 'name' = 'Accept' 33 | 'value' = 'application/json' 34 | } 35 | ) 36 | exclude_response_headers = $ExcludeResponseHeaders.IsPresent 37 | body = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Body)) 38 | } 39 | 40 | return $BatchRequest 41 | } -------------------------------------------------------------------------------- /src/Private/ConvertTo-QueryString.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-QueryString { 2 | [CmdletBinding()] 3 | param( 4 | [Parameter(Mandatory)] 5 | [String] 6 | $BaseURL, 7 | [Parameter()] 8 | $QueryParameters 9 | ) 10 | try{ 11 | $QueryCollection = [System.Web.HttpUtility]::ParseQueryString('') 12 | $URI = [System.UriBuilder]$BaseURL 13 | 14 | if($QueryParameters){ 15 | if($QueryParameters.GetType().name -eq "Hashtable"){ 16 | foreach($Property in $QueryParameters.GetEnumerator()){ 17 | if($Property.Value){ 18 | $QueryCollection.Add($Property.key,$Property.Value) 19 | } 20 | } 21 | }elseif($QueryParameters.GetType().name -in @("DictionaryEntry","Object[]")){ 22 | foreach($Property in $QueryParameters){ 23 | if($Property.Value){ 24 | $QueryCollection.Add($Property.key,$Property.Value) 25 | } 26 | } 27 | } 28 | } 29 | 30 | $URI.Query = $QueryCollection.ToString() 31 | if($URI.Query){ 32 | Return $URI.URI.OriginalString 33 | }else{ 34 | Return $URI.URI.OriginalString + "?" 35 | } 36 | }catch{ 37 | #If auth has not been set, it's possible a bad URI has been passed to this function so we'll run the auth check in this instance 38 | if($_.Exception.message -like "*Invalid URI: The hostname could not be parsed*"){ 39 | Assert-SNOWAuth 40 | } 41 | 42 | #If the auth check passes or for all other reasons, throw the original error 43 | Throw $_ 44 | } 45 | } -------------------------------------------------------------------------------- /src/Private/Format-Hashtable.ps1: -------------------------------------------------------------------------------- 1 | Function Format-Hashtable { 2 | Param( 3 | [Parameter(Mandatory)] 4 | [hashtable] 5 | $Hashtable, 6 | [Parameter()] 7 | [switch] 8 | $KeysToLowerCase 9 | ) 10 | 11 | BEGIN { 12 | $OutputHashtable = @{} 13 | } 14 | 15 | PROCESS { 16 | if($KeysToLowerCase.IsPresent){ 17 | foreach ($Key in $Hashtable.Keys) { 18 | $OutputHashtable.Add($Key.ToLower(), $Hashtable[$Key]) 19 | } 20 | } 21 | } 22 | 23 | END { 24 | Return $OutputHashtable 25 | } 26 | } -------------------------------------------------------------------------------- /src/Private/Get-AuthHeader.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuthHeader { 2 | param() 3 | 4 | if($script:SNOWAuth.Type -eq "basic"){ 5 | $authInfo = "$($script:SNOWAuth.Credential.Username):$($script:SNOWAuth.Credential.GetNetworkCredential().Password)" 6 | @{ 7 | Authorization = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($authInfo)) 8 | } 9 | }elseif($script:SNOWAuth.Type -eq "oauth"){ 10 | @{ 11 | Authorization = "Bearer $($script:SNOWAuth.token.access_token)" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Private/Import-DefaultParamSet.ps1: -------------------------------------------------------------------------------- 1 | function Import-DefaultParamSet { 2 | <# 3 | .SYNOPSIS 4 | Used to inherit default parameters from a base function 5 | .DESCRIPTION 6 | Builds a parameter dictionary based on the existing parameters of the supplied function name 7 | .NOTES 8 | Can be used to populate a dynamic parameter block from a proxy function 9 | .EXAMPLE 10 | DynamicParam { Import-DefaultParamSet } 11 | Used in a child function to import the parents parameters 12 | #> 13 | 14 | [CmdletBinding()] 15 | param( 16 | [Parameter(ValueFromPipeline)] 17 | [string] 18 | $TemplateFunction, 19 | [Parameter()] 20 | [array] 21 | $Exclusions = @("table"), 22 | [Parameter()] 23 | [switch] 24 | $AsStringArray, 25 | [Parameter()] 26 | [switch] 27 | $IncludeCommon 28 | ) 29 | 30 | process { 31 | $BaseCommand = Get-Command $TemplateFunction 32 | $Common = @( 33 | [System.Management.Automation.PSCmdlet]::CommonParameters; 34 | [System.Management.Automation.PSCmdlet]::OptionalCommonParameters; 35 | $Exclusions 36 | ) 37 | 38 | if(-not $BaseCommand){ 39 | Write-Error "Unable to find function $TemplateFunction" -ErrorAction Stop 40 | } 41 | 42 | if($AsStringArray.IsPresent){ 43 | if($IncludeCommon.IsPresent){ 44 | return $BaseCommand.Parameters.Keys 45 | }else{ 46 | return ($BaseCommand.Parameters.Keys | Where-Object {$_ -notin $Common}) 47 | } 48 | }else{ 49 | $ParamDictionary = [RuntimeDefinedParameterDictionary]::new() 50 | $BaseCommand.Parameters.GetEnumerator().foreach{ 51 | $Val = $_.value 52 | $Key = $_.key 53 | if ($Key -notin $Common) 54 | { 55 | $param = [RuntimeDefinedParameter]::new( 56 | $key, $val.parameterType, $val.attributes) 57 | $ParamDictionary.add($key, $param) 58 | } 59 | } 60 | return $ParamDictionary 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/Private/Invoke-SNOWTableCREATE.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-SNOWTableCREATE { 2 | [CmdletBinding(SupportsShouldProcess)] 3 | param ( 4 | [Parameter(Mandatory)] 5 | [hashtable] 6 | $Parameters, 7 | [Parameter(Mandatory)] 8 | [string] 9 | $Table, 10 | [Parameter()] 11 | [switch] 12 | $PassThru 13 | ) 14 | 15 | BEGIN { 16 | $URI = "https://$($script:SNOWAuth.instance).service-now.com/api/now/v2/table/$Table" 17 | $DefaultParameterList = Import-DefaultParamSet -TemplateFunction "New-SNOWObject" -AsStringArray -IncludeCommon 18 | $CreateParameters = $Parameters.GetEnumerator() | Where-Object {$_.Key -notin $DefaultParameterList} 19 | } 20 | 21 | PROCESS { 22 | #? sysparm_input_display_value 23 | if($Parameters.ContainsKey('InputDisplayValue')){ 24 | $URI = "$URI`?sysparm_input_display_value=$($Parameters.InputDisplayValue.ToString().ToLower())" 25 | } 26 | 27 | #? Create BODY 28 | #Combine properties hashtable with any additional parameters 29 | if($Parameters.Properties){ 30 | $Body = $Parameters.Properties 31 | }else{ 32 | $Body = @{} 33 | } 34 | 35 | if($CreateParameters){ 36 | if($CreateParameters.GetType().Name -eq "DictionaryEntry"){ 37 | $Body.Add($CreateParameters.Key,$CreateParameters.Value) 38 | }else{ 39 | Foreach($Property in $CreateParameters.GetEnumerator()){ 40 | $Body.Add($Property.Key,$Property.Value) 41 | } 42 | } 43 | } 44 | 45 | $Body = Format-Hashtable -Hashtable $Body -KeysToLowerCase 46 | $Body = $Body | ConvertTo-Json -Depth 10 -Compress 47 | 48 | if($Parameters.AsBatchRequest.IsPresent){ 49 | return (ConvertTo-BatchRequest -URI $URI -Method 'POST' -Body $Body) 50 | } 51 | 52 | #? API Call 53 | try{ 54 | if($PSCmdlet.ShouldProcess($URI,'POST')){ 55 | $Response = Invoke-SNOWWebRequest -UseRestMethod -Method POST -URI $URI -Body $Body -ContentType "Application/Json;charset=utf-8" 56 | <# 57 | Unlike the other CRUD private functions, CREATE has an additional PassThru 58 | This is for granularity between the public and private functions as some CREATE actions may require the sys_id in order to perform other tasks, while not necessarily wanting to return output to the user 59 | A good example of this is New-SNOWUser which features adding a photo to the user record (it's a second rest call after creation of the user) 60 | #> 61 | if($Parameters.PassThru.IsPresent -or $PassThru.IsPresent){ 62 | Return $Response.result 63 | } 64 | } 65 | }catch{ 66 | Write-Error "$($_.Exception.Message) [$URI]" 67 | } 68 | 69 | } 70 | } 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/Private/Invoke-SNOWTableDELETE.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-SNOWTableDELETE { 2 | [CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')] 3 | param ( 4 | [Parameter(Mandatory)] 5 | [string] 6 | $table, 7 | [Parameter(Mandatory)] 8 | [hashtable] 9 | $Parameters 10 | ) 11 | 12 | BEGIN { 13 | $Parameters = Format-Hashtable -Hashtable $Parameters -KeysToLowerCase 14 | $BaseURL = "https://$($script:SNOWAuth.instance).service-now.com/api/now/v2/table/$Table/" 15 | } 16 | 17 | PROCESS { 18 | $URI = "$BaseURL$($Parameters.sys_id)" 19 | 20 | #? sysparm_query_no_domain 21 | if($Parameters.ContainsKey('RestrictDomain')){ 22 | $URI = "$URI`?sysparm_query_no_domain=$($Parameters.RestrictDomain.ToString().ToLower())" 23 | } 24 | 25 | try{ 26 | if($PSCmdlet.ShouldProcess($URI,'DELETE')){ 27 | Invoke-SNOWWebRequest -UseRestMethod -Method "DELETE" -URI $URI 28 | } 29 | }catch{ 30 | Write-Error "$($_.Exception.Message) [$URI]" 31 | } 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /src/Private/Invoke-SNOWTableUPDATE.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-SNOWTableUPDATE { 2 | [CmdletBinding(SupportsShouldProcess)] 3 | param ( 4 | [Parameter(Mandatory)] 5 | [hashtable] 6 | $Parameters, 7 | [Parameter(Mandatory)] 8 | [string] 9 | $Table 10 | ) 11 | 12 | BEGIN { 13 | $BaseURL = "https://$($script:SNOWAuth.instance).service-now.com/api/now/v2/table/$Table" 14 | $DefaultParameterList = Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" -AsStringArray -IncludeCommon 15 | $UpdateParameters = $Parameters.GetEnumerator() | Where-Object {$_.Key -notin $DefaultParameterList} 16 | } 17 | 18 | PROCESS { 19 | $URI = "$BaseURL/$($Parameters.Sys_ID)" 20 | 21 | #? sysparm_input_display_value 22 | if($Parameters.ContainsKey('InputDisplayValue')){ 23 | $URI = "$URI`?sysparm_input_display_value=$($Parameters.InputDisplayValue.ToString().ToLower())" 24 | } 25 | 26 | #? Create BODY 27 | #Combine properties hashtable with any additional parameters 28 | if($Parameters.Properties){ 29 | $Body = $Parameters.Properties 30 | }else{ 31 | $Body = @{} 32 | } 33 | 34 | if($UpdateParameters){ 35 | if($UpdateParameters.GetType().Name -eq "DictionaryEntry"){ 36 | $Body.Add($UpdateParameters.Key,$UpdateParameters.Value) 37 | }else{ 38 | Foreach($Property in $UpdateParameters.GetEnumerator()){ 39 | $Body.Add($Property.Key,$Property.Value) 40 | } 41 | } 42 | } 43 | 44 | $Body = Format-Hashtable -Hashtable $Body -KeysToLowerCase 45 | $Body = $Body | ConvertTo-Json -Depth 10 -Compress 46 | 47 | if($Parameters.AsBatchRequest.IsPresent){ 48 | return (ConvertTo-BatchRequest -URI $URI -Method 'PATCH' -Body $Body -ExcludeResponseHeaders) 49 | } 50 | 51 | #? API Call 52 | try{ 53 | 54 | if($PSVersionTable.PSEdition -eq "Core" -and $VerbosePreference -eq "Continue"){ 55 | Write-Verbose $URI 56 | } 57 | 58 | if($PSCmdlet.ShouldProcess("$table/$($Parameters.Sys_ID)","UPDATE")){ 59 | $Response = Invoke-SNOWWebRequest -UseRestMethod -Method PATCH -URI $URI -Body $Body -ContentType "Application/Json;charset=utf-8" 60 | 61 | if($Parameters.PassThru.IsPresent){ 62 | Return $Response.Result 63 | } 64 | } 65 | }catch{ 66 | Write-Error "$($_.Exception.Message) [$URI]" 67 | } 68 | 69 | } 70 | } 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/Public/Get-SNOWAuth.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWAuth { 2 | <# 3 | .SYNOPSIS 4 | Returns the currently set SNOWAuth 5 | .DESCRIPTION 6 | Returns the module scope authentication for PSSnow 7 | .EXAMPLE 8 | Get-SNOWAuth 9 | .LINK 10 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWAuth.md 11 | .LINK 12 | https://docs.servicenow.com/csh?topicname=c_RESTAPI.html&version=latest 13 | #> 14 | param () 15 | 16 | return $Script:SNOWAuth 17 | } -------------------------------------------------------------------------------- /src/Public/Get-SNOWRITMVariableSet.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWRITMVariableSet { 2 | <# 3 | .SYNOPSIS 4 | Gets all associated variables for a RITM 5 | .DESCRIPTION 6 | Returns all the RITM variables and display labels 7 | .EXAMPLE 8 | Get-SNOWRITMVariableSet -number "RITM0010001" 9 | Returns RITM Variables for RITM0010001 10 | .EXAMPLE 11 | Get-SNOWRITMVariableSet -Sys_id a07e6bd947616110d3e5fa8bd36d4339 12 | Returns RITM Variables for the RITM with a sys_id of a07e6bd947616110d3e5fa8bd36d4339 13 | .EXAMPLE 14 | Get-SNOWRITMVariableSet -number "RITM0010001" -IncludeLabels 15 | Returns RITM Variables for RITM0010001, adding the display label to the output object 16 | .EXAMPLE 17 | Get-SNOWSCRequestedItem -Number "RITM0010001" | Get-SNOWRITMVariableSet 18 | Returns RITM Variables for RITM0010001 19 | .LINK 20 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWRITMVariableSet.md 21 | #> 22 | 23 | [CmdletBinding(DefaultParameterSetName='sys_id')] 24 | [alias('Get-SNOWSCRequestedItemVariableSet')] 25 | [alias('Get-SNOWSCRequestedItemVariable')] 26 | param ( 27 | [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='number')] 28 | [string] 29 | $Number, 30 | [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='sys_id')] 31 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 32 | [alias('sysid')] 33 | [string] 34 | $Sys_Id, 35 | [Parameter(ParameterSetName='sys_id')] 36 | [Parameter(ParameterSetName='number')] 37 | [switch] 38 | $IncludeLabels 39 | ) 40 | begin { 41 | $table = "sc_item_option_mtom" 42 | } 43 | process { 44 | switch ($PSCmdlet.ParameterSetName) { 45 | "number" { 46 | $RITM = Get-SNOWSCRequestedItem -number $Number -Fields @('sys_id') 47 | if($null -eq $RITM){ 48 | Write-Error "Unable to locate $Number" 49 | return 50 | } 51 | $RitmID = $RITM.sys_id 52 | } 53 | "sys_id" { 54 | $RitmID = $sys_id 55 | } 56 | } 57 | 58 | $MTOMSplat = @{ 59 | Table = $table 60 | Query = "request_item=$RitmID" 61 | Fields = @( 62 | "sc_item_option.item_option_new.name", 63 | "sc_item_option.item_option_new", 64 | "sc_item_option.value" 65 | ) 66 | ExcludeReferenceLinks = $true 67 | DisplayValue = $true 68 | } 69 | $RITMVariables = Get-SNOWObject @MTOMSplat 70 | 71 | if($RITMVariables){ 72 | $OutputObject = [PSCustomObject]@{} 73 | 74 | if($IncludeLabels.IsPresent){ 75 | Foreach($RITMVariable in $RITMVariables){ 76 | $OutputRow = [PSCustomObject]@{ 77 | label = $RITMVariable."sc_item_option.item_option_new" 78 | value = $RITMVariable."sc_item_option.value" 79 | } 80 | $OutputObject | Add-Member -MemberType NoteProperty -Name $RITMVariable."sc_item_option.item_option_new.name" -Value $OutputRow 81 | } 82 | }else{ 83 | Foreach($RITMVariable in $RITMVariables){ 84 | $OutputObject | Add-Member -MemberType NoteProperty -Name $RITMVariable."sc_item_option.item_option_new.name" -Value $RITMVariable."sc_item_option.value" 85 | } 86 | } 87 | 88 | switch ($PSCmdlet.ParameterSetName) { 89 | "number" { 90 | $OutputObject | Add-Member -MemberType NoteProperty -Name "number" -Value $number 91 | } 92 | "sys_id" { 93 | $OutputObject | Add-Member -MemberType NoteProperty -Name "sys_id" -Value $sys_id 94 | } 95 | } 96 | 97 | return $OutputObject 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /src/Public/Invoke-SNOWRestMethod.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-SNOWRestMethod { 2 | 3 | <# 4 | .SYNOPSIS 5 | A generic way to make rest calls to servicenow API's [deprecated] 6 | .DESCRIPTION 7 | A wrapper for Invoke-RestMethod that utilizes authentication set with Set-SNOWAuth [deprecated] 8 | .NOTES 9 | !This function is deprecated and has been left in for backward compatibility. Please use Invoke-SNOWWebRequest instead. 10 | .LINK 11 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Invoke-SNOWRestMethod.md 12 | .EXAMPLE 13 | $Response = Invoke-SNOWRestMethod -uri "api/now/v2/table/sys_user?sysparm_limit=1" 14 | .EXAMPLE 15 | $Body = @{first_name="john";last_name="smith"} | ConvertTo-json 16 | $Headers = @{"Content-Type"="Application/Json"} 17 | $Response = Invoke-SNOWRestMethod -uri "api/now/v2/table/sys_user" -Method "POST" -Body $Body -Headers $Headers 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter(Mandatory)] 23 | [string] 24 | $Uri, 25 | [Parameter()] 26 | [ValidateSet( 27 | 'DEFAULT', 28 | 'HEAD', 29 | 'MERGE', 30 | 'OPTIONS', 31 | 'TRACE', 32 | 'GET', 33 | 'PATCH', 34 | 'POST', 35 | 'PUT', 36 | 'DELETE' 37 | )] 38 | [string] 39 | $Method, 40 | [Parameter()] 41 | [object] 42 | $Body, 43 | [Parameter()] 44 | [Hashtable] 45 | $Headers 46 | ) 47 | 48 | Begin {} 49 | Process { 50 | $RestMethodSplat = @{ 51 | URI = $URI 52 | Headers = $Headers 53 | } 54 | 55 | if($Method){ 56 | $RestMethodSplat['Method'] = $Method 57 | } 58 | 59 | if($Body){ 60 | $RestMethodSplat['Body'] = $Body 61 | } 62 | 63 | Invoke-SNOWWebRequest -UseRestMethod @RestMethodSplat 64 | } 65 | } -------------------------------------------------------------------------------- /src/Public/Set-SNOWRITMVariable.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWRITMVariable { 2 | <# 3 | .SYNOPSIS 4 | Set the value of a variable associated with a RITM 5 | .DESCRIPTION 6 | Updates the value of a variable in the sc_item_option table 7 | .EXAMPLE 8 | Set-SNOWRITMVariable -Sys_id "a07e6bd947616110d3e5fa8bd36d4339" -Name "business_purpose" -Value "Hello World" 9 | Sets the value of business_purpose on a RITM with the sys_id of 'a07e6bd947616110d3e5fa8bd36d4339' to 'Hello World' 10 | .EXAMPLE 11 | Set-SNOWRITMVariable -Number "RITM0010001" -Name "business_purpose" -Value "Hello World" 12 | Sets the value of business_purpose on RITM00100001 to 'Hello World' 13 | .EXAMPLE 14 | Get-SNOWSCRequestedItem -number "RITM00100001" | Set-SNOWRITMVariable -Name "business_purpose" -Value "Hello World" 15 | Sets the value of business_purpose on RITM00100001 to 'Hello World' 16 | .LINK 17 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWRITMVariable.md 18 | #> 19 | 20 | [CmdletBinding(DefaultParameterSetName='sys_id', SupportsShouldProcess)] 21 | [alias('Set-SNOWSCRequestedItemVariable')] 22 | param ( 23 | [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='sys_id')] 24 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 25 | [alias('sysid')] 26 | [string] 27 | $Sys_Id, 28 | [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='number')] 29 | [string] 30 | $Number, 31 | [Parameter(Mandatory, ParameterSetName='sys_id')] 32 | [Parameter(Mandatory, ParameterSetName='number')] 33 | [string] 34 | $Name, 35 | [Parameter(Mandatory, ParameterSetName='sys_id')] 36 | [Parameter(Mandatory, ParameterSetName='number')] 37 | [string] 38 | $Value 39 | ) 40 | begin {} 41 | process { 42 | switch ($PSCmdlet.ParameterSetName) { 43 | "number" { 44 | $RITM = Get-SNOWSCRequestedItem -number $Number -Fields @('sys_id') 45 | if($null -eq $RITM){ 46 | Write-Error "Unable to locate $Number" 47 | return 48 | } 49 | $RitmID = $RITM.sys_id 50 | } 51 | "sys_id" { 52 | $RitmID = $sys_id 53 | } 54 | } 55 | 56 | #? Get the MTOM Pointer 57 | $MTOMRecord = Get-SNOWObject -Table "sc_item_option_mtom" -Query "request_item=$RitmID^sc_item_option.item_option_new.name=$Name" -Fields @( "sc_item_option.item_option_new.name", "sc_item_option", "sc_item_option.value") -ExcludeReferenceLinks 58 | if($null -eq $MTOMRecord){ 59 | Write-Error "Unable to locate variable '$Name'" 60 | return 61 | } 62 | 63 | #? Update the variable's value in the sc_item_option table 64 | if($PSCmdlet.ShouldProcess("RITM: $RitmID \ Variable: $Name","UPDATE")){ 65 | Set-SNOWObject -table "sc_item_option" -sys_id $MTOMRecord.sc_item_option -Properties @{value=$Value} 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/Public/attachment/Remove-SNOWAttachment.ps1: -------------------------------------------------------------------------------- 1 | function Remove-SNOWAttachment { 2 | <# 3 | .SYNOPSIS 4 | Removes attachments from servicenow. 5 | .DESCRIPTION 6 | Deletes an attachment from servicenow. 7 | .LINK 8 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWAttachment.md 9 | .LINK 10 | https://docs.servicenow.com/csh?topicname=c_AttachmentAPI.html&version=latest 11 | .EXAMPLE 12 | Remove-SNOWAttachment -Sys_ID a73f6d2447292110d3e5fa8bd36d4304 13 | Removes a single attachment by sys_id 14 | .EXAMPLE 15 | Get-SNOWUser -user_name "bruce.wayne" | Get-SNOWAttachment | Remove-SNOWAttachment -Verbose 16 | Removes all attachments on the associated parent object 17 | #> 18 | 19 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] 20 | param ( 21 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 22 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 23 | [string] 24 | #The SysID of the attachment record to be deleted 25 | $Sys_ID, 26 | [Parameter(ValueFromPipelineByPropertyName)] 27 | [string] 28 | $file_name 29 | ) 30 | 31 | begin { 32 | $BaseURL = "https://$($script:SNOWAuth.instance).service-now.com/api/now/v1/attachment/" 33 | } 34 | 35 | process { 36 | try{ 37 | if($PSCmdlet.ShouldProcess($file_name,'DELETE')){ 38 | Invoke-SNOWWebRequest -UseRestMethod -URI "$BaseURL$Sys_ID" -Method "DELETE" 39 | } 40 | }catch{ 41 | Write-Error "$($_.Exception.Message) [$BaseURL$Sys_ID]" 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/Public/attachment/Set-SNOWUserPhoto.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWUserPhoto { 2 | <# 3 | .SYNOPSIS 4 | Attaches a picture to a user record and updates the photo property 5 | .DESCRIPTION 6 | This function uses the Attachment API to upload a photo to a user record as a hidden attachment 7 | .OUTPUTS 8 | PSCustomObject. The full table record (requires -PassThru). 9 | .LINK 10 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWUserPhoto.md 11 | .LINK 12 | https://docs.servicenow.com/csh?topicname=c_AttachmentAPI.html&version=latest 13 | .EXAMPLE 14 | $User | Set-SNOWUserPhoto -filepath "C:\Temp\Bruce.jpg" 15 | Updates a user photo 16 | #> 17 | 18 | [CmdletBinding(SupportsShouldProcess)] 19 | param ( 20 | [Parameter(ParameterSetName = 'Filepath', Mandatory)] 21 | [ValidateScript({ 22 | if($_ | Test-Path){ 23 | if($_ | Test-Path -PathType Leaf){ 24 | $filetypes = @('.jpg','.png','.bmp','.gif','.jpeg','.ico','.svg') 25 | if([System.IO.Path]::GetExtension($_) -in $filetypes){ 26 | $true 27 | }else{ 28 | Throw "Incorrect filetype, must be one of the following: $($filetypes -join ',')" 29 | } 30 | }else{ 31 | Throw "Filepath cannot be a directory." 32 | } 33 | }else{ 34 | Throw "Unable to find file." 35 | } 36 | })] 37 | [System.IO.FileInfo] 38 | $Filepath, 39 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 40 | [alias('SysID')] 41 | [ValidateScript({ 42 | if($_ -match "^[0-9a-f]{32}$"){ 43 | $true 44 | }else{ 45 | Throw "Must be a valid sys_id" 46 | } 47 | })] 48 | [string] 49 | #The sys_id of the user record in the sys_user table 50 | $Sys_ID, 51 | [Parameter()] 52 | [switch] 53 | $PassThru, 54 | [Parameter(DontShow)] 55 | [switch] 56 | $AsBatchRequest 57 | ) 58 | 59 | process { 60 | #? Check for existing user photo 61 | if(-not $AsBatchRequest.IsPresent){ 62 | $ExistingPhotos = Get-SNOWAttachment -Query "table_sys_id=$Sys_ID^file_name=photo^table_name=ZZ_YYsys_user" 63 | Foreach($Photo in $ExistingPhotos){ 64 | $Photo | Remove-SNOWAttachment -Confirm:$false 65 | } 66 | } 67 | 68 | if($PSCmdlet.ShouldProcess($Sys_ID,"SET")){ 69 | $AttachmentSplat = @{ 70 | File = $Filepath 71 | Sys_ID = $Sys_ID 72 | Sys_Class_Name = "ZZ_YYsys_user" 73 | PassThru = $PassThru.IsPresent 74 | AttachedFilename = "photo" 75 | AsBatchRequest = $AsBatchRequest.IsPresent 76 | } 77 | New-SNOWAttachment @AttachmentSplat 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /src/Public/import/New-SNOWImport.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWImport { 2 | <# 3 | .SYNOPSIS 4 | Sends a new record to the import API 5 | .DESCRIPTION 6 | The import API can be used to push data into staging tables with transform maps 7 | .EXAMPLE 8 | $Movies = import-csv -Path "C:\temp\movies.csv" 9 | $Imports = ForEach($Movie in $Movies){ 10 | $MovieProperties = @{ 11 | u_title = $Movie."Movie Title" 12 | u_director = $Movie.Director 13 | u_actor = $Movie."Lead Actor" 14 | u_genre = $Movie.Genre 15 | } 16 | New-SNOWImport -table "u_moviesimport" -properties $MovieProperties 17 | } 18 | $Imports.result | Group-Object status | Select Count,Name 19 | .LINK 20 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWImport.md 21 | .LINK 22 | https://docs.servicenow.com/csh?topicname=c_ImportSetAPI.html&version=latest 23 | #> 24 | 25 | [CmdletBinding(SupportsShouldProcess)] 26 | param( 27 | [Parameter(Mandatory)] 28 | [string] 29 | $Table, 30 | [Parameter(Mandatory, ValueFromPipeline)] 31 | [ValidateCount(1, [int]::MaxValue)] 32 | [hashtable] 33 | $Properties, 34 | [Parameter(DontShow)] 35 | [switch]$AsBatchRequest 36 | ) 37 | 38 | Begin { 39 | $BaseURL = "https://$($script:SNOWAuth.Instance).service-now.com/api/now/v1/import/" 40 | } 41 | 42 | Process { 43 | $URI = $BaseURL + $Table 44 | $Body = Format-Hashtable -Hashtable $Properties -KeysToLowerCase 45 | $Body = $Body | ConvertTo-Json -Depth 10 -Compress 46 | 47 | if($AsBatchRequest.IsPresent){ 48 | return (ConvertTo-BatchRequest -URI $URI -Method 'POST' -Body $Body) 49 | } 50 | 51 | #? API Call 52 | try{ 53 | if($PSCmdlet.ShouldProcess($URI,'POST')){ 54 | Invoke-SNOWWebRequest -UseRestMethod -Method POST -URI $URI -Body $Body -ContentType "Application/Json" 55 | } 56 | }catch{ 57 | Write-Error "$($_.Exception.Message) [$URI]" 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/Public/sn_sc/Get-SNOWSCCart.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWSCCart { 2 | <# 3 | .SYNOPSIS 4 | Gets the current cart 5 | .DESCRIPTION 6 | returns the current cart properties 7 | .EXAMPLE 8 | Get-SNOWSCCart 9 | returns the cart object, no parameters required. 10 | .LINK 11 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCCart.md 12 | .LINK 13 | https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest 14 | #> 15 | [CmdletBinding()] 16 | param() 17 | 18 | $URI = "https://$($Script:SNOWAuth.Instance).service-now.com/api/sn_sc/servicecatalog/cart" 19 | $Response = Invoke-SNOWWebRequest -UseRestMethod -Uri $URI -Method GET 20 | if($Response){ 21 | return $Response.Result 22 | } 23 | } -------------------------------------------------------------------------------- /src/Public/sn_sc/Invoke-SNOWSCCart.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-SNOWSCCart { 2 | <# 3 | .SYNOPSIS 4 | Can be used to checkout or empty a cart 5 | .DESCRIPTION 6 | either processes a cart or clears the contents depending on paramters 7 | .EXAMPLE 8 | New-SNOWSCCartItem -Sys_ID "e91336da4fff0200086eeed18110c7a3" -Properties @{ 9 | primary_contact = "a8f98bb0eb32010045e1a5115206fe3a" 10 | cost_center = "a581ab703710200044e0bfc8bcbe5de8" 11 | ip_range = "127.0.0.1" 12 | business_purpose = "testing" 13 | } 14 | Invoke-SNOWSCCart -Checkout -PassThru 15 | .EXAMPLE 16 | New-SNOWSCCartItem -Sys_ID "e91336da4fff0200086eeed18110c7a3" -Properties @{ 17 | primary_contact = "a8f98bb0eb32010045e1a5115206fe3a" 18 | cost_center = "a581ab703710200044e0bfc8bcbe5de8" 19 | ip_range = "127.0.0.1" 20 | business_purpose = "testing" 21 | } 22 | Invoke-SNOWSCCart -Empty 23 | .LINK 24 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Invoke-SNOWSCCart.md 25 | .LINK 26 | https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest 27 | .NOTES 28 | If one-step checkout, the method checks out (saves) the cart and returns the request number and the request order ID. 29 | If two-step checkout, the method returns the cart order status and all the information required for two-step checkout. 30 | #> 31 | [CmdletBinding(SupportsShouldProcess,DefaultParameterSetName='checkout')] 32 | param( 33 | [Parameter(ParameterSetName='empty')] 34 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 35 | [string] 36 | $Sys_id, 37 | [Parameter(ParameterSetName='empty')] 38 | [switch] 39 | $Empty, 40 | [Parameter(ParameterSetName='checkout')] 41 | [switch] 42 | $Checkout, 43 | [Parameter(ParameterSetName='checkout')] 44 | [switch] 45 | $PassThru 46 | ) 47 | 48 | $URI = "https://$($Script:SNOWAuth.Instance).service-now.com/api/sn_sc/servicecatalog/cart/" 49 | $Headers = @{ 50 | 'Accept' = 'application/json' 51 | 'Content-Type' = 'application/json' 52 | } 53 | 54 | if($Checkout.IsPresent){ 55 | $URI = $URI + "checkout" 56 | $Method = "POST" 57 | } 58 | 59 | if($Empty){ 60 | if(-not $sys_id){ 61 | $sys_id = (Get-SNOWSCCart).cart_id 62 | } 63 | $URI = $URI + "$sys_id/empty" 64 | $Method = "DELETE" 65 | } 66 | 67 | if($PSCmdlet.ShouldProcess($URI,$Method)){ 68 | $Response = Invoke-SNOWWebRequest -UseRestMethod -Method $Method -Uri $URI -Headers $Headers 69 | if($Response -and $PassThru.IsPresent){ 70 | return $Response.Result 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/Public/sn_sc/New-SNOWSCCartItem.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWSCCartItem { 2 | <# 3 | .SYNOPSIS 4 | Adds the specified item to the cart of the current user 5 | .DESCRIPTION 6 | Adds an item to the service catalog cart. Checkout can also be initiated using -checkout. 7 | .EXAMPLE 8 | #todo 9 | .LINK 10 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWSCCartItem.md 11 | .LINK 12 | https://docs.servicenow.com/csh?topicname=c_ServiceCatalogAPI.html&version=latest 13 | .NOTES 14 | While using this function it is possible to bypass any validation that may be present on the web form. 15 | #> 16 | [CmdletBinding(SupportsShouldProcess)] 17 | param( 18 | [Parameter(Mandatory)] 19 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 20 | [string] 21 | # The sys_id for the catalog item 22 | $Sys_ID, 23 | [Parameter()] 24 | [hashtable] 25 | $Properties, 26 | [Parameter()] 27 | [ValidateRange(0, [int]::MaxValue)] 28 | [int] 29 | $Quantity = 1, 30 | [Parameter()] 31 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 32 | [string] 33 | $RequestedFor, 34 | [Parameter()] 35 | [ValidateCount(0,50)] 36 | [ValidateScript({ $_ | ForEach-Object { $_ | Confirm-SysID -ValidateScript }})] 37 | [array] 38 | #An array of sys_id's to order the item for. If the associated item does not have the requested_for variable set, the request is rejected. 39 | $AlsoRequestFor, 40 | [Parameter()] 41 | [switch] 42 | $Checkout, 43 | [Parameter()] 44 | [switch] 45 | $PassThru 46 | ) 47 | 48 | Begin { 49 | $BaseURL = "https://$($Script:SNOWAuth.Instance).service-now.com/api/sn_sc/servicecatalog/items" 50 | $Headers = @{ 51 | 'Accept' = 'application/json' 52 | 'Content-Type' = 'application/json' 53 | } 54 | } 55 | Process { 56 | $URI = "$BaseURL/$Sys_ID/add_to_cart" 57 | $Body = @{ 58 | variables = $Properties 59 | sysparm_quantity = $Quantity 60 | } 61 | 62 | if($RequestedFor){ 63 | $Body += @{ 64 | sysparm_requested_for = $RequestedFor 65 | } 66 | } 67 | if($AlsoRequestFor){ 68 | $Body += @{ 69 | sysparm_also_request_for = $AlsoRequestFor -join "," 70 | } 71 | } 72 | 73 | $Body = $Body | ConvertTo-Json -Compress -Depth 10 74 | 75 | 76 | if($PSCmdlet.ShouldProcess($URI,'POST')){ 77 | $RestSplat = @{ 78 | Method = "POST" 79 | Headers = $Headers 80 | URI = $URI 81 | Body = $Body 82 | } 83 | $Response = Invoke-SNOWWebRequest -UseRestMethod @RestSplat 84 | if($Response){ 85 | $Response = $Response.result 86 | } 87 | 88 | if($Checkout.IsPresent){ 89 | $Response = Invoke-SNOWSCCart -Checkout -PassThru 90 | } 91 | 92 | if($Response -and $PassThru.IsPresent){ 93 | return $Response 94 | } 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /src/Public/stats/Get-SNOWStatistic.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWStatistic { 2 | <# 3 | .SYNOPSIS 4 | Used to interact with the aggregate API to get statistics on table data 5 | .DESCRIPTION 6 | Retrieves records for the specified table and performs aggregate functions to return statistics. 7 | .NOTES 8 | For Aggregate API requests, you must have read access for all records in the table you query. If an ACL prevents the requesting user from accessing any record in the table, the request returns a 403 Forbidden error. 9 | .LINK 10 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWStatistic.md 11 | .LINK 12 | https://docs.servicenow.com/csh?topicname=c_AggregateAPI.html&version=latest 13 | .EXAMPLE 14 | Get-SNOWStatistic -Table "sys_user" -Query "active=true" -Count 15 | Returns the count of active users in the user table 16 | #> 17 | 18 | [CmdletBinding()] 19 | param ( 20 | [Parameter(Mandatory)] 21 | [string] 22 | $Table, 23 | [Parameter()] 24 | [array] 25 | # List of fields on which to perform each aggregate operation. 26 | $Fields, 27 | [Parameter()] 28 | [ValidateSet('avg','max','min','sum')] 29 | [string] 30 | #The aggregation function to perform on the fields parameter 31 | $FieldAggregation, 32 | [Parameter()] 33 | [ValidateSet('true','false','all')] 34 | [string] 35 | #The query returns either the display value, the actual value in the database, or both. 36 | $DisplayValue, 37 | [Parameter()] 38 | [array] 39 | #Fields by which to group the returned data 40 | $GroupBy, 41 | [Parameter()] 42 | [string] 43 | #You can specify an order using, fields or an aggregate including COUNT. E.g, 'AVG^state'. Ascending by default. Use ^DESC to sort in descending order, E.g 'state^DESC' 44 | $OrderBy, 45 | [Parameter()] 46 | #A ServiceNow encoded query, can be copied directly from the web ui 47 | $Query, 48 | [Parameter()] 49 | [string] 50 | #Additional query to filter based on an aggregate operation. e.g 'count^priority^>^3' to obtain the number of records within the query results with a priority greater than 3. You can specify multiple queries by separating each with a comma. 51 | $HavingQuery, 52 | [Parameter()] 53 | [switch] 54 | #Flag that determines whether to return the number of records returned by the query. 55 | $Count 56 | ) 57 | 58 | begin { 59 | $URI = "https://$($script:SNOWAuth.Instance).service-now.com/api/now/v1/stats/$Table`?" 60 | } 61 | 62 | process { 63 | Switch ($PSBoundParameters.Keys) { 64 | 'Fields' {$URI += "&sysparm_$FieldAggregation`_fields=$($Fields -join ',')"} 65 | 'DisplayValue' {$URI += "&sysparm_display_value=$DisplayValue"} 66 | 'GroupBy' {$URI += "&sysparm_group_by=$($GroupBy -join ',')"} 67 | 'OrderBy' {$URI += "&sysparm_orderby=$OrderBy"} 68 | 'Query' {$URI += "&sysparm_query=$Query"} 69 | 'HavingQuery' {$URI += "&sysparm_having=$HavingQuery"} 70 | 'Count' {$URI += "&sysparm_count=$($Count.IsPresent.ToString().ToLower())"} 71 | } 72 | 73 | $Response = Invoke-SNOWWebRequest -UseRestMethod -URI $URI 74 | if($Response){ 75 | return $Response.result 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWApprovalGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWApprovalGroup { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a sysapproval_group record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the sysapproval_group table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWApprovalGroup.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWApprovalGroup -limit 1 -verbose 17 | Returns a single record from sysapproval_group 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $admin_override, 25 | [Parameter()] 26 | [string] 27 | $approval_user, 28 | [Parameter()] 29 | [alias('handle_a_rejection_by')] 30 | [string] 31 | $reject_handling, 32 | [Parameter()] 33 | [string] 34 | $wait_for, 35 | [Parameter()] 36 | [boolean] 37 | $active, 38 | [Parameter()] 39 | [string] 40 | $additional_assignee_list, 41 | [Parameter()] 42 | [string] 43 | $approval, 44 | [Parameter()] 45 | [string] 46 | $assigned_to, 47 | [Parameter()] 48 | [string] 49 | $assignment_group, 50 | [Parameter()] 51 | [string] 52 | $business_duration, 53 | [Parameter()] 54 | [alias('service')] 55 | [string] 56 | $business_service, 57 | [Parameter()] 58 | [alias('duration')] 59 | [string] 60 | $calendar_duration, 61 | [Parameter()] 62 | [string] 63 | $closed_by, 64 | [Parameter()] 65 | [string] 66 | $close_notes, 67 | [Parameter()] 68 | [alias('configuration_item')] 69 | [string] 70 | $cmdb_ci, 71 | [Parameter()] 72 | [alias('additional_comments')] 73 | [string] 74 | $comments, 75 | [Parameter()] 76 | [string] 77 | $comments_and_work_notes, 78 | [Parameter()] 79 | [string] 80 | $company, 81 | [Parameter()] 82 | [string] 83 | $contact_type, 84 | [Parameter()] 85 | [string] 86 | $contract, 87 | [Parameter()] 88 | [string] 89 | $correlation_display, 90 | [Parameter()] 91 | [string] 92 | $correlation_id, 93 | [Parameter()] 94 | [string] 95 | $delivery_plan, 96 | [Parameter()] 97 | [string] 98 | $delivery_task, 99 | [Parameter()] 100 | [string] 101 | $description, 102 | [Parameter()] 103 | [string] 104 | $escalation, 105 | [Parameter()] 106 | [string] 107 | $group_list, 108 | [Parameter()] 109 | [string] 110 | $impact, 111 | [Parameter()] 112 | [boolean] 113 | $knowledge, 114 | [Parameter()] 115 | [string] 116 | $location, 117 | [Parameter()] 118 | [boolean] 119 | $made_sla, 120 | [Parameter()] 121 | [string] 122 | $number, 123 | [Parameter()] 124 | [string] 125 | $opened_by, 126 | [Parameter()] 127 | [string] 128 | $order, 129 | [Parameter()] 130 | [string] 131 | $parent, 132 | [Parameter()] 133 | [string] 134 | $priority, 135 | [Parameter()] 136 | [alias('transfer_reason')] 137 | [string] 138 | $route_reason, 139 | [Parameter()] 140 | [string] 141 | $service_offering, 142 | [Parameter()] 143 | [string] 144 | $short_description, 145 | [Parameter()] 146 | [string] 147 | $state, 148 | [Parameter()] 149 | [alias('effective_number')] 150 | [string] 151 | $task_effective_number, 152 | [Parameter()] 153 | [string] 154 | $time_worked, 155 | [Parameter()] 156 | [string] 157 | $urgency, 158 | [Parameter()] 159 | [string] 160 | $user_input, 161 | [Parameter()] 162 | [string] 163 | $watch_list, 164 | [Parameter()] 165 | [string] 166 | $work_notes, 167 | [Parameter()] 168 | [string] 169 | $work_notes_list 170 | ) 171 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 172 | 173 | Begin { 174 | $table = "sysapproval_group" 175 | } 176 | Process { 177 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 178 | } 179 | } 180 | 181 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWApprover.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWApprover { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a sysapproval_approver record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the sysapproval_approver table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWApprover.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWApprover -limit 1 -verbose 17 | Returns a single record from sysapproval_approver 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $approval_source, 25 | [Parameter()] 26 | [string] 27 | $approver, 28 | [Parameter()] 29 | [alias('ParentSysID')] 30 | [string] 31 | $document_id, 32 | [Parameter()] 33 | [string] 34 | $group, 35 | [Parameter()] 36 | [string] 37 | $source_table, 38 | [Parameter()] 39 | [string] 40 | $state, 41 | [Parameter()] 42 | [string] 43 | $sysapproval 44 | ) 45 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 46 | 47 | Begin { 48 | $table = "sysapproval_approver" 49 | } 50 | Process { 51 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWChangeRequest.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWChangeRequest { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a change_request record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the change_request table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWChangeRequest.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWChangeRequest -limit 1 -verbose 17 | Returns a single record from change_request 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $number, 25 | [Parameter()] 26 | [string] 27 | $requested_by, 28 | [Parameter()] 29 | [string] 30 | $category, 31 | [Parameter()] 32 | [alias('service')] 33 | [string] 34 | $business_service, 35 | [Parameter()] 36 | [string] 37 | $service_offering, 38 | [Parameter()] 39 | [alias('configuration_item')] 40 | [string] 41 | $cmdb_ci, 42 | [Parameter()] 43 | [string] 44 | $priority, 45 | [Parameter()] 46 | [string] 47 | $risk, 48 | [Parameter()] 49 | [string] 50 | $impact, 51 | [Parameter()] 52 | [alias('model')] 53 | [string] 54 | $chg_model, 55 | [Parameter()] 56 | [string] 57 | $type, 58 | [Parameter()] 59 | [string] 60 | $state, 61 | [Parameter()] 62 | [boolean] 63 | $on_hold, 64 | [Parameter()] 65 | [string] 66 | $conflict_status, 67 | [Parameter()] 68 | [string] 69 | $assignment_group, 70 | [Parameter()] 71 | [string] 72 | $assigned_to, 73 | [Parameter()] 74 | [string] 75 | $short_description, 76 | [Parameter()] 77 | [boolean] 78 | $cab_required, 79 | [Parameter()] 80 | [string] 81 | $cab_delegate, 82 | [Parameter()] 83 | [string] 84 | $cab_recommendation, 85 | [Parameter()] 86 | [string] 87 | $close_code, 88 | [Parameter()] 89 | [string] 90 | $on_hold_task, 91 | [Parameter()] 92 | [boolean] 93 | $production_system, 94 | [Parameter()] 95 | [string] 96 | $opened_by, 97 | [Parameter()] 98 | [string] 99 | $closed_by, 100 | [Parameter()] 101 | [boolean] 102 | $active, 103 | [Parameter()] 104 | [string] 105 | $approval, 106 | [Parameter()] 107 | [string] 108 | $parent, 109 | [Parameter()] 110 | [string] 111 | $phase, 112 | [Parameter()] 113 | [string] 114 | $phase_state, 115 | [Parameter()] 116 | [boolean] 117 | $unauthorized, 118 | [Parameter()] 119 | [string] 120 | $company, 121 | [Parameter()] 122 | [string] 123 | $escalation, 124 | [Parameter()] 125 | [string] 126 | $location, 127 | [Parameter()] 128 | [boolean] 129 | $made_sla 130 | ) 131 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 132 | 133 | Begin { 134 | $table = "change_request" 135 | } 136 | Process { 137 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWDepartment.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWDepartment { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a cmn_department record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the cmn_department table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWDepartment.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWDepartment -limit 1 -verbose 17 | Returns a single record from cmn_department 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $business_unit, 25 | [Parameter()] 26 | [string] 27 | $company, 28 | [Parameter()] 29 | [string] 30 | $cost_center, 31 | [Parameter()] 32 | [alias('department_head')] 33 | [string] 34 | $dept_head, 35 | [Parameter()] 36 | [string] 37 | $description, 38 | [Parameter()] 39 | [string] 40 | $head_count, 41 | [Parameter()] 42 | [string] 43 | $id, 44 | [Parameter()] 45 | [string] 46 | $name, 47 | [Parameter()] 48 | [string] 49 | $parent, 50 | [Parameter()] 51 | [string] 52 | $primary_contact 53 | ) 54 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 55 | 56 | Begin { 57 | $table = "cmn_department" 58 | } 59 | Process { 60 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWIncident.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWIncident { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a servicenow Incident 5 | .DESCRIPTION 6 | Gets a record from the incident table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWIncident.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWIncident -limit 1 -verbose 17 | Returns a single Incident 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $made_sla, 25 | [Parameter()] 26 | [string] 27 | $number, 28 | [Parameter()] 29 | [string] 30 | $resolved_by, 31 | [Parameter()] 32 | [string] 33 | $opened_by, 34 | [Parameter()] 35 | [string] 36 | $state, 37 | [Parameter()] 38 | [string] 39 | $impact, 40 | [Parameter()] 41 | [boolean] 42 | $active, 43 | [Parameter()] 44 | [string] 45 | $business_impact, 46 | [Parameter()] 47 | [string] 48 | $priority, 49 | [Parameter()] 50 | [string] 51 | $caller_id, 52 | [Parameter()] 53 | [string] 54 | $short_description, 55 | [Parameter()] 56 | [string] 57 | $assignment_group, 58 | [Parameter()] 59 | [string] 60 | $notify, 61 | [Parameter()] 62 | [string] 63 | $closed_by, 64 | [Parameter()] 65 | [string] 66 | $parent_incident, 67 | [Parameter()] 68 | [string] 69 | $contact_type, 70 | [Parameter()] 71 | [string] 72 | $reopened_by, 73 | [Parameter()] 74 | [string] 75 | $incident_state, 76 | [Parameter()] 77 | [string] 78 | $urgency, 79 | [Parameter()] 80 | [string] 81 | $company, 82 | [Parameter()] 83 | [string] 84 | $assigned_to, 85 | [Parameter()] 86 | [string] 87 | $severity, 88 | [Parameter()] 89 | [string] 90 | $approval, 91 | [Parameter()] 92 | [string] 93 | $reopen_count, 94 | [Parameter()] 95 | [string] 96 | $escalation, 97 | [Parameter()] 98 | [string] 99 | $location, 100 | [Parameter()] 101 | [string] 102 | $category 103 | ) 104 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 105 | 106 | Begin { 107 | $table = "incident" 108 | } 109 | Process { 110 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 111 | } 112 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWLocation.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWLocation { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a cmn_location record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the cmn_location table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWLocation.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWLocation -limit 1 -verbose 17 | Returns a single record from cmn_location 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $city, 25 | [Parameter()] 26 | [alias('location_source')] 27 | [string] 28 | $cmn_location_source, 29 | [Parameter()] 30 | [alias('location_type')] 31 | [string] 32 | $cmn_location_type, 33 | [Parameter()] 34 | [string] 35 | $company, 36 | [Parameter()] 37 | [string] 38 | $contact, 39 | [Parameter()] 40 | [string] 41 | $country, 42 | [Parameter()] 43 | [boolean] 44 | $duplicate, 45 | [Parameter()] 46 | [string] 47 | $fax_phone, 48 | [Parameter()] 49 | [string] 50 | $full_name, 51 | [Parameter()] 52 | [string] 53 | $latitude, 54 | [Parameter()] 55 | [string] 56 | $lat_long_error, 57 | [Parameter()] 58 | [string] 59 | $life_cycle_stage, 60 | [Parameter()] 61 | [string] 62 | $life_cycle_stage_status, 63 | [Parameter()] 64 | [string] 65 | $longitude, 66 | [Parameter()] 67 | [string] 68 | $managed_by_group, 69 | [Parameter()] 70 | [string] 71 | $name, 72 | [Parameter()] 73 | [string] 74 | $parent, 75 | [Parameter()] 76 | [string] 77 | $phone, 78 | [Parameter()] 79 | [string] 80 | $phone_territory, 81 | [Parameter()] 82 | [string] 83 | $primary_location, 84 | [Parameter()] 85 | [alias('state___province')] 86 | [string] 87 | $state, 88 | [Parameter()] 89 | [boolean] 90 | $stock_room, 91 | [Parameter()] 92 | [string] 93 | $street, 94 | [Parameter()] 95 | [string] 96 | $time_zone, 97 | [Parameter()] 98 | [alias('zip___postal_code')] 99 | [string] 100 | $zip 101 | ) 102 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 103 | 104 | Begin { 105 | $table = "cmn_location" 106 | } 107 | Process { 108 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 109 | } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWObject.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWObject { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a servicenow table API object 5 | .DESCRIPTION 6 | A template function for getting records from the table API 7 | .NOTES 8 | Queries can be copied directly from SNOW by right clicking on the end of the query string, this can be used within the query parameter. 9 | .INPUTS 10 | String. Any servicenow object with a sys_id property. 11 | .OUTPUTS 12 | PSCustomObject. The full table record/s. 13 | .LINK 14 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWObject.md 15 | .LINK 16 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 17 | .EXAMPLE 18 | Get-SNOWObject -table 'sys_user' -limit 1 -verbose 19 | Returns a single user from the sys_user table 20 | .EXAMPLE 21 | Get-SNOWObject -table 'sc_request' -query 'active=true' -limit 1 22 | Returns a single user from the sys_user table 23 | #> 24 | 25 | [CmdletBinding()] 26 | param ( 27 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 28 | [ValidateNotNullOrEmpty()] 29 | [alias("sys_class_name")] 30 | [string] 31 | $Table, 32 | [Parameter(ValueFromPipelineByPropertyName)] 33 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 34 | [string] 35 | [alias('SysID')] 36 | $Sys_ID, 37 | [Parameter()] 38 | [string] 39 | #Can be copied directly from the snow web gui 40 | $Query, 41 | [Parameter()] 42 | [ValidateCount(1,1000)] 43 | [array] 44 | #Which fields should be returned 45 | $Fields, 46 | [Parameter()] 47 | [ValidateSet("true","false","all")] 48 | [string] 49 | #The query returns either the display value, the actual value in the database, or both. 50 | $DisplayValue, 51 | [Parameter()] 52 | [switch] 53 | #Removes http links from reference fields 54 | $ExcludeReferenceLinks, 55 | [Parameter()] 56 | [ValidateRange(0, [int]::MaxValue)] 57 | [int] 58 | $Offset, 59 | [Parameter()] 60 | [ValidateRange(0, [int]::MaxValue)] 61 | [int] 62 | $Limit, 63 | [Parameter()] 64 | [switch] 65 | #Restricts the record search to only the domains for the logged in user. Only available to system administrators or query_no_domain_table_api role. 66 | $RestrictDomain = $false, 67 | [Parameter(DontShow)] 68 | [ValidateSet("desktop","mobile","both")] 69 | [string] 70 | #UI view for which to render the data. Determines the fields returned in the response. 71 | $SysParmView 72 | ) 73 | 74 | Process { 75 | Invoke-SNOWTableREAD -table $Table -Parameters $PSBoundParameters 76 | } 77 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWSCOrderGuide.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWSCOrderGuide { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a sc_cat_item_guide record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the sc_cat_item_guide table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCOrderGuide.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWSCOrderGuide -limit 1 -verbose 17 | Returns a single record from sc_cat_item_guide 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [alias('cascade_variables')] 24 | [boolean] 25 | $cascade, 26 | [Parameter()] 27 | [alias('show_include_toggle')] 28 | [boolean] 29 | $include_items, 30 | [Parameter()] 31 | [boolean] 32 | $order_to_cart, 33 | [Parameter()] 34 | [string] 35 | $script, 36 | [Parameter()] 37 | [boolean] 38 | $two_step, 39 | [Parameter()] 40 | [string] 41 | $validator 42 | ) 43 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 44 | 45 | Begin { 46 | $table = "sc_cat_item_guide" 47 | } 48 | Process { 49 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWSCRequest.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWSCRequest { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a servicenow Request 5 | .DESCRIPTION 6 | Gets a record from the sc_request table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCRequest.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWRequest -limit 1 -verbose 17 | Returns a single Request from the sc_request 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $made_sla, 25 | [Parameter()] 26 | [string] 27 | $requested_for, 28 | [Parameter()] 29 | [string] 30 | $number, 31 | [Parameter()] 32 | [string] 33 | $opened_by, 34 | [Parameter()] 35 | [string] 36 | $state, 37 | [Parameter()] 38 | [string] 39 | $impact, 40 | [Parameter()] 41 | [boolean] 42 | $active, 43 | [Parameter()] 44 | [string] 45 | $priority, 46 | [Parameter()] 47 | [string] 48 | $short_description, 49 | [Parameter()] 50 | [string] 51 | $assignment_group, 52 | [Parameter()] 53 | [string] 54 | $closed_by, 55 | [Parameter()] 56 | [string] 57 | $urgency, 58 | [Parameter()] 59 | [string] 60 | $company, 61 | [Parameter()] 62 | [string] 63 | $assigned_to, 64 | [Parameter()] 65 | [string] 66 | $approval, 67 | [Parameter()] 68 | [string] 69 | $request_state, 70 | [Parameter()] 71 | [string] 72 | $stage, 73 | [Parameter()] 74 | [string] 75 | $location 76 | ) 77 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 78 | 79 | Begin { 80 | $table = "sc_request" 81 | } 82 | Process { 83 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 84 | } 85 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWSCRequestedItem.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWSCRequestedItem { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a servicenow RITM record 5 | .DESCRIPTION 6 | Gets a record from the sc_req_item table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCRequestedItem.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWRequestedItem -limit 1 -verbose 17 | Returns a single RITM from the sc_req_item table 18 | #> 19 | 20 | [alias("Get-SNOWRITM")] 21 | [CmdletBinding()] 22 | param ( 23 | [Parameter()] 24 | [boolean] 25 | $active, 26 | [Parameter()] 27 | [string] 28 | $approval, 29 | [Parameter()] 30 | [string] 31 | $assigned_to, 32 | [Parameter()] 33 | [string] 34 | $assignment_group, 35 | [Parameter()] 36 | [string] 37 | $business_service, 38 | [Parameter()] 39 | [string] 40 | $cat_item, 41 | [Parameter()] 42 | [string] 43 | $closed_by, 44 | [Parameter()] 45 | [string] 46 | $company, 47 | [Parameter()] 48 | [string] 49 | $configuration_item, 50 | [Parameter()] 51 | [string] 52 | $impact, 53 | [Parameter()] 54 | [boolean] 55 | $made_sla, 56 | [Parameter()] 57 | [string] 58 | $number, 59 | [Parameter()] 60 | [string] 61 | $opened_by, 62 | [Parameter()] 63 | [string] 64 | $priority, 65 | [Parameter()] 66 | [string] 67 | $request, 68 | [Parameter()] 69 | [string] 70 | $requested_for, 71 | [Parameter()] 72 | [string] 73 | $short_description, 74 | [Parameter()] 75 | [string] 76 | $stage, 77 | [Parameter()] 78 | [string] 79 | $state, 80 | [Parameter()] 81 | [string] 82 | $urgency, 83 | [Parameter()] 84 | [string] 85 | $order_guide 86 | ) 87 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 88 | 89 | Begin { 90 | $table = "sc_req_item" 91 | } 92 | Process { 93 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 94 | } 95 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWSCTask.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWSCTask { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a servicenow Task 5 | .DESCRIPTION 6 | Gets a record from the sc_task table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWSCTask.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWTask -limit 1 -verbose 17 | Returns a single Task from the sc_task table 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $parent, 25 | [Parameter()] 26 | [boolean] 27 | $made_sla, 28 | [Parameter()] 29 | [string] 30 | $number, 31 | [Parameter()] 32 | [string] 33 | $opened_by, 34 | [Parameter()] 35 | [string] 36 | $state, 37 | [Parameter()] 38 | [string] 39 | $impact, 40 | [Parameter()] 41 | [boolean] 42 | $active, 43 | [Parameter()] 44 | [string] 45 | $priority, 46 | [Parameter()] 47 | [string] 48 | $request, 49 | [Parameter()] 50 | [string] 51 | $short_description, 52 | [Parameter()] 53 | [string] 54 | $delivery_task, 55 | [Parameter()] 56 | [string] 57 | $assignment_group, 58 | [Parameter()] 59 | [string] 60 | $closed_by, 61 | [Parameter()] 62 | [string] 63 | $urgency, 64 | [Parameter()] 65 | [string] 66 | $company, 67 | [Parameter()] 68 | [string] 69 | $assigned_to, 70 | [Parameter()] 71 | [string] 72 | $approval, 73 | [Parameter()] 74 | [string] 75 | $request_item 76 | ) 77 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 78 | 79 | Begin { 80 | $table = "sc_task" 81 | } 82 | Process { 83 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 84 | } 85 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWTask.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWTask { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a task record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the task table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWTask.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWTask -limit 1 -verbose 17 | Returns a single record from task 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $active, 25 | [Parameter()] 26 | [string] 27 | $approval, 28 | [Parameter()] 29 | [string] 30 | $assigned_to, 31 | [Parameter()] 32 | [string] 33 | $assignment_group, 34 | [Parameter()] 35 | [alias('service')] 36 | [string] 37 | $business_service, 38 | [Parameter()] 39 | [string] 40 | $closed_by, 41 | [Parameter()] 42 | [string] 43 | $close_notes, 44 | [Parameter()] 45 | [alias('configuration_item')] 46 | [string] 47 | $cmdb_ci, 48 | [Parameter()] 49 | [alias('additional_comments')] 50 | [string] 51 | $comments, 52 | [Parameter()] 53 | [string] 54 | $comments_and_work_notes, 55 | [Parameter()] 56 | [string] 57 | $company, 58 | [Parameter()] 59 | [string] 60 | $contact_type, 61 | [Parameter()] 62 | [string] 63 | $contract, 64 | [Parameter()] 65 | [string] 66 | $delivery_plan, 67 | [Parameter()] 68 | [string] 69 | $delivery_task, 70 | [Parameter()] 71 | [string] 72 | $description, 73 | [Parameter()] 74 | [string] 75 | $escalation, 76 | [Parameter()] 77 | [string] 78 | $impact, 79 | [Parameter()] 80 | [string] 81 | $location, 82 | [Parameter()] 83 | [boolean] 84 | $made_sla, 85 | [Parameter()] 86 | [string] 87 | $number, 88 | [Parameter()] 89 | [string] 90 | $opened_by, 91 | [Parameter()] 92 | [string] 93 | $order, 94 | [Parameter()] 95 | [string] 96 | $parent, 97 | [Parameter()] 98 | [string] 99 | $priority, 100 | [Parameter()] 101 | [string] 102 | $reassignment_count, 103 | [Parameter()] 104 | [alias('transfer_reason')] 105 | [string] 106 | $route_reason, 107 | [Parameter()] 108 | [string] 109 | $service_offering, 110 | [Parameter()] 111 | [string] 112 | $short_description, 113 | [Parameter()] 114 | [string] 115 | $state, 116 | [Parameter()] 117 | [string] 118 | $urgency 119 | ) 120 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 121 | 122 | Begin { 123 | $table = "task" 124 | } 125 | Process { 126 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 127 | } 128 | } 129 | 130 | -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWUser.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWUser { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a sys_user record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the sys_user table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWUser.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWUser -limit 1 -verbose 17 | Returns a single record from sys_user 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $active, 25 | [Parameter()] 26 | [string] 27 | $building, 28 | [Parameter()] 29 | [string] 30 | $city, 31 | [Parameter()] 32 | [string] 33 | $company, 34 | [Parameter()] 35 | [string] 36 | $cost_center, 37 | [Parameter()] 38 | [alias('country_code')] 39 | [string] 40 | $country, 41 | [Parameter()] 42 | [string] 43 | $department, 44 | [Parameter()] 45 | [string] 46 | $email, 47 | [Parameter()] 48 | [string] 49 | $employee_number, 50 | [Parameter()] 51 | [alias('enable_multifactor_authentication')] 52 | [boolean] 53 | $enable_multifactor_authn, 54 | [Parameter()] 55 | [alias('failed_login_attempts')] 56 | [string] 57 | $failed_attempts, 58 | [Parameter()] 59 | [string] 60 | $first_name, 61 | [Parameter()] 62 | [string] 63 | $gender, 64 | [Parameter()] 65 | [string] 66 | $home_phone, 67 | [Parameter()] 68 | [boolean] 69 | $internal_integration_user, 70 | [Parameter()] 71 | [alias('prefix')] 72 | [string] 73 | $introduction, 74 | [Parameter()] 75 | [string] 76 | $last_name, 77 | [Parameter()] 78 | [string] 79 | $ldap_server, 80 | [Parameter()] 81 | [string] 82 | $location, 83 | [Parameter()] 84 | [boolean] 85 | $locked_out, 86 | [Parameter()] 87 | [string] 88 | $manager, 89 | [Parameter()] 90 | [string] 91 | $middle_name, 92 | [Parameter()] 93 | [string] 94 | $mobile_phone, 95 | [Parameter()] 96 | [string] 97 | $name, 98 | [Parameter()] 99 | [string] 100 | $notification, 101 | [Parameter()] 102 | [boolean] 103 | $password_needs_reset, 104 | [Parameter()] 105 | [alias('business_phone')] 106 | [string] 107 | $phone, 108 | [Parameter()] 109 | [string] 110 | $photo, 111 | [Parameter()] 112 | [alias('language')] 113 | [string] 114 | $preferred_language, 115 | [Parameter()] 116 | [string] 117 | $roles, 118 | [Parameter()] 119 | [string] 120 | $schedule, 121 | [Parameter()] 122 | [string] 123 | $source, 124 | [Parameter()] 125 | [alias('state___province')] 126 | [string] 127 | $state, 128 | [Parameter()] 129 | [string] 130 | $street, 131 | [Parameter()] 132 | [string] 133 | $time_format, 134 | [Parameter()] 135 | [string] 136 | $time_zone, 137 | [Parameter()] 138 | [string] 139 | $title, 140 | [Parameter()] 141 | [alias('user_id')] 142 | [string] 143 | $user_name, 144 | [Parameter()] 145 | [boolean] 146 | $vip, 147 | [Parameter()] 148 | [boolean] 149 | $web_service_access_only, 150 | [Parameter()] 151 | [alias('zip___postal_code')] 152 | [string] 153 | $zip 154 | ) 155 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 156 | 157 | Begin { 158 | $table = "sys_user" 159 | } 160 | Process { 161 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 162 | } 163 | } -------------------------------------------------------------------------------- /src/Public/table/Get-SNOWUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-SNOWUserGroup { 2 | <# 3 | .SYNOPSIS 4 | Retrieves a sys_user_group record from SNOW 5 | .DESCRIPTION 6 | Gets a record from the sys_user_group table 7 | .NOTES 8 | Uses Get-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Get-SNOWUserGroup.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Get-SNOWUserGroup -limit 1 -verbose 17 | Returns a single record from sys_user_group 18 | #> 19 | 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $active, 25 | [Parameter()] 26 | [string] 27 | $cost_center, 28 | [Parameter()] 29 | [string] 30 | $default_assignee, 31 | [Parameter()] 32 | [string] 33 | $description, 34 | [Parameter()] 35 | [alias('group_email')] 36 | [string] 37 | $email, 38 | [Parameter()] 39 | [boolean] 40 | $exclude_manager, 41 | [Parameter()] 42 | [boolean] 43 | $include_members, 44 | [Parameter()] 45 | [string] 46 | $manager, 47 | [Parameter()] 48 | [string] 49 | $name, 50 | [Parameter()] 51 | [string] 52 | $parent, 53 | [Parameter()] 54 | [string] 55 | $roles, 56 | [Parameter()] 57 | [string] 58 | $source, 59 | [Parameter()] 60 | [string] 61 | $type 62 | ) 63 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Get-SNOWObject" } 64 | 65 | Begin { 66 | $table = "sys_user_group" 67 | } 68 | Process { 69 | Invoke-SNOWTableREAD -table $table -Parameters $PSBoundParameters 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/Public/table/New-SNOWDepartment.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWDepartment { 2 | <# 3 | .SYNOPSIS 4 | Creates a cmn_department record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the cmn_department table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWDepartment.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | New-SNOWDepartment -Properties @{""=""} -PassThru 17 | Creates a single record in cmn_department and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $business_unit, 25 | [Parameter()] 26 | [string] 27 | $company, 28 | [Parameter()] 29 | [string] 30 | $cost_center, 31 | [Parameter()] 32 | [alias('department_head')] 33 | [string] 34 | $dept_head, 35 | [Parameter()] 36 | [string] 37 | $description, 38 | [Parameter()] 39 | [string] 40 | $head_count, 41 | [Parameter()] 42 | [string] 43 | $id, 44 | [Parameter()] 45 | [string] 46 | $name, 47 | [Parameter()] 48 | [string] 49 | $parent, 50 | [Parameter()] 51 | [string] 52 | $primary_contact 53 | ) 54 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 55 | 56 | Begin { 57 | $table = "cmn_department" 58 | } 59 | Process { 60 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/Public/table/New-SNOWLocation.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWLocation { 2 | <# 3 | .SYNOPSIS 4 | Creates a cmn_location record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the cmn_location table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWLocation.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | New-SNOWLocation -Properties @{""=""} -PassThru 17 | Creates a single record in cmn_location and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $city, 25 | [Parameter()] 26 | [alias('location_source')] 27 | [string] 28 | $cmn_location_source, 29 | [Parameter()] 30 | [alias('location_type')] 31 | [string] 32 | $cmn_location_type, 33 | [Parameter()] 34 | [string] 35 | $company, 36 | [Parameter()] 37 | [string] 38 | $contact, 39 | [Parameter()] 40 | [string] 41 | $coordinates_retrieved_on, 42 | [Parameter()] 43 | [string] 44 | $country, 45 | [Parameter()] 46 | [boolean] 47 | $duplicate, 48 | [Parameter()] 49 | [string] 50 | $fax_phone, 51 | [Parameter()] 52 | [string] 53 | $full_name, 54 | [Parameter()] 55 | [string] 56 | $latitude, 57 | [Parameter()] 58 | [string] 59 | $lat_long_error, 60 | [Parameter()] 61 | [string] 62 | $life_cycle_stage, 63 | [Parameter()] 64 | [string] 65 | $life_cycle_stage_status, 66 | [Parameter()] 67 | [string] 68 | $longitude, 69 | [Parameter()] 70 | [string] 71 | $managed_by_group, 72 | [Parameter()] 73 | [string] 74 | $name, 75 | [Parameter()] 76 | [string] 77 | $parent, 78 | [Parameter()] 79 | [string] 80 | $phone, 81 | [Parameter()] 82 | [string] 83 | $phone_territory, 84 | [Parameter()] 85 | [string] 86 | $primary_location, 87 | [Parameter()] 88 | [alias('state___province')] 89 | [string] 90 | $state, 91 | [Parameter()] 92 | [boolean] 93 | $stock_room, 94 | [Parameter()] 95 | [string] 96 | $street, 97 | [Parameter()] 98 | [string] 99 | $time_zone, 100 | [Parameter()] 101 | [alias('zip___postal_code')] 102 | [string] 103 | $zip 104 | ) 105 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 106 | 107 | Begin { 108 | $table = "cmn_location" 109 | } 110 | Process { 111 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/Public/table/New-SNOWObject.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWObject { 2 | <# 3 | .SYNOPSIS 4 | Creates a new servicenow table record 5 | .DESCRIPTION 6 | Creates a record in the specified table 7 | .OUTPUTS 8 | PSCustomObject. The full table record (requires -PassThru). 9 | .LINK 10 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWObject.md 11 | .LINK 12 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 13 | .EXAMPLE 14 | $Properties = @{ 15 | user_name = "bruce.wayne" 16 | title = "Director" 17 | first_name = "Bruce" 18 | last_name = "Wayne" 19 | department = "Finance" 20 | email = "Bruce@WayneIndustries.com" 21 | } 22 | New-SNOWObject -Table 'sys_user' -Properties $Properties -PassThru 23 | Creates a new user called bruce wayne in the sys_user table 24 | #> 25 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 26 | [CmdletBinding(SupportsShouldProcess)] 27 | param ( 28 | [Parameter(Mandatory)] 29 | [ValidateNotNullOrEmpty()] 30 | [string] 31 | $Table, 32 | [Parameter()] 33 | [hashtable] 34 | # Keys must exactly match the names in the snow table. Not the display values in the web front end. Case sensitive. 35 | $Properties, 36 | [Parameter()] 37 | [switch] 38 | # This flag is required when setting encrypted fields (e.g user_password) 39 | $InputDisplayValue, 40 | [Parameter()] 41 | [switch] 42 | $PassThru, 43 | [Parameter(DontShow)] 44 | [switch] 45 | $AsBatchRequest 46 | ) 47 | 48 | Process { 49 | Invoke-SNOWTableCREATE -table $Table -Parameters $PSBoundParameters 50 | } 51 | } -------------------------------------------------------------------------------- /src/Public/table/New-SNOWSCRequest.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWSCRequest { 2 | <# 3 | .SYNOPSIS 4 | Creates a sc_request record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the sc_request table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWSCRequest.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | New-SNOWSCRequest -Properties @{""=""} -PassThru 17 | Creates a single record in sc_request and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $delivery_address, 25 | [Parameter()] 26 | [alias('requested_for_date')] 27 | [string] 28 | $requested_date, 29 | [Parameter()] 30 | [string] 31 | $requested_for, 32 | [Parameter()] 33 | [string] 34 | $request_state, 35 | [Parameter()] 36 | [string] 37 | $special_instructions, 38 | [Parameter()] 39 | [string] 40 | $stage, 41 | [Parameter()] 42 | [boolean] 43 | $active, 44 | [Parameter()] 45 | [string] 46 | $activity_due, 47 | [Parameter()] 48 | [string] 49 | $additional_assignee_list, 50 | [Parameter()] 51 | [string] 52 | $approval, 53 | [Parameter()] 54 | [string] 55 | $approval_set, 56 | [Parameter()] 57 | [string] 58 | $assigned_to, 59 | [Parameter()] 60 | [string] 61 | $assignment_group, 62 | [Parameter()] 63 | [alias('service')] 64 | [string] 65 | $business_service, 66 | [Parameter()] 67 | [alias('configuration_item')] 68 | [string] 69 | $cmdb_ci, 70 | [Parameter()] 71 | [alias('additional_comments')] 72 | [string] 73 | $comments, 74 | [Parameter()] 75 | [string] 76 | $comments_and_work_notes, 77 | [Parameter()] 78 | [string] 79 | $company, 80 | [Parameter()] 81 | [string] 82 | $delivery_plan, 83 | [Parameter()] 84 | [string] 85 | $delivery_task, 86 | [Parameter()] 87 | [string] 88 | $description, 89 | [Parameter()] 90 | [string] 91 | $due_date, 92 | [Parameter()] 93 | [string] 94 | $expected_start, 95 | [Parameter()] 96 | [string] 97 | $follow_up, 98 | [Parameter()] 99 | [string] 100 | $group_list, 101 | [Parameter()] 102 | [string] 103 | $impact, 104 | [Parameter()] 105 | [boolean] 106 | $made_sla, 107 | [Parameter()] 108 | [alias('opened')] 109 | [string] 110 | $opened_at, 111 | [Parameter()] 112 | [string] 113 | $opened_by, 114 | [Parameter()] 115 | [string] 116 | $parent, 117 | [Parameter()] 118 | [string] 119 | $priority, 120 | [Parameter()] 121 | [string] 122 | $service_offering, 123 | [Parameter()] 124 | [string] 125 | $short_description, 126 | [Parameter()] 127 | [string] 128 | $sla_due, 129 | [Parameter()] 130 | [string] 131 | $state, 132 | [Parameter()] 133 | [string] 134 | $urgency, 135 | [Parameter()] 136 | [string] 137 | $user_input, 138 | [Parameter()] 139 | [string] 140 | $watch_list, 141 | [Parameter()] 142 | [alias('actual_end')] 143 | [string] 144 | $work_end, 145 | [Parameter()] 146 | [string] 147 | $work_notes, 148 | [Parameter()] 149 | [string] 150 | $work_notes_list, 151 | [Parameter()] 152 | [alias('actual_start')] 153 | [string] 154 | $work_start 155 | ) 156 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 157 | 158 | Begin { 159 | $table = "sc_request" 160 | } 161 | Process { 162 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 163 | } 164 | } 165 | 166 | -------------------------------------------------------------------------------- /src/Public/table/New-SNOWSCTask.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWSCTask { 2 | <# 3 | .SYNOPSIS 4 | Creates a sc_task record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the sc_task table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWSCTask.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | New-SNOWSCTask -Properties @{""=""} -PassThru 17 | Creates a single record in sc_task and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $request_item, 25 | [Parameter()] 26 | [boolean] 27 | $active, 28 | [Parameter()] 29 | [string] 30 | $activity_due, 31 | [Parameter()] 32 | [string] 33 | $additional_assignee_list, 34 | [Parameter()] 35 | [string] 36 | $approval, 37 | [Parameter()] 38 | [string] 39 | $approval_set, 40 | [Parameter()] 41 | [string] 42 | $assigned_to, 43 | [Parameter()] 44 | [string] 45 | $assignment_group, 46 | [Parameter()] 47 | [alias('service')] 48 | [string] 49 | $business_service, 50 | [Parameter()] 51 | [alias('configuration_item')] 52 | [string] 53 | $cmdb_ci, 54 | [Parameter()] 55 | [alias('additional_comments')] 56 | [string] 57 | $comments, 58 | [Parameter()] 59 | [string] 60 | $comments_and_work_notes, 61 | [Parameter()] 62 | [string] 63 | $delivery_plan, 64 | [Parameter()] 65 | [string] 66 | $delivery_task, 67 | [Parameter()] 68 | [string] 69 | $description, 70 | [Parameter()] 71 | [string] 72 | $due_date, 73 | [Parameter()] 74 | [string] 75 | $expected_start, 76 | [Parameter()] 77 | [string] 78 | $follow_up, 79 | [Parameter()] 80 | [string] 81 | $group_list, 82 | [Parameter()] 83 | [string] 84 | $impact, 85 | [Parameter()] 86 | [boolean] 87 | $made_sla, 88 | [Parameter()] 89 | [alias('opened')] 90 | [string] 91 | $opened_at, 92 | [Parameter()] 93 | [string] 94 | $opened_by, 95 | [Parameter()] 96 | [string] 97 | $parent, 98 | [Parameter()] 99 | [string] 100 | $priority, 101 | [Parameter()] 102 | [string] 103 | $service_offering, 104 | [Parameter()] 105 | [string] 106 | $short_description, 107 | [Parameter()] 108 | [string] 109 | $sla_due, 110 | [Parameter()] 111 | [string] 112 | $state, 113 | [Parameter()] 114 | [string] 115 | $urgency, 116 | [Parameter()] 117 | [string] 118 | $user_input, 119 | [Parameter()] 120 | [string] 121 | $watch_list, 122 | [Parameter()] 123 | [alias('actual_end')] 124 | [string] 125 | $work_end, 126 | [Parameter()] 127 | [string] 128 | $work_notes, 129 | [Parameter()] 130 | [string] 131 | $work_notes_list, 132 | [Parameter()] 133 | [alias('actual_start')] 134 | [string] 135 | $work_start 136 | ) 137 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 138 | 139 | Begin { 140 | $table = "sc_task" 141 | } 142 | Process { 143 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/Public/table/New-SNOWTask.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWTask { 2 | <# 3 | .SYNOPSIS 4 | Creates a task record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the task table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWTask.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | New-SNOWTask -Properties @{""=""} -PassThru 17 | Creates a single record in task and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $active, 25 | [Parameter()] 26 | [string] 27 | $activity_due, 28 | [Parameter()] 29 | [string] 30 | $additional_assignee_list, 31 | [Parameter()] 32 | [string] 33 | $approval, 34 | [Parameter()] 35 | [string] 36 | $approval_history, 37 | [Parameter()] 38 | [string] 39 | $approval_set, 40 | [Parameter()] 41 | [string] 42 | $assigned_to, 43 | [Parameter()] 44 | [string] 45 | $assignment_group, 46 | [Parameter()] 47 | [alias('service')] 48 | [string] 49 | $business_service, 50 | [Parameter()] 51 | [alias('configuration_item')] 52 | [string] 53 | $cmdb_ci, 54 | [Parameter()] 55 | [alias('additional_comments')] 56 | [string] 57 | $comments, 58 | [Parameter()] 59 | [string] 60 | $comments_and_work_notes, 61 | [Parameter()] 62 | [string] 63 | $delivery_plan, 64 | [Parameter()] 65 | [string] 66 | $delivery_task, 67 | [Parameter()] 68 | [string] 69 | $description, 70 | [Parameter()] 71 | [string] 72 | $due_date, 73 | [Parameter()] 74 | [string] 75 | $expected_start, 76 | [Parameter()] 77 | [string] 78 | $follow_up, 79 | [Parameter()] 80 | [string] 81 | $group_list, 82 | [Parameter()] 83 | [string] 84 | $impact, 85 | [Parameter()] 86 | [boolean] 87 | $made_sla, 88 | [Parameter()] 89 | [alias('opened')] 90 | [string] 91 | $opened_at, 92 | [Parameter()] 93 | [string] 94 | $opened_by, 95 | [Parameter()] 96 | [string] 97 | $order, 98 | [Parameter()] 99 | [string] 100 | $parent, 101 | [Parameter()] 102 | [string] 103 | $priority, 104 | [Parameter()] 105 | [string] 106 | $service_offering, 107 | [Parameter()] 108 | [string] 109 | $short_description, 110 | [Parameter()] 111 | [string] 112 | $sla_due, 113 | [Parameter()] 114 | [string] 115 | $state, 116 | [Parameter()] 117 | [string] 118 | $urgency, 119 | [Parameter()] 120 | [string] 121 | $watch_list, 122 | [Parameter()] 123 | [alias('actual_end')] 124 | [string] 125 | $work_end, 126 | [Parameter()] 127 | [string] 128 | $work_notes, 129 | [Parameter()] 130 | [string] 131 | $work_notes_list, 132 | [Parameter()] 133 | [alias('actual_start')] 134 | [string] 135 | $work_start 136 | ) 137 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 138 | 139 | Begin { 140 | $table = "task" 141 | } 142 | Process { 143 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/Public/table/New-SNOWUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function New-SNOWUserGroup { 2 | <# 3 | .SYNOPSIS 4 | Creates a sys_user_group record in SNOW 5 | .DESCRIPTION 6 | Creates a record in the sys_user_group table 7 | .NOTES 8 | Uses New-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/New-SNOWUserGroup.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | New-SNOWUserGroup -Properties @{""=""} -PassThru 17 | Creates a single record in sys_user_group and returns the new record with SysID 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $active, 25 | [Parameter()] 26 | [string] 27 | $cost_center, 28 | [Parameter()] 29 | [string] 30 | $default_assignee, 31 | [Parameter()] 32 | [string] 33 | $description, 34 | [Parameter()] 35 | [alias('group_email')] 36 | [string] 37 | $email, 38 | [Parameter()] 39 | [boolean] 40 | $exclude_manager, 41 | [Parameter()] 42 | [boolean] 43 | $include_members, 44 | [Parameter()] 45 | [string] 46 | $manager, 47 | [Parameter()] 48 | [string] 49 | $name, 50 | [Parameter()] 51 | [string] 52 | $parent, 53 | [Parameter()] 54 | [string] 55 | $roles, 56 | [Parameter()] 57 | [string] 58 | $source, 59 | [Parameter()] 60 | [string] 61 | $type 62 | ) 63 | DynamicParam { Import-DefaultParamSet -TemplateFunction "New-SNOWObject" } 64 | 65 | Begin { 66 | $table = "sys_user_group" 67 | } 68 | Process { 69 | Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundParameters 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/Public/table/Remove-SNOWDepartment.ps1: -------------------------------------------------------------------------------- 1 | function Remove-SNOWDepartment { 2 | <# 3 | .SYNOPSIS 4 | Removes a cmn_department record in SNOW 5 | .DESCRIPTION 6 | Removes a record from the cmn_department table 7 | .NOTES 8 | Uses Remove-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWDepartment.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Remove-SNOWDepartment -Sys_ID "" 17 | Removes a specific record in the table cmn_department 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] 21 | param () 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Remove-SNOWObject" } 23 | 24 | Begin { 25 | $table = "cmn_department" 26 | } 27 | Process { 28 | Invoke-SNOWTableDELETE -table $table -Parameters $PSBoundParameters 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Public/table/Remove-SNOWLocation.ps1: -------------------------------------------------------------------------------- 1 | function Remove-SNOWLocation { 2 | <# 3 | .SYNOPSIS 4 | Removes a cmn_location record in SNOW 5 | .DESCRIPTION 6 | Removes a record from the cmn_location table 7 | .NOTES 8 | Uses Remove-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWLocation.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Remove-SNOWLocation -Sys_ID "" 17 | Removes a specific record in the table cmn_location 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] 21 | param () 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Remove-SNOWObject" } 23 | 24 | Begin { 25 | $table = "cmn_location" 26 | } 27 | Process { 28 | Invoke-SNOWTableDELETE -table $table -Parameters $PSBoundParameters 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Public/table/Remove-SNOWObject.ps1: -------------------------------------------------------------------------------- 1 | function Remove-SNOWObject { 2 | <# 3 | .SYNOPSIS 4 | Removes a new servicenow record in the specified table 5 | .DESCRIPTION 6 | Removes a new servicenow record in the specified table 7 | .LINK 8 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWObject.md 9 | .LINK 10 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 11 | .EXAMPLE 12 | Remove-SNOWObject -table "sys_user" -sys_id "02826bf03710200044e0bfc8bcbe5d3f" -confirm:$false 13 | Removes the specified user with the matching sys_id from the sys_user table and bypasses confirmation 14 | .EXAMPLE 15 | Get-SNOWUser -user_name 'bruce.wayne9' -limit 1 | Remove-SNOWObject -table 'sys_user' 16 | Removes the specified user with the matching sys_id from the sys_user table, after prompt confirmation 17 | #> 18 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 19 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] 20 | param ( 21 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 22 | [ValidateScript({ $_ | Confirm-SysID -ValidateScript })] 23 | [string] 24 | $Sys_ID, 25 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 26 | [ValidateNotNullOrEmpty()] 27 | [alias("sys_class_name")] 28 | [string] 29 | $Table, 30 | [Parameter()] 31 | [switch] 32 | $RestrictDomain = $false 33 | ) 34 | 35 | Process { 36 | if($sys_class_name){ 37 | $Table = $sys_class_name 38 | } 39 | Invoke-SNOWTableDELETE -table $Table -Parameters $PSBoundParameters 40 | } 41 | } -------------------------------------------------------------------------------- /src/Public/table/Remove-SNOWUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Remove-SNOWUserGroup { 2 | <# 3 | .SYNOPSIS 4 | Removes a sys_user_group record in SNOW 5 | .DESCRIPTION 6 | Removes a record from the sys_user_group table 7 | .NOTES 8 | Uses Remove-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Remove-SNOWUserGroup.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Remove-SNOWUserGroup -Sys_ID "" 17 | Removes a specific record in the table sys_user_group 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] 21 | param () 22 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Remove-SNOWObject" } 23 | 24 | Begin { 25 | $table = "sys_user_group" 26 | } 27 | Process { 28 | Invoke-SNOWTableDELETE -table $table -Parameters $PSBoundParameters 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/Public/table/Set-SNOWApprover.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWApprover { 2 | <# 3 | .SYNOPSIS 4 | Updates a sysapproval_approver record in SNOW 5 | .DESCRIPTION 6 | Updates a record from the sysapproval_approver table 7 | .NOTES 8 | Uses Set-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s. 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWApprover.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Set-SNOWApprover -Sys_ID "" -Properties @{""=""} -verbose 17 | Updates a specific record in the table sysapproval_approver 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $approver, 25 | [Parameter()] 26 | [string] 27 | $comments, 28 | [Parameter()] 29 | [string] 30 | $document_id, 31 | [Parameter()] 32 | [string] 33 | $due_date, 34 | [Parameter()] 35 | [string] 36 | $expected_start, 37 | [Parameter()] 38 | [string] 39 | $group, 40 | [Parameter()] 41 | [string] 42 | $source_table, 43 | [Parameter()] 44 | [string] 45 | $state, 46 | [Parameter()] 47 | [string] 48 | $sysapproval 49 | ) 50 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" } 51 | 52 | Begin { 53 | $table = "sysapproval_approver" 54 | } 55 | Process { 56 | Invoke-SNOWTableUPDATE -table $table -Parameters $PSBoundParameters 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/Public/table/Set-SNOWDepartment.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWDepartment { 2 | <# 3 | .SYNOPSIS 4 | Updates a cmn_department record in SNOW 5 | .DESCRIPTION 6 | Updates a record from the cmn_department table 7 | .NOTES 8 | Uses Set-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWDepartment.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Set-SNOWDepartment -Sys_ID "" -Properties @{""=""} -verbose 17 | Updates a specific record in the table cmn_department 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $business_unit, 25 | [Parameter()] 26 | [string] 27 | $company, 28 | [Parameter()] 29 | [string] 30 | $cost_center, 31 | [Parameter()] 32 | [alias('department_head')] 33 | [string] 34 | $dept_head, 35 | [Parameter()] 36 | [string] 37 | $description, 38 | [Parameter()] 39 | [string] 40 | $head_count, 41 | [Parameter()] 42 | [string] 43 | $id, 44 | [Parameter()] 45 | [string] 46 | $name, 47 | [Parameter()] 48 | [string] 49 | $parent, 50 | [Parameter()] 51 | [string] 52 | $primary_contact 53 | ) 54 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" } 55 | 56 | Begin { 57 | $table = "cmn_department" 58 | } 59 | Process { 60 | Invoke-SNOWTableUPDATE -table $table -Parameters $PSBoundParameters 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/Public/table/Set-SNOWLocation.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWLocation { 2 | <# 3 | .SYNOPSIS 4 | Updates a cmn_location record in SNOW 5 | .DESCRIPTION 6 | Updates a record from the cmn_location table 7 | .NOTES 8 | Uses Set-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWLocation.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Set-SNOWLocation -Sys_ID "" -Properties @{""=""} -verbose 17 | Updates a specific record in the table cmn_location 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [string] 24 | $city, 25 | [Parameter()] 26 | [alias('location_source')] 27 | [string] 28 | $cmn_location_source, 29 | [Parameter()] 30 | [alias('location_type')] 31 | [string] 32 | $cmn_location_type, 33 | [Parameter()] 34 | [string] 35 | $company, 36 | [Parameter()] 37 | [string] 38 | $contact, 39 | [Parameter()] 40 | [string] 41 | $coordinates_retrieved_on, 42 | [Parameter()] 43 | [string] 44 | $country, 45 | [Parameter()] 46 | [boolean] 47 | $duplicate, 48 | [Parameter()] 49 | [string] 50 | $fax_phone, 51 | [Parameter()] 52 | [string] 53 | $full_name, 54 | [Parameter()] 55 | [string] 56 | $latitude, 57 | [Parameter()] 58 | [string] 59 | $lat_long_error, 60 | [Parameter()] 61 | [string] 62 | $life_cycle_stage, 63 | [Parameter()] 64 | [string] 65 | $life_cycle_stage_status, 66 | [Parameter()] 67 | [string] 68 | $longitude, 69 | [Parameter()] 70 | [string] 71 | $managed_by_group, 72 | [Parameter()] 73 | [string] 74 | $name, 75 | [Parameter()] 76 | [string] 77 | $parent, 78 | [Parameter()] 79 | [string] 80 | $phone, 81 | [Parameter()] 82 | [string] 83 | $phone_territory, 84 | [Parameter()] 85 | [string] 86 | $primary_location, 87 | [Parameter()] 88 | [alias('state___province')] 89 | [string] 90 | $state, 91 | [Parameter()] 92 | [boolean] 93 | $stock_room, 94 | [Parameter()] 95 | [string] 96 | $street, 97 | [Parameter()] 98 | [string] 99 | $time_zone, 100 | [Parameter()] 101 | [alias('zip___postal_code')] 102 | [string] 103 | $zip 104 | ) 105 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" } 106 | 107 | Begin { 108 | $table = "cmn_location" 109 | } 110 | Process { 111 | Invoke-SNOWTableUPDATE -table $table -Parameters $PSBoundParameters 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/Public/table/Set-SNOWObject.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWObject { 2 | <# 3 | .SYNOPSIS 4 | Updates a new servicenow record 5 | .DESCRIPTION 6 | Updates a record in the specified table 7 | .OUTPUTS 8 | PSCustomObject. The full table record (requires -PassThru). 9 | .LINK 10 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWObject.md 11 | .LINK 12 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 13 | .EXAMPLE 14 | Get-SNOWObject -table "sys_user" -query "user_name=bruce.wayne^active=true" | Set-SNOWObject -table "sys_user" -middle_name "Thomas" 15 | Updates the middle_name of the user record bruce.wayne in the sys_user table 16 | .EXAMPLE 17 | Set-SNOWObject -table "sys_user" -sys_id '02826bf03710200044e0bfc8bcbe5d3f' -properties @{middle_name="Thomas"} 18 | Updates the middle_name of the user record bruce.wayne in the sys_user table 19 | #> 20 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')] 21 | [CmdletBinding(SupportsShouldProcess)] 22 | param ( 23 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 24 | [ValidateNotNullOrEmpty()] 25 | [alias("sys_class_name")] 26 | [string] 27 | $Table, 28 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 29 | [ValidateScript({ 30 | Confirm-SysID -Sys_ID $_ -ValidateScript 31 | })] 32 | [string] 33 | [alias('SysID')] 34 | $Sys_ID, 35 | [Parameter()] 36 | [hashtable] 37 | $Properties, 38 | [Parameter()] 39 | [switch] 40 | $InputDisplayValue, 41 | [Parameter()] 42 | [switch] 43 | $PassThru, 44 | [Parameter(DontShow)] 45 | [switch] 46 | $AsBatchRequest 47 | ) 48 | 49 | Process { 50 | Invoke-SNOWTableUPDATE -table $Table -Parameters $PSBoundParameters 51 | } 52 | } -------------------------------------------------------------------------------- /src/Public/table/Set-SNOWUser.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWUser { 2 | <# 3 | .SYNOPSIS 4 | Updates a sys_user record in SNOW 5 | .DESCRIPTION 6 | Updates a record from the sys_user table 7 | .NOTES 8 | Uses Set-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWUser.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Set-SNOWUser -Sys_ID "" -Properties @{""=""} -verbose 17 | Updates a specific record in the table sys_user 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] 20 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUsernameAndPasswordParams', '')] 21 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 22 | [CmdletBinding(SupportsShouldProcess)] 23 | param ( 24 | [Parameter()] 25 | [boolean] 26 | $active, 27 | [Parameter()] 28 | [string] 29 | $building, 30 | [Parameter()] 31 | [string] 32 | $city, 33 | [Parameter()] 34 | [string] 35 | $company, 36 | [Parameter()] 37 | [string] 38 | $cost_center, 39 | [Parameter()] 40 | [alias('country_code')] 41 | [string] 42 | $country, 43 | [Parameter()] 44 | [string] 45 | $department, 46 | [Parameter()] 47 | [string] 48 | $email, 49 | [Parameter()] 50 | [string] 51 | $employee_number, 52 | [Parameter()] 53 | [alias('enable_multifactor_authentication')] 54 | [boolean] 55 | $enable_multifactor_authn, 56 | [Parameter()] 57 | [string] 58 | $first_name, 59 | [Parameter()] 60 | [string] 61 | $gender, 62 | [Parameter()] 63 | [string] 64 | $home_phone, 65 | [Parameter()] 66 | [alias('prefix')] 67 | [string] 68 | $introduction, 69 | [Parameter()] 70 | [string] 71 | $last_name, 72 | [Parameter()] 73 | [string] 74 | $location, 75 | [Parameter()] 76 | [boolean] 77 | $locked_out, 78 | [Parameter()] 79 | [string] 80 | $manager, 81 | [Parameter()] 82 | [string] 83 | $middle_name, 84 | [Parameter()] 85 | [string] 86 | $mobile_phone, 87 | [Parameter()] 88 | [string] 89 | $name, 90 | [Parameter()] 91 | [string] 92 | $notification, 93 | [Parameter()] 94 | [boolean] 95 | $password_needs_reset, 96 | [Parameter()] 97 | [alias('business_phone')] 98 | [string] 99 | $phone, 100 | [Parameter()] 101 | [alias('language')] 102 | [string] 103 | $preferred_language, 104 | [Parameter()] 105 | [alias('province')] 106 | [string] 107 | $state, 108 | [Parameter()] 109 | [string] 110 | $street, 111 | [Parameter()] 112 | [string] 113 | $title, 114 | [Parameter()] 115 | [alias('user_id')] 116 | [string] 117 | $user_name, 118 | [Parameter()] 119 | [alias('password')] 120 | [string] 121 | $user_password, 122 | [Parameter()] 123 | [boolean] 124 | $vip, 125 | [Parameter()] 126 | [boolean] 127 | $web_service_access_only, 128 | [Parameter()] 129 | [alias('zip___postal_code')] 130 | [string] 131 | $zip 132 | ) 133 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" } 134 | 135 | Begin { 136 | $table = "sys_user" 137 | } 138 | Process { 139 | if($PSBoundParameters.ContainsKey('user_password') -and -not $PSBoundParameters.ContainsKey('InputDisplayValue')){ 140 | # This is required for setting encrypted fields 141 | $PSBoundParameters.add('InputDisplayValue',$True) 142 | } 143 | 144 | Invoke-SNOWTableUPDATE -table $table -Parameters $PSBoundParameters 145 | } 146 | } -------------------------------------------------------------------------------- /src/Public/table/Set-SNOWUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Set-SNOWUserGroup { 2 | <# 3 | .SYNOPSIS 4 | Updates a sys_user_group record in SNOW 5 | .DESCRIPTION 6 | Updates a record from the sys_user_group table 7 | .NOTES 8 | Uses Set-SNOWObject as a template function. 9 | .OUTPUTS 10 | PSCustomObject. The full table record/s (-PassThru only). 11 | .LINK 12 | https://github.com/insomniacc/PSSnow/blob/main/docs/functions/Set-SNOWUserGroup.md 13 | .LINK 14 | https://docs.servicenow.com/csh?topicname=c_TableAPI.html&version=latest 15 | .EXAMPLE 16 | Set-SNOWUserGroup -Sys_ID "" -Properties @{""=""} -verbose 17 | Updates a specific record in the table sys_user_group 18 | #> 19 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "")] 20 | [CmdletBinding(SupportsShouldProcess)] 21 | param ( 22 | [Parameter()] 23 | [boolean] 24 | $active, 25 | [Parameter()] 26 | [string] 27 | $cost_center, 28 | [Parameter()] 29 | [string] 30 | $default_assignee, 31 | [Parameter()] 32 | [string] 33 | $description, 34 | [Parameter()] 35 | [alias('group_email')] 36 | [string] 37 | $email, 38 | [Parameter()] 39 | [boolean] 40 | $exclude_manager, 41 | [Parameter()] 42 | [boolean] 43 | $include_members, 44 | [Parameter()] 45 | [string] 46 | $manager, 47 | [Parameter()] 48 | [string] 49 | $name, 50 | [Parameter()] 51 | [string] 52 | $parent, 53 | [Parameter()] 54 | [string] 55 | $roles, 56 | [Parameter()] 57 | [string] 58 | $source, 59 | [Parameter()] 60 | [string] 61 | $type 62 | ) 63 | DynamicParam { Import-DefaultParamSet -TemplateFunction "Set-SNOWObject" } 64 | 65 | Begin { 66 | $table = "sys_user_group" 67 | } 68 | Process { 69 | Invoke-SNOWTableUPDATE -table $table -Parameters $PSBoundParameters 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /tests/AggregateAPI.Tests.ps1: -------------------------------------------------------------------------------- 1 | #todo -------------------------------------------------------------------------------- /tests/Authentication.Tests.ps1: -------------------------------------------------------------------------------- 1 | $ScriptRoot = $PSScriptRoot 2 | $ModulePath = ($ScriptRoot | Split-Path -parent) + "\src" 3 | $ProjectName = $ScriptRoot | Split-Path -parent | Split-Path -leaf 4 | Import-Module "$ModulePath\$ProjectName.psd1" -Force -ErrorAction Stop 5 | 6 | InModuleScope $ProjectName { 7 | Describe "Authentication" { 8 | BeforeAll { 9 | $RestMethodResponse = Import-Clixml "$PSScriptRoot\MockedResponses\Set-SNOWAuth_oauth.xml" 10 | 11 | $Username = 'DummyUsername' 12 | $Password = 'DummyPassword' 13 | $Instance = 'DummyInstance' 14 | $ClientID = "DummyClientID" 15 | $ClientSecret = "DummyClientSecret" | ConvertTo-SecureString -AsPlainText -Force 16 | $SSPassword = $Password | ConvertTo-SecureString -AsPlainText -Force 17 | $Credential = New-Object PSCredential ($Username, $SSPassword) 18 | $Command = Get-Command Set-SNOWAuth 19 | 20 | Mock -CommandName Invoke-RestMethod -ParameterFilter { $URI -like "*oauth_token*" -and $Method -eq "POST" } -MockWith { $RestMethodResponse } 21 | Mock -CommandName Invoke-WebRequest -ParameterFilter { $Uri -eq "https://$Instance.service-now.com/stats.do" } 22 | } 23 | 24 | Context "Set-SNOWAuth" -tag "Unit" { 25 | It "Should have parameter '' for " -ForEach @( 26 | @{ Parameter = "Instance"; RequiredFor = 'all rest calls'} 27 | @{ Parameter = "Credential"; RequiredFor = 'basic authentication'} 28 | @{ Parameter = "ClientID"; RequiredFor = 'oauth authentication'} 29 | @{ Parameter = "ClientSecret"; RequiredFor = 'oauth authentication'} 30 | ) { 31 | $Command.Parameters.Keys | Should -Contain $parameter -Because "$parameter is required for $RequiredFor" 32 | } 33 | 34 | It "Should set authentication in script scope [basic]" { 35 | Set-SNOWAuth -instance $Instance -credential $Credential 36 | 37 | $script:SNOWAuth | Should -BeOfType Hashtable 38 | $script:SNOWAuth.Instance | Should -BeExactly $Instance 39 | $script:SNOWAuth.Credential | Should -BeExactly $Credential 40 | $script:SNOWAuth.type | Should -BeExactly 'basic' 41 | Should -Invoke Invoke-RestMethod -Exactly 0 42 | } 43 | 44 | It "Should set authentication in script scope [oauth]" { 45 | Set-SNOWAuth -Instance $Instance -Credential $Credential -ClientId $ClientID -ClientSecret $ClientSecret 46 | 47 | $script:SNOWAuth | Should -BeOfType Hashtable 48 | $script:SNOWAuth.Instance | Should -BeExactly $Instance 49 | $script:SNOWAuth.ClientID | Should -BeExactly $ClientID 50 | $script:SNOWAuth.ClientSecret | Should -BeOfType SecureString 51 | $script:SNOWAuth.Token | Should -Not -BeNullOrEmpty 52 | $script:SNOWAuth.Expires | Should -BeOfType DateTime 53 | $script:SNOWAuth.type | Should -BeExactly 'oauth' 54 | Should -Invoke Invoke-RestMethod -Exactly 1 55 | } 56 | 57 | It "Should renew the token on expiry [oauth]" { 58 | Set-SNOWAuth -Instance $Instance -Credential $Credential -ClientId $ClientID -ClientSecret $ClientSecret 59 | Assert-SNOWAuth 60 | $OriginalExpiry = $script:SNOWAuth.Expires 61 | $ForcedExpiry = (get-date).AddMinutes(-5) 62 | $script:SNOWAuth.Expires = $ForcedExpiry 63 | Assert-SNOWAuth 64 | 65 | $script:SNOWAuth.Expires | Should -BeOfType DateTime 66 | $script:SNOWAuth.Expires | Should -BeGreaterThan $OriginalExpiry 67 | $script:SNOWAuth.Expires | Should -BeGreaterThan $ForcedExpiry 68 | Should -Invoke Invoke-RestMethod -Exactly 2 69 | } 70 | 71 | It "Should throw an exception if the instance is hibernating" { 72 | Mock -CommandName Invoke-WebRequest -ParameterFilter { $Uri -like "https://$Instance.service-now.com/stats.do"} -MockWith {@{content="Instance Hibernating page"}} 73 | { Set-SNOWAuth -Instance $Instance -Credential $Credential } | Should -Throw -ExpectedMessage "This servicenow instance is hibernating. Please wake the instance up and use * again." 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /tests/BatchAPI.Tests.ps1: -------------------------------------------------------------------------------- 1 | $ModulePath = ($PSScriptRoot | Split-Path -parent) + "\src" 2 | $ProjectName = $PSScriptRoot | Split-Path -parent | Split-Path -leaf 3 | Import-Module "$ModulePath\$ProjectName.psd1" -Force -ErrorAction Stop 4 | 5 | InModuleScope $ProjectName { 6 | 7 | BeforeAll { 8 | #Get mock data 9 | $BatchRequestResponse = Import-Clixml "$PSScriptRoot\MockedResponses\Invoke-BatchRequest.xml" 10 | $RestMethodResponse = Import-Clixml "$PSScriptRoot\MockedResponses\Invoke-RestMethod.xml" 11 | 12 | $Username = 'DummyUsername' 13 | $Password = 'DummyPassword' 14 | $Instance = 'DummyInstance' 15 | $SSPassword = $Password | ConvertTo-SecureString -AsPlainText -Force 16 | $Credential = New-Object System.Management.Automation.PSCredential ($Username, $SSPassword) 17 | $Script:SNOWAuth = @{ 18 | Instance = $Instance 19 | Credential = $Credential 20 | Type = 'basic' 21 | HandleRatelimiting = $false 22 | WebCallTimeoutSeconds = 0 23 | } 24 | 25 | Mock -CommandName Invoke-SNOWWebRequest -ParameterFilter { $URI -like '*api/now/v1/batch' -and $UseRestMethod.IsPresent } -MockWith { 26 | $BatchRequestResponse 27 | } 28 | 29 | Mock -CommandName Invoke-SNOWWebRequest -ParameterFilter {$URI -notlike '*api/now/v1/batch' -and $UseRestMethod.IsPresent} -MockWith { 30 | $RestMethodResponse 31 | } 32 | } 33 | 34 | Describe "Invoke-SNOWBatch" { 35 | It "Should make a single rest call for multiple requests (scriptblock)" { 36 | $Output = Invoke-SNOWBatch -ScriptBlock { 37 | Set-SNOWUser -Sys_ID 02826bf03710200044e0bfc8bcbe5d3f -Properties @{middle_name="thomas"} 38 | Set-SNOWUser -Sys_ID 02826bf03710200044e0bfc8bcbe5d3f -Properties @{middle_name="thomas"} 39 | Set-SNOWUser -Sys_ID 02826bf03710200044e0bfc8bcbe5d3f -Properties @{middle_name="thomas"} 40 | } 41 | $Output | Should -Not -BeNullOrEmpty 42 | $Output.serviced_requests.count | Should -BeExactly 3 43 | Should -Invoke Invoke-SNOWWebRequest -Exactly 1 44 | } 45 | 46 | It "Should not throw or provide output when run with no requests" { 47 | $Output = Invoke-SNOWBatch -ScriptBlock { 48 | Get-SNOWUser -Sys_ID "02826bf03710200044e0bfc8bcbe5d3f" 49 | } -WarningAction SilentlyContinue 50 | $Output | Should -BeNullOrEmpty 51 | Should -Invoke Invoke-SNOWWebRequest -Exactly 0 52 | } 53 | 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /tests/ImportAPI.Tests.ps1: -------------------------------------------------------------------------------- 1 | $ModulePath = ($PSScriptRoot | Split-Path -parent) + "\src" 2 | $ProjectName = $PSScriptRoot | Split-Path -parent | Split-Path -leaf 3 | Import-Module "$ModulePath\$ProjectName.psd1" -Force -ErrorAction Stop 4 | 5 | InModuleScope $ProjectName { 6 | 7 | BeforeAll { 8 | #Get mock data 9 | $RestMethodResponse = Import-Clixml "$PSScriptRoot\MockedResponses\New-SNOWImport.xml" 10 | 11 | $Username = 'DummyUsername' 12 | $Password = 'DummyPassword' 13 | $Instance = 'DummyInstance' 14 | $SSPassword = $Password | ConvertTo-SecureString -AsPlainText -Force 15 | $Credential = New-Object System.Management.Automation.PSCredential ($Username, $SSPassword) 16 | $Script:SNOWAuth = @{ 17 | Instance = $Instance 18 | Credential = $Credential 19 | Type = 'basic' 20 | HandleRatelimiting = $false 21 | WebCallTimeoutSeconds = 0 22 | } 23 | } 24 | 25 | Describe "New-SNOWImport" { 26 | BeforeAll { 27 | Mock -CommandName Invoke-SNOWWebRequest -ParameterFilter { $URI -like "*import*" -and $Method -eq "POST" -and $UseRestMethod.IsPresent} -MockWith { $RestMethodResponse } 28 | } 29 | 30 | It "Should a result indicating successful import" { 31 | $Movies = @( 32 | @{ 33 | u_title = "The Great Banana Heist" 34 | u_director = "Benny Banana" 35 | u_actor = "Lily Lime" 36 | u_genre = "Crime/Comedy" 37 | }, 38 | @{ 39 | u_title = "The Revenge of the Ninja Hamsters" 40 | u_director = "Hiroshi Hamada" 41 | u_actor = "Sakura Sushi" 42 | u_genre = "Martial Arts/Comedy" 43 | } 44 | ) 45 | $Output = $Movies | New-SNOWImport -table "u_moviesimport" 46 | 47 | $Output.count | Should -BeExactly 2 48 | Should -Invoke Invoke-SNOWWebRequest -Exactly 2 49 | } 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /tests/MockedResponses/Get-SNOWAttachment_RestMethod.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Get-SNOWAttachment_RestMethod.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Get-SNOWAttachment_WebRequest.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Get-SNOWAttachment_WebRequest.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Get-SNOWSCCart_Empty.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Get-SNOWSCCart_Empty.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Get-SNOWSCCart_WithItem.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Get-SNOWSCCart_WithItem.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Invoke-BatchRequest.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Invoke-BatchRequest.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Invoke-RestMethod.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Invoke-RestMethod.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Invoke-SNOWSCCart.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Invoke-SNOWSCCart.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Invoke-SNOWSCCart_CheckedOut.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Invoke-SNOWSCCart_CheckedOut.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Invoke-WebRequest_Paged.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Invoke-WebRequest_Paged.xml -------------------------------------------------------------------------------- /tests/MockedResponses/New-SNOWAttachment.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/New-SNOWAttachment.xml -------------------------------------------------------------------------------- /tests/MockedResponses/New-SNOWImport.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/New-SNOWImport.xml -------------------------------------------------------------------------------- /tests/MockedResponses/Set-SNOWAuth_oauth.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insomniacc/PSSnow/690e523fb853a1181b3a775a073384b718e8d953/tests/MockedResponses/Set-SNOWAuth_oauth.xml --------------------------------------------------------------------------------