Skip to content

Commit 72227e0

Browse files
authored
Merge pull request #52 from Sam-Martin/development
v1.2.1 - Get-ServiceNowTableEntry & Update-ServiceNowNumber
2 parents 52a8e71 + 8c384d7 commit 72227e0

13 files changed

+482
-150
lines changed

Build/psake.ps1

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Properties {
1313
$lines = '----------------------------------------------------------------------'
1414

1515
$Verbose = @{}
16-
if($ENV:BHCommitMessage -match "!verbose")
17-
{
16+
if ($ENV:BHCommitMessage -match "!verbose") {
1817
$Verbose = @{Verbose = $True}
1918
}
2019
}
@@ -30,23 +29,20 @@ Task Init {
3029
"`n"
3130
}
3231

33-
3432
Task Analyze -Depends Init {
3533
$saResults = Invoke-ScriptAnalyzer -Path $ENV:BHModulePath -Severity @('Error', 'Warning') -Recurse -Verbose:$false
3634
if ($saResults) {
37-
$saResults | Format-Table
38-
#Write-Error -Message 'One or more Script Analyzer errors/warnings where found. Build cannot continue!'
35+
$saResults | Format-Table
36+
# Write-Error -Message 'One or more Script Analyzer errors/warnings where found. Build cannot continue!'
3937
}
4038
}
4139

42-
4340
Task UnitTests -Depends Init {
4441
$lines
4542
'Running quick unit tests to fail early if there is an error'
46-
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests\*unit* -PassThru -Tag Build
47-
48-
if($TestResults.FailedCount -gt 0)
49-
{
43+
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests\*unit* -PassThru -Tag Build
44+
45+
if($TestResults.FailedCount -gt 0) {
5046
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
5147
}
5248
"`n"
@@ -63,13 +59,12 @@ Task Test -Depends UnitTests {
6359
$CodeCoverage.AddRange($CodeFiles.FullName)
6460
$Script:TestResults = Invoke-Pester -Path $ProjectRoot\Tests -CodeCoverage $CodeCoverage -PassThru -OutputFormat NUnitXml -OutputFile $TestFilePath
6561

66-
# In Appveyor? Upload our tests! #Abstract this into a function?
67-
If($ENV:BHBuildSystem -eq 'AppVeyor')
68-
{
69-
[xml]$content = Get-Content $TestFilePath
70-
$content.'test-results'.'test-suite'.type = "Powershell"
71-
$content.Save($TestFilePath)
62+
[xml]$content = Get-Content $TestFilePath
63+
$content.'test-results'.'test-suite'.type = "Powershell"
64+
$content.Save($TestFilePath)
7265

66+
# In Appveyor? Upload our tests! #Abstract this into a function?
67+
If($ENV:BHBuildSystem -eq 'AppVeyor') {
7368
"Uploading $ProjectRoot\$TestFile to AppVeyor"
7469
"JobID: $env:APPVEYOR_JOB_ID"
7570
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $TestFilePath))
@@ -79,8 +74,7 @@ Task Test -Depends UnitTests {
7974

8075
# Failed tests?
8176
# Need to tell psake or it will proceed to the deployment. Danger!
82-
if($TestResults.FailedCount -gt 0)
83-
{
77+
if($TestResults.FailedCount -gt 0) {
8478
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
8579
}
8680
"`n"
@@ -89,9 +83,9 @@ Task Test -Depends UnitTests {
8983
Task Build -Depends Test {
9084
$lines
9185

92-
$functions = Get-ChildItem "$ENV:BHModulePath\Public\*.ps1" |
93-
Where-Object{ $_.name -notmatch 'Tests'} |
94-
Select-Object -ExpandProperty basename
86+
$functions = Get-ChildItem "$ENV:BHModulePath\Public\*.ps1" |
87+
Where-Object {$_.name -notmatch 'Tests'} |
88+
Select-Object -ExpandProperty basename
9589

9690
# Load the module, read the exported functions, update the psd1 FunctionsToExport
9791
Set-ModuleFunctions -Name $env:BHPSModuleManifest -FunctionsToExport $functions
@@ -105,11 +99,11 @@ Task Build -Depends Test {
10599
}
106100
$Script:version = [version]::New($version.Major,$version.Minor,$version.Build)
107101
Write-Host "Using version: $version"
108-
102+
109103
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $version
110104

111105
# Update Code Coverage
112-
Function Update-CodeCoveragePercent{
106+
Function Update-CodeCoveragePercent {
113107
param(
114108
[int]$CodeCoverage=0,
115109
[string]$TextFilePath="$Env:BHProjectPath\Readme.md"
@@ -138,16 +132,15 @@ Task Build -Depends Test {
138132
Task MakePackage -Depends Build,Test {
139133
$lines
140134

141-
function ZipFiles
142-
{
135+
function ZipFiles {
143136
param( $zipfilename, $sourcedir )
144-
Add-Type -Assembly System.IO.Compression.FileSystem
137+
Add-Type -Assembly System.IO.Compression.FileSystem
145138
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
146139
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
147-
$zipfilename, $compressionLevel, $true)
140+
$zipfilename, $compressionLevel, $true)
148141
}
149142

150-
function New-MakePackage{
143+
function New-MakePackage {
151144
param(
152145
[string]$PackageName,
153146
[string]$PackagePath,
@@ -171,24 +164,21 @@ Task Deploy -Depends Build,MakePackage {
171164
$lines
172165

173166
# Gate deployment
174-
if(
167+
if (
175168
$ENV:BHBuildSystem -ne 'Unknown' -and
176169
$ENV:BHBranchName -eq "master" -and
177170
$ENV:BHCommitMessage -match '!deploy'
178-
)
179-
{
171+
) {
180172
$Params = @{
181173
Path = $ProjectRoot
182174
Force = $true
183175
}
184176

185177
Invoke-PSDeploy @Verbose @Params
186-
}
187-
else
188-
{
178+
} else {
189179
"Skipping deployment: To deploy, ensure that...`n" +
190180
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
191181
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
192182
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)"
193183
}
194-
}
184+
}

Readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ServiceNow
22

3-
[![GitHub release](https://img.shields.io/github/release/Sam-Martin/servicenow-powershell.svg)](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) [![GitHub license](https://img.shields.io/github/license/Sam-Martin/servicenow-powershell.svg)](LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-74%25-orange.svg)
3+
[![GitHub release](https://img.shields.io/github/release/Sam-Martin/servicenow-powershell.svg)](https://github.com/Sam-Martin/servicenow-powershell/releases/latest) [![GitHub license](https://img.shields.io/github/license/Sam-Martin/servicenow-powershell.svg)](LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-78%25-yellow.svg)
44

55
This PowerShell module provides a series of cmdlets for interacting with the [ServiceNow REST API](http://wiki.servicenow.com/index.php?title=REST_API), performed by wrapping `Invoke-RestMethod` for the API calls.
66

@@ -77,9 +77,11 @@ The `Connection` parameter accepts a hashtable object that requires a username,
7777
## Cmdlets
7878

7979
* Get-ServiceNowChangeRequest
80-
* Get-ServiceNowConfigurationItem
80+
* Get-ServiceNowConfigurationIte
8181
* Get-ServiceNowIncident
82+
* Get-ServiceNowRequest
8283
* Get-ServiceNowTable
84+
* Get-ServiceNowTableEntry
8385
* Get-ServiceNowUser
8486
* Get-ServiceNowUserGroup
8587
* New-ServiceNowIncident
@@ -91,6 +93,7 @@ The `Connection` parameter accepts a hashtable object that requires a username,
9193
* Test-ServiceNowAuthIsSet
9294
* Update-ServiceNowChangeRequest
9395
* Update-ServiceNowIncident
96+
* Update-ServiceNowNumber
9497
* Update-ServiceNowTableEntry
9598

9699
## Tests

ServiceNow/Public/Get-ServiceNowChangeRequest.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowChangeRequest {
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='opened_at',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowChangeRequest {
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -36,7 +36,7 @@ function Get-ServiceNowChangeRequest {
3636
[parameter(ParameterSetName='SetGlobalAuth')]
3737
[hashtable]$MatchContains=@{},
3838

39-
# Whether or not to show human readable display values instead of machine values
39+
# Whether to return manipulated display values rather than actual database values.
4040
[parameter(mandatory=$false)]
4141
[parameter(ParameterSetName='SpecifyConnectionFields')]
4242
[parameter(ParameterSetName='UseConnectionObject')]
@@ -47,19 +47,19 @@ function Get-ServiceNowChangeRequest {
4747
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4848
[ValidateNotNullOrEmpty()]
4949
[PSCredential]
50-
$ServiceNowCredential,
50+
$ServiceNowCredential,
5151

5252
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5353
[ValidateNotNullOrEmpty()]
5454
[string]
55-
$ServiceNowURL,
55+
$ServiceNowURL,
5656

57-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
57+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
5858
[ValidateNotNullOrEmpty()]
5959
[Hashtable]
6060
$Connection
6161
)
62-
62+
6363
# Query Splat
6464
$newServiceNowQuerySplat = @{
6565
OrderBy = $OrderBy
@@ -68,7 +68,7 @@ function Get-ServiceNowChangeRequest {
6868
MatchContains = $MatchContains
6969
}
7070
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
71-
71+
7272
# Table Splat
7373
$getServiceNowTableSplat = @{
7474
Table = 'change_request'
@@ -79,10 +79,10 @@ function Get-ServiceNowChangeRequest {
7979

8080
# Update the Table Splat if the parameters have values
8181
if ($null -ne $PSBoundParameters.Connection)
82-
{
82+
{
8383
$getServiceNowTableSplat.Add('Connection',$Connection)
8484
}
85-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
85+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8686
{
8787
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
8888
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)
@@ -92,4 +92,4 @@ function Get-ServiceNowChangeRequest {
9292
$Result = Get-ServiceNowTable @getServiceNowTableSplat
9393
$Result | ForEach-Object{$_.PSObject.TypeNames.Insert(0,"ServiceNow.ChangeRequest")}
9494
$Result
95-
}
95+
}

ServiceNow/Public/Get-ServiceNowConfigurationItem.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowConfigurationItem {
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='name',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowConfigurationItem {
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -36,7 +36,7 @@ function Get-ServiceNowConfigurationItem {
3636
[parameter(ParameterSetName='SetGlobalAuth')]
3737
[hashtable]$MatchContains=@{},
3838

39-
# Whether or not to show human readable display values instead of machine values
39+
# Whether to return manipulated display values rather than actual database values.
4040
[parameter(mandatory=$false)]
4141
[parameter(ParameterSetName='SpecifyConnectionFields')]
4242
[parameter(ParameterSetName='UseConnectionObject')]
@@ -47,14 +47,14 @@ function Get-ServiceNowConfigurationItem {
4747
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4848
[ValidateNotNullOrEmpty()]
4949
[PSCredential]
50-
$ServiceNowCredential,
50+
$ServiceNowCredential,
5151

5252
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5353
[ValidateNotNullOrEmpty()]
5454
[string]
55-
$ServiceNowURL,
55+
$ServiceNowURL,
5656

57-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
57+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
5858
[ValidateNotNullOrEmpty()]
5959
[Hashtable]
6060
$Connection
@@ -68,7 +68,7 @@ function Get-ServiceNowConfigurationItem {
6868
MatchContains = $MatchContains
6969
}
7070
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
71-
71+
7272
# Table Splat
7373
$getServiceNowTableSplat = @{
7474
Table = 'cmdb_ci'
@@ -79,10 +79,10 @@ function Get-ServiceNowConfigurationItem {
7979

8080
# Update the Table Splat if the parameters have values
8181
if ($null -ne $PSBoundParameters.Connection)
82-
{
82+
{
8383
$getServiceNowTableSplat.Add('Connection',$Connection)
8484
}
85-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
85+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8686
{
8787
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
8888
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)

ServiceNow/Public/Get-ServiceNowIncident.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-ServiceNowIncident{
66
[parameter(ParameterSetName='UseConnectionObject')]
77
[parameter(ParameterSetName='SetGlobalAuth')]
88
[string]$OrderBy='opened_at',
9-
9+
1010
# Direction of ordering (Desc/Asc)
1111
[parameter(mandatory=$false)]
1212
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -21,7 +21,7 @@ function Get-ServiceNowIncident{
2121
[parameter(ParameterSetName='UseConnectionObject')]
2222
[parameter(ParameterSetName='SetGlobalAuth')]
2323
[int]$Limit=10,
24-
24+
2525
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
2626
[parameter(mandatory=$false)]
2727
[parameter(ParameterSetName='SpecifyConnectionFields')]
@@ -36,28 +36,28 @@ function Get-ServiceNowIncident{
3636
[parameter(ParameterSetName='SetGlobalAuth')]
3737
[hashtable]$MatchContains=@{},
3838

39-
# Whether or not to show human readable display values instead of machine values
39+
# Whether to return manipulated display values rather than actual database values.
4040
[parameter(mandatory=$false)]
4141
[parameter(ParameterSetName='SpecifyConnectionFields')]
4242
[parameter(ParameterSetName='UseConnectionObject')]
4343
[parameter(ParameterSetName='SetGlobalAuth')]
4444
[ValidateSet("true","false", "all")]
4545
[string]$DisplayValues='true',
4646

47-
# Credential used to authenticate to ServiceNow
47+
# Credential used to authenticate to ServiceNow
4848
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
4949
[ValidateNotNullOrEmpty()]
5050
[PSCredential]
51-
$ServiceNowCredential,
51+
$ServiceNowCredential,
5252

53-
# The URL for the ServiceNow instance being used
53+
# The URL for the ServiceNow instance being used
5454
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
5555
[ValidateNotNullOrEmpty()]
5656
[string]
57-
$ServiceNowURL,
57+
$ServiceNowURL,
5858

5959
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
60-
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
60+
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
6161
[ValidateNotNullOrEmpty()]
6262
[Hashtable]
6363
$Connection
@@ -72,20 +72,20 @@ function Get-ServiceNowIncident{
7272
}
7373
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
7474

75-
# Table Splat
75+
# Table Splat
7676
$getServiceNowTableSplat = @{
7777
Table = 'incident'
7878
Query = $Query
7979
Limit = $Limit
8080
DisplayValues = $DisplayValues
8181
}
82-
82+
8383
# Update the splat if the parameters have values
8484
if ($null -ne $PSBoundParameters.Connection)
85-
{
85+
{
8686
$getServiceNowTableSplat.Add('Connection',$Connection)
8787
}
88-
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
88+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
8989
{
9090
$getServiceNowTableSplat.Add('ServiceNowCredential',$ServiceNowCredential)
9191
$getServiceNowTableSplat.Add('ServiceNowURL',$ServiceNowURL)

0 commit comments

Comments
 (0)