Skip to content

Commit

Permalink
Added Get-ServiceNowChangeRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Martin committed May 12, 2015
1 parent 6a162a4 commit efee4c4
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
4 changes: 2 additions & 2 deletions MAKE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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=$_;
Expand Down Expand Up @@ -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";

Expand Down
37 changes: 37 additions & 0 deletions PSServiceNow-Changes.psm1
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions PSServiceNow.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
}
68 changes: 68 additions & 0 deletions PSServiceNow.format.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<ViewDefinitions>
<View>
<Name>PSServiceNow.ChangeRequest</Name>
<ViewSelectedBy>
<TypeName>PSServiceNow.ChangeRequest</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader />
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>assigned_to</Label>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>cmdb_ci</Label>
<Width>30</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>number</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>short_description</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>state</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
$_.assigned_to.display_value
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>approval</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
$_.cmdb_ci.display_value
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>opened_at</PropertyName>
</TableColumnItem>

</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
7 changes: 4 additions & 3 deletions PSServiceNow.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -19,6 +19,7 @@ Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'}
```

## Cmdlets
* Get-ServiceNowChangeRequest
* Get-ServiceNowConfigurationItem
* Get-ServiceNowIncident
* Get-ServiceNowTable
Expand All @@ -28,6 +29,7 @@ Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'}
* New-ServiceNowQuery
* New-ServiceNowTableEntry
* Remove-ServiceNowAuth
* Remove-ServiceNowTableEntry
* Set-ServiceNowAuth
* Test-ServiceNowAuthIsSet

Expand Down

0 comments on commit efee4c4

Please sign in to comment.