diff --git a/Dockerfile b/Dockerfile index 987fc37..4c03cce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,27 @@ -FROM mcr.microsoft.com/powershell:latest +# LTS image +FROM mcr.microsoft.com/powershell:7.4-alpine-3.20 AS installer -RUN pwsh -Command 'Set-PSRepository PSGallery -InstallationPolicy Trusted; Install-Module ServiceNow -ErrorAction Stop' +# Opt-out of telemetry +ENV POWERSHELL_TELEMETRY_OPTOUT=1 + +# Install the ServiceNow module to a specific path +# We use -Scope CurrentUser to keep the path predictable for the 'COPY' step later +RUN pwsh -Command "Install-Module -Name 'ServiceNow' -Force -AllowClobber -Scope CurrentUser" + +# ----------------------------------------------------------------------------- -ENV SNOW_SERVER=${SNOW_SERVER} -ENV SNOW_TOKEN=${SNOW_TOKEN} -ENV SNOW_USER=${SNOW_USER} -ENV SNOW_PASS=${SNOW_PASS} +FROM mcr.microsoft.com/powershell:7.4-alpine-3.20 + +RUN apk add --no-cache icu-libs +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false ENV POWERSHELL_TELEMETRY_OPTOUT=1 -SHELL ["pwsh"] +# Copy only the installed module from the builder stage +COPY --from=installer /root/.local/share/powershell/Modules/ServiceNow /usr/local/share/powershell/Modules/ServiceNow + +# Create a non-root user +RUN adduser -D psworker +USER psworker +WORKDIR /home/psworker + +ENTRYPOINT ["pwsh"] \ No newline at end of file diff --git a/Readme.md b/Readme.md index 9659ca2..cc024e9 100644 --- a/Readme.md +++ b/Readme.md @@ -89,12 +89,6 @@ $params = @{ New-ServiceNowIncident @params ``` -### Azure Connection Object (Automation Integration Module Support) - -The module can use the `Connection` parameter in conjunction with the included `ServiceNow-Automation.json` file for use as an Azure automation integration module. Details of the process is available at [Authoring Integration Modules for Azure Automation](https://azure.microsoft.com/en-us/blog/authoring-integration-modules-for-azure-automation). - -The `Connection` parameter accepts a hashtable object that requires a username, password, and ServiceNowURL. - ## Scope & Contributing Contributions are gratefully received, so please feel free to submit a pull request with additional features or amendments. diff --git a/ServiceNow/Private/Get-ServiceNowAuth.ps1 b/ServiceNow/Private/Get-ServiceNowAuth.ps1 index b0afa3b..c090965 100644 --- a/ServiceNow/Private/Get-ServiceNowAuth.ps1 +++ b/ServiceNow/Private/Get-ServiceNowAuth.ps1 @@ -14,10 +14,6 @@ function Get-ServiceNowAuth { [System.Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'requirement of azure automation')] param ( - [Parameter()] - [Alias('C')] - [hashtable] $Connection, - [Parameter()] [Alias('N')] [string] $Namespace = 'now', @@ -83,12 +79,12 @@ function Get-ServiceNowAuth { $hashOut.ProxyUseDefaultCredentials = $true } } - } elseif ( $Connection ) { - Write-Verbose 'connection' - # issue 248 - $pair = '{0}:{1}' -f $Connection.Username, $Connection.Password - $hashOut.Headers = @{ Authorization = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) } - $hashOut.Uri = 'https://{0}/api/{1}/v1' -f $Connection.ServiceNowUri, $Namespace + # } elseif ( $Connection ) { + # Write-Verbose 'connection' + # # issue 248 + # $pair = '{0}:{1}' -f $Connection.Username, $Connection.Password + # $hashOut.Headers = @{ Authorization = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) } + # $hashOut.Uri = 'https://{0}/api/{1}/v1' -f $Connection.ServiceNowUri, $Namespace } elseif ( $env:SNOW_SERVER ) { $hashOut.Uri = 'https://{0}/api/{1}' -f $env:SNOW_SERVER, $Namespace if ( $env:SNOW_TOKEN ) { @@ -101,7 +97,7 @@ function Get-ServiceNowAuth { throw 'A ServiceNow server environment variable has been set, but authentication via SNOW_TOKEN or SNOW_USER/SNOW_PASS was not found' } } else { - throw "You must authenticate by either calling the New-ServiceNowSession cmdlet or passing in an Azure Automation connection object" + throw "You must authenticate by calling the New-ServiceNowSession cmdlet" } } diff --git a/ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1 b/ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1 index 3d5c355..a190c8b 100644 --- a/ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1 +++ b/ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1 @@ -69,15 +69,12 @@ function Invoke-ServiceNowRestMethod { [Alias('DisplayValues')] [string] $DisplayValue = 'true', - [Parameter()] - [hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) # get header/body auth values - $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession -N $namespace + $params = Get-ServiceNowAuth -S $ServiceNowSession -N $namespace $params.Method = $Method $params.ContentType = 'application/json' diff --git a/ServiceNow/Private/Invoke-TableIdLookup.ps1 b/ServiceNow/Private/Invoke-TableIdLookup.ps1 index acd2e2b..8cd427a 100644 --- a/ServiceNow/Private/Invoke-TableIdLookup.ps1 +++ b/ServiceNow/Private/Invoke-TableIdLookup.ps1 @@ -33,11 +33,6 @@ function Invoke-TableIdLookup { [Alias('AS')] [switch] $AsSysId, - [Parameter(ParameterSetName = 'IdSysId')] - [Parameter(ParameterSetName = 'TableIdSysId')] - [Alias('C')] - [hashtable] $Connection, - [Parameter(ParameterSetName = 'IdSysId')] [Parameter(ParameterSetName = 'TableIdSysId')] [Alias('S')] @@ -85,7 +80,7 @@ function Invoke-TableIdLookup { Table = $thisTable.Name Filter = @('number', '-eq', $ID) Property = 'sys_class_name', 'sys_id', 'number' - Connection = $Connection + ServiceNowSession = $ServiceNowSession } diff --git a/ServiceNow/Public/Add-ServiceNowAttachment.ps1 b/ServiceNow/Public/Add-ServiceNowAttachment.ps1 index 6171880..feccf03 100644 --- a/ServiceNow/Public/Add-ServiceNowAttachment.ps1 +++ b/ServiceNow/Public/Add-ServiceNowAttachment.ps1 @@ -26,9 +26,6 @@ Function Add-ServiceNowAttachment { .PARAMETER PassThru Return the newly created attachment details - .PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -104,15 +101,12 @@ Function Add-ServiceNowAttachment { [Parameter()] [switch] $PassThru, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) begin { - $auth = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession + $auth = Get-ServiceNowAuth -S $ServiceNowSession $params = $auth $params.UseBasicParsing = $true $params.Method = 'POST' @@ -120,7 +114,7 @@ Function Add-ServiceNowAttachment { process { - $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -C $Connection -S $ServiceNowSession + $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -S $ServiceNowSession foreach ($thisFile in $File) { diff --git a/ServiceNow/Public/Export-ServiceNowAttachment.ps1 b/ServiceNow/Public/Export-ServiceNowAttachment.ps1 index 6786a1b..7185951 100644 --- a/ServiceNow/Public/Export-ServiceNowAttachment.ps1 +++ b/ServiceNow/Public/Export-ServiceNowAttachment.ps1 @@ -92,15 +92,12 @@ Function Export-ServiceNowAttachment { [Parameter(ParameterSetName = 'ToPipeline', Mandatory)] [switch] $AsValue, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) begin { - $authParams = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession + $authParams = Get-ServiceNowAuth -S $ServiceNowSession } process { diff --git a/ServiceNow/Public/Get-ServiceNowAttachment.ps1 b/ServiceNow/Public/Get-ServiceNowAttachment.ps1 index 44747dd..e192a51 100644 --- a/ServiceNow/Public/Get-ServiceNowAttachment.ps1 +++ b/ServiceNow/Public/Get-ServiceNowAttachment.ps1 @@ -33,9 +33,6 @@ Function Get-ServiceNowAttachment { Array or multidimensional array of fields to sort on. Each array should be of the format @(field, asc/desc). - .PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -91,9 +88,6 @@ Function Get-ServiceNowAttachment { [ValidateNotNullOrEmpty()] [object[]] $Sort, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) @@ -104,14 +98,13 @@ Function Get-ServiceNowAttachment { First = $PSCmdlet.PagingParameters.First Skip = $PSCmdlet.PagingParameters.Skip IncludeTotalCount = $PSCmdlet.PagingParameters.IncludeTotalCount - Connection = $Connection ServiceNowSession = $ServiceNowSession } } process { - $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -C $Connection -S $ServiceNowSession + $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -S $ServiceNowSession $params.Filter = @('table_name', '-eq', $thisTable.Name), 'and', @('table_sys_id', '-eq', $thisID) diff --git a/ServiceNow/Public/Get-ServiceNowRecord.ps1 b/ServiceNow/Public/Get-ServiceNowRecord.ps1 index 23f88f5..378a8b4 100644 --- a/ServiceNow/Public/Get-ServiceNowRecord.ps1 +++ b/ServiceNow/Public/Get-ServiceNowRecord.ps1 @@ -60,9 +60,6 @@ Only valid when the Property parameter is set to 1 item. Helpful when retrieving sys_id for example. -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -233,9 +230,6 @@ function Get-ServiceNowRecord { [Parameter()] [switch] $AsValue, - [Parameter()] - [hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) @@ -253,7 +247,6 @@ function Get-ServiceNowRecord { First = $PSCmdlet.PagingParameters.First Skip = $PSCmdlet.PagingParameters.Skip IncludeTotalCount = $PSCmdlet.PagingParameters.IncludeTotalCount - Connection = $Connection ServiceNowSession = $ServiceNowSession } @@ -332,7 +325,7 @@ function Get-ServiceNowRecord { $thisParams.UriLeaf = '/attachment' } - [array]$result = Invoke-ServiceNowRestMethod @thisParams + [array]$result = Invoke-ServiceNowRestMethoduest @thisParams if ( -not $result ) { return @@ -395,7 +388,7 @@ function Get-ServiceNowRecord { $newVar.Value = $refValue } } - + } if ( $var.'sc_item_option.item_option_new.name' ) { diff --git a/ServiceNow/Public/Invoke-ServiceNowGraphQL.ps1 b/ServiceNow/Public/Invoke-ServiceNowGraphQL.ps1 index 79fe2f5..ac736c8 100644 --- a/ServiceNow/Public/Invoke-ServiceNowGraphQL.ps1 +++ b/ServiceNow/Public/Invoke-ServiceNowGraphQL.ps1 @@ -26,9 +26,6 @@ .PARAMETER Raw Provide the server response as is instead of parsing out the application, schema, and service names. -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -68,9 +65,6 @@ function Invoke-ServiceNowGraphQL { [Parameter()] [switch] $Raw, - [Parameter()] - [hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) @@ -85,7 +79,7 @@ function Invoke-ServiceNowGraphQL { $fullQuery = ('{0} {{ {1} {{ {2} {{ {3} }}}}}}' -f $Operation, $Application, $Schema, $Query) } - $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession + $params = Get-ServiceNowAuth -S $ServiceNowSession $params.Method = 'Post' $params.ContentType = 'application/json' diff --git a/ServiceNow/Public/New-ServiceNowChangeRequest.ps1 b/ServiceNow/Public/New-ServiceNowChangeRequest.ps1 index 98291b8..8118f63 100644 --- a/ServiceNow/Public/New-ServiceNowChangeRequest.ps1 +++ b/ServiceNow/Public/New-ServiceNowChangeRequest.ps1 @@ -41,9 +41,6 @@ .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER PassThru If provided, the new record will be returned @@ -112,9 +109,6 @@ function New-ServiceNowChangeRequest { [Alias('CustomFields', 'InputData')] [hashtable] $CustomField, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession, @@ -159,7 +153,6 @@ function New-ServiceNowChangeRequest { $params = @{ Table = 'change_request' Values = $values - Connection = $Connection ServiceNowSession = $ServiceNowSession PassThru = $true } diff --git a/ServiceNow/Public/New-ServiceNowChangeTask.ps1 b/ServiceNow/Public/New-ServiceNowChangeTask.ps1 index b0cf9d6..bb08b92 100644 --- a/ServiceNow/Public/New-ServiceNowChangeTask.ps1 +++ b/ServiceNow/Public/New-ServiceNowChangeTask.ps1 @@ -24,9 +24,6 @@ function New-ServiceNowChangeTask { .PARAMETER CustomField Other key/value pairs to create the task which are not one of the existing parameters - .PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER PassThru Return the newly created item details @@ -63,9 +60,6 @@ function New-ServiceNowChangeTask { [Parameter()] [hashtable] $CustomField, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession, @@ -114,12 +108,11 @@ function New-ServiceNowChangeTask { Method = 'Post' Table = 'change_task' Values = $createValues - Connection = $Connection ServiceNowSession = $ServiceNowSession } If ( $PSCmdlet.ShouldProcess($ShortDescription, 'Create new change task') ) { - $response = Invoke-ServiceNowRestMethod @params + $response = Invoke-ServiceNowRestMethoduest @params If ( $PassThru ) { $response.PSObject.TypeNames.Insert(0, "ServiceNow.ChangeTask") $response diff --git a/ServiceNow/Public/New-ServiceNowConfigurationItem.ps1 b/ServiceNow/Public/New-ServiceNowConfigurationItem.ps1 index 801cb6d..667c8e4 100644 --- a/ServiceNow/Public/New-ServiceNowConfigurationItem.ps1 +++ b/ServiceNow/Public/New-ServiceNowConfigurationItem.ps1 @@ -23,9 +23,6 @@ .PARAMETER PassThru Return the newly created CI -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -39,7 +36,7 @@ #> function New-ServiceNowConfigurationItem { - [CmdletBinding(DefaultParameterSetName = 'Session', SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] Param( @@ -61,11 +58,7 @@ function New-ServiceNowConfigurationItem { [Parameter()] [switch] $PassThru, - [Parameter(ParameterSetName = 'UseConnectionObject', Mandatory)] - [ValidateNotNullOrEmpty()] - [Hashtable] $Connection, - - [Parameter(ParameterSetName = 'Session')] + [Parameter()] [ValidateNotNullOrEmpty()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) @@ -109,13 +102,7 @@ function New-ServiceNowConfigurationItem { Table = 'cmdb_ci' Values = $TableEntryValues PassThru = $true - } - - if ($ServiceNowSession) { - $params.ServiceNowSession = $ServiceNowSession - } - else { - $params.Connection = $Connection + ServiceNowSession = $ServiceNowSession } If ( $PSCmdlet.ShouldProcess($Name, 'Create new configuration item') ) { diff --git a/ServiceNow/Public/New-ServiceNowIncident.ps1 b/ServiceNow/Public/New-ServiceNowIncident.ps1 index 0b5e8bc..c8a1cde 100644 --- a/ServiceNow/Public/New-ServiceNowIncident.ps1 +++ b/ServiceNow/Public/New-ServiceNowIncident.ps1 @@ -35,9 +35,6 @@ Generates a new ServiceNow Incident using predefined or other field values .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER PassThru If provided, the new record will be returned @@ -96,9 +93,6 @@ function New-ServiceNowIncident { [Alias('CustomFields', 'InputData')] [hashtable] $CustomField, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession, @@ -142,7 +136,6 @@ function New-ServiceNowIncident { $params = @{ Table = 'incident' Values = $values - Connection = $Connection ServiceNowSession = $ServiceNowSession PassThru = $true } diff --git a/ServiceNow/Public/New-ServiceNowRecord.ps1 b/ServiceNow/Public/New-ServiceNowRecord.ps1 index 6862894..4b18c3f 100644 --- a/ServiceNow/Public/New-ServiceNowRecord.ps1 +++ b/ServiceNow/Public/New-ServiceNowRecord.ps1 @@ -14,9 +14,6 @@ .PARAMETER PassThru If provided, the new record will be returned -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -49,9 +46,6 @@ function New-ServiceNowRecord { [Alias('Values')] [hashtable] $InputData, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession, @@ -65,13 +59,12 @@ function New-ServiceNowRecord { Method = 'Post' Table = $Table Values = $InputData - Connection = $Connection ServiceNowSession = $ServiceNowSession } If ( $PSCmdlet.ShouldProcess($Table, 'Create new record') ) { - $response = Invoke-ServiceNowRestMethod @params + $response = Invoke-ServiceNowRestMethoduest @params If ( $PassThru ) { $type = $script:ServiceNowTable | Where-Object { $_.Name -eq $Table -or $_.ClassName -eq $Table } | Select-Object -ExpandProperty Type diff --git a/ServiceNow/Public/Remove-ServiceNowAttachment.ps1 b/ServiceNow/Public/Remove-ServiceNowAttachment.ps1 index f1246e2..8352385 100644 --- a/ServiceNow/Public/Remove-ServiceNowAttachment.ps1 +++ b/ServiceNow/Public/Remove-ServiceNowAttachment.ps1 @@ -31,9 +31,6 @@ Function Remove-ServiceNowAttachment { [Alias('sys_id')] [string] $SysId, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) @@ -45,7 +42,6 @@ Function Remove-ServiceNowAttachment { $params = @{ Method = 'Delete' UriLeaf = "/attachment/$SysId" - Connection = $Connection ServiceNowSession = $ServiceNowSession } diff --git a/ServiceNow/Public/Remove-ServiceNowRecord.ps1 b/ServiceNow/Public/Remove-ServiceNowRecord.ps1 index d96332e..6be091e 100644 --- a/ServiceNow/Public/Remove-ServiceNowRecord.ps1 +++ b/ServiceNow/Public/Remove-ServiceNowRecord.ps1 @@ -43,16 +43,13 @@ function Remove-ServiceNowRecord { [Alias('sys_id', 'SysId', 'number')] [string] $ID, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) process { - $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -C $Connection -S $ServiceNowSession + $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -S $ServiceNowSession If ($PSCmdlet.ShouldProcess("$($thisTable.ClassName) $ID", 'Remove record')) { @@ -60,7 +57,7 @@ function Remove-ServiceNowRecord { Method = 'Delete' Table = $thisTable.Name SysId = $thisID - Connection = $Connection + ServiceNowSession = $ServiceNowSession } diff --git a/ServiceNow/Public/Update-ServiceNowRecord.ps1 b/ServiceNow/Public/Update-ServiceNowRecord.ps1 index 5d3b78d..2733ddc 100644 --- a/ServiceNow/Public/Update-ServiceNowRecord.ps1 +++ b/ServiceNow/Public/Update-ServiceNowRecord.ps1 @@ -23,9 +23,6 @@ .PARAMETER PassThru If provided, the updated record will be returned -.PARAMETER Connection - Azure Automation Connection object containing username, password, and URL for the ServiceNow instance - .PARAMETER ServiceNowSession ServiceNow session created by New-ServiceNowSession. Will default to script-level variable $ServiceNowSession. @@ -88,16 +85,13 @@ function Update-ServiceNowRecord { [Parameter()] [switch] $PassThru, - [Parameter()] - [Hashtable] $Connection, - [Parameter()] [hashtable] $ServiceNowSession = $script:ServiceNowSession ) process { - $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -C $Connection -S $ServiceNowSession + $thisTable, $thisID = Invoke-TableIdLookup -T $Table -I $ID -AsSysId -S $ServiceNowSession If (-not $PSCmdlet.ShouldProcess("$($thisTable.ClassName) $ID", 'Update values')) { return @@ -117,16 +111,16 @@ function Update-ServiceNowRecord { Table = $thisTable.Name SysId = $thisID Values = $InputData - Connection = $Connection + ServiceNowSession = $ServiceNowSession } - $response = Invoke-ServiceNowRestMethod @params + $response = Invoke-ServiceNowRestMethoduest @params } if ( $PSBoundParameters.ContainsKey('CustomVariableData') ) { - $customVarsOut = Get-ServiceNowRecord -Table $thisTable.Name -ID $thisID -IncludeCustomVariable -Property sys_id, number -Connection $Connection -ServiceNowSession $ServiceNowSession | Select-Object -ExpandProperty CustomVariable + $customVarsOut = Get-ServiceNowRecord -Table $thisTable.Name -ID $thisID -IncludeCustomVariable -Property sys_id, number -ServiceNowSession $ServiceNowSession | Select-Object -ExpandProperty CustomVariable foreach ($key in $CustomVariableData.Keys) { @@ -138,10 +132,10 @@ function Update-ServiceNowRecord { Table = 'sc_item_option' SysId = $thisCustomVar.SysId Values = @{'value' = $CustomVariableData[$key] } - Connection = $Connection + ServiceNowSession = $ServiceNowSession } - $null = Invoke-ServiceNowRestMethod @params + $null = Invoke-ServiceNowRestMethoduest @params } else { Write-Warning ('Custom variable {0} not found' -f $key) @@ -151,7 +145,7 @@ function Update-ServiceNowRecord { if ( $PassThru ) { if ( $PSBoundParameters.ContainsKey('CustomVariableData') ) { - $response = Get-ServiceNowRecord -Table $thisTable.Name -ID $thisID -IncludeCustomVariable -Connection $Connection -ServiceNowSession $ServiceNowSession + $response = Get-ServiceNowRecord -Table $thisTable.Name -ID $thisID -IncludeCustomVariable -ServiceNowSession $ServiceNowSession } if ($thisTable.Type) { diff --git a/ServiceNow/ServiceNow-Automation.json b/ServiceNow/ServiceNow-Automation.json deleted file mode 100644 index ceabcdf..0000000 --- a/ServiceNow/ServiceNow-Automation.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "ConnectionFields": [ - { - "IsEncrypted": false, - "IsOptional": false, - "Name": "Username", - "TypeName": "System.String" - }, - { - "IsEncrypted": true, - "IsOptional": false, - "Name": "Password", - "TypeName": "System.String" - }, - { - "IsEncrypted": false, - "IsOptional": false, - "Name": "ServiceNowUri", - "TypeName": "System.String" - }, - { - "IsEncrypted": false, - "IsOptional": true, - "Name": "APIVersion", - "TypeName": "System.String" - } - - ], - - "ConnectionTypeName": "ServiceNow", - "IntegrationModuleName": "ServiceNow" -} diff --git a/ServiceNow/ServiceNow.psd1 b/ServiceNow/ServiceNow.psd1 index 5f8252a..c19b1c4 100644 --- a/ServiceNow/ServiceNow.psd1 +++ b/ServiceNow/ServiceNow.psd1 @@ -12,7 +12,7 @@ RootModule = 'ServiceNow.psm1' # Version number of this module. -ModuleVersion = '4.1.0' +ModuleVersion = '5.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -27,10 +27,10 @@ Author = 'Greg Brownstein, Rick Arroues, Sam Martin' CompanyName = 'None' # Copyright statement for this module -Copyright = '(c) 2015-2025 Snow-Shell. All rights reserved.' +Copyright = '(c) 2015-2026 Snow-Shell. All rights reserved.' # Description of the functionality provided by this module -Description = 'Automate against ServiceNow service and asset management. This module can be used standalone, with Azure Automation, or Docker.' +Description = 'Automate against ServiceNow service and asset management. This module can be used standalone or with Docker.' # Minimum version of the PowerShell engine required by this module # PowerShellVersion = '' @@ -104,7 +104,7 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'Azure','Automation','ServiceNow','PSModule' + Tags = 'Automation','ServiceNow','PSModule' # A URL to the license for this module. LicenseUri = 'https://github.com/Snow-Shell/servicenow-powershell/blob/master/LICENSE' diff --git a/ServiceNow/ServiceNow.psm1 b/ServiceNow/ServiceNow.psm1 index fffb197..cc0b58b 100644 --- a/ServiceNow/ServiceNow.psm1 +++ b/ServiceNow/ServiceNow.psm1 @@ -39,6 +39,30 @@ $tableLookupArgCompleterSb = { Register-ArgumentCompleter -CommandName 'New-ServiceNowCartItem' -ParameterName 'CatalogItem' -ScriptBlock $tableLookupArgCompleterSb + +$script:tableField = @{} + +$propSb = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + + $t = $fakeBoundParameters.Table + + if ( $t ) { + if ( -not $script:tableField.$t) { + # first time with this table + $tableItem = Get-ServiceNowRecord -Table $t -First 1 + $properties = $tableItem.psobject.Properties | Select-Object Name, TypeNameOfValue, Value + $script:tableField.Add($t, $properties) + } + + $script:tableField.$t | Where-Object { $_ -like ('{0}*' -f $wordToComplete.Trim("'")) } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', ('{0}, ex: {1}' -f $_.TypeNameOfValue, $_.Value)) + } + } +} + +Register-ArgumentCompleter -CommandName 'Get-ServiceNowRecord' -ParameterName 'Property' -ScriptBlock $propSb + $tableArgCompleterSb = { $ServiceNowTable | ForEach-Object { if ( $_.ClassName ) {