diff --git a/MAKE.ps1 b/MAKE.ps1 index 168929d..3fd9365 100644 --- a/MAKE.ps1 +++ b/MAKE.ps1 @@ -13,7 +13,7 @@ function New-MakePackage{ [string]$PackageName, [string]$ModuleName ) - ($FilePatternExclusions | %{"MAKE.zip" -match $_}).contains($true) + @($FilePatternExclusions | %{"MAKE.zip" -match $_}).contains($true) $FilesToInclude = Get-ChildItem -Path $here | ?{ $File=$_; @@ -66,7 +66,7 @@ $PackageFilePatternExclusions = @( $here = Split-Path -Parent $MyInvocation.MyCommand.Path -$Version = "0.1.1" +$Version = "0.1.2" $ModuleName = "PSServiceNow" $PackageName = "$ModuleName-v$($version).zip"; diff --git a/PSServiceNow-Changes.psm1 b/PSServiceNow-Changes.psm1 new file mode 100644 index 0000000..4625f04 --- /dev/null +++ b/PSServiceNow-Changes.psm1 @@ -0,0 +1,37 @@ +function Get-ServiceNowChangeRequest { + param( + # Machine name of the field to order by + [parameter(mandatory=$false)] + [string]$OrderBy='opened_at', + + # Direction of ordering (Desc/Asc) + [parameter(mandatory=$false)] + [ValidateSet("Desc", "Asc")] + [string]$OrderDirection='Desc', + + # Maximum number of records to return + [parameter(mandatory=$false)] + [int]$Limit=10, + + # Hashtable containing machine field names and values returned must match exactly (will be combined with AND) + [parameter(mandatory=$false)] + [hashtable]$MatchExact=@{}, + + # Hashtable containing machine field names and values returned rows must contain (will be combined with AND) + [parameter(mandatory=$false)] + [hashtable]$MatchContains=@{}, + + # Whether or not to show human readable display values instead of machine values + [parameter(mandatory=$false)] + [ValidateSet("true","false", "all")] + [string]$DisplayValues='true' + ) + + $private:Query = New-ServiceNowQuery -OrderBy $private:OrderBy -OrderDirection $private:OrderDirection -MatchExact $private:MatchExact -MatchContains $private:MatchContains + + $private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues; + + # Add the custom type to the change request to enable a view + $private:result | %{$_.psobject.TypeNames.Insert(0, "PSServiceNow.ChangeRequest")} + return $private:result +} \ No newline at end of file diff --git a/PSServiceNow.Tests.ps1 b/PSServiceNow.Tests.ps1 index 501da27..be3b6c7 100644 --- a/PSServiceNow.Tests.ps1 +++ b/PSServiceNow.Tests.ps1 @@ -18,6 +18,7 @@ if(Test-Path $DefaultsFile){ ServiceNowURL = 'testingurl.service-now.com' TestCategory = 'Internal' TestUserGroup = 'e9e9a2406f4c35001855fa0dba3ee4f3' + TestUser = "7a4b573a6f3725001855fa0dba3ee485" } | ConvertTo-Json | Set-Content $DefaultsFile return; } @@ -66,4 +67,8 @@ Describe "ServiceNow-Module" { # There should be one or more configuration items returned (Get-ServiceNowConfigurationItem).Count -gt 0 | Should Match $true } + + It "Get-ServiceNowChangeRequest works" { + (Get-ServiceNowChangeRequest).Count -gt 0 | Should Match $true + } } \ No newline at end of file diff --git a/PSServiceNow.format.ps1xml b/PSServiceNow.format.ps1xml new file mode 100644 index 0000000..667c8c9 --- /dev/null +++ b/PSServiceNow.format.ps1xml @@ -0,0 +1,68 @@ + + + + + PSServiceNow.ChangeRequest + + PSServiceNow.ChangeRequest + + + + + 20 + + + + 20 + + + + 20 + + + 20 + + + + 30 + + + 20 + + + + + + + number + + + short_description + + + state + + + + $_.assigned_to.display_value + + + + approval + + + + $_.cmdb_ci.display_value + + + + opened_at + + + + + + + + + \ No newline at end of file diff --git a/PSServiceNow.psd1 b/PSServiceNow.psd1 index f33e4a3..c3f74af 100644 --- a/PSServiceNow.psd1 +++ b/PSServiceNow.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSServiceNow.psm1' # Version number of this module. -ModuleVersion = '0.1.1' +ModuleVersion = '0.1.2' # ID used to uniquely identify this module GUID = 'b90d67da-f8d0-4406-ad74-89d169cd0633' @@ -60,14 +60,15 @@ Copyright = '(c) 2015 Sam. All rights reserved.' # TypesToProcess = @() # Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() +FormatsToProcess = @('PSServiceNow.format.ps1xml') # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess NestedModules = @( 'PSServiceNow-Tables.psm1', 'PSServiceNow-Incidents.psm1', 'PSServiceNow-Users.psm1', - 'PSServiceNow-ConfigurationManagement.psm1' + 'PSServiceNow-ConfigurationManagement.psm1', + 'PSServiceNow-Changes.psm1' ) # Functions to export from this module diff --git a/Readme.md b/Readme.md index 9604240..043c309 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,5 @@ # PSServiceNow -[![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-86%25-yellowgreen.svg) +[![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-87%25-yellowgreen.svg) 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. **IMPORTANT:** Neither this module, nor its creator are in any way affiliated with ServiceNow. @@ -19,6 +19,7 @@ Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'} ``` ## Cmdlets +* Get-ServiceNowChangeRequest * Get-ServiceNowConfigurationItem * Get-ServiceNowIncident * Get-ServiceNowTable @@ -28,6 +29,7 @@ Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'} * New-ServiceNowQuery * New-ServiceNowTableEntry * Remove-ServiceNowAuth +* Remove-ServiceNowTableEntry * Set-ServiceNowAuth * Test-ServiceNowAuthIsSet