Skip to content

Commit

Permalink
Merge pull request #6 from Sam-Martin/development
Browse files Browse the repository at this point in the history
v1.12
  • Loading branch information
Sam-Martin authored Mar 11, 2017
2 parents efee4c4 + b619dd1 commit 10945dc
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 47 deletions.
2 changes: 1 addition & 1 deletion MAKE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $PackageFilePatternExclusions = @(

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

$Version = "0.1.2"
$Version = "0.1.12"
$ModuleName = "PSServiceNow"
$PackageName = "$ModuleName-v$($version).zip";

Expand Down
Binary file added PSServiceNow-Automation.json
Binary file not shown.
53 changes: 48 additions & 5 deletions PSServiceNow-Changes.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,79 @@ function Get-ServiceNowChangeRequest {
param(
# Machine name of the field to order by
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$OrderBy='opened_at',

# Direction of ordering (Desc/Asc)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("Desc", "Asc")]
[string]$OrderDirection='Desc',

# Maximum number of records to return
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[int]$Limit=10,

# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchExact=@{},

# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchContains=@{},

# Whether or not to show human readable display values instead of machine values
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("true","false", "all")]
[string]$DisplayValues='true'
)
[string]$DisplayValues='true',

[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[PSCredential]
$ServiceNowCredential,

[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceNowURL,

[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[Hashtable]
$Connection
)

$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;


if ($Connection -ne $null) {
$private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues -Connection $Connection
}
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null) {
$private:result = Get-ServiceNowTable -Table 'change_request' -Query $private:Query -Limit $private:Limit -DisplayValues $private:DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
}
else {
$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
}
}

48 changes: 45 additions & 3 deletions PSServiceNow-ConfigurationManagement.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,76 @@ function Get-ServiceNowConfigurationItem {
param(
# Machine name of the field to order by
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$OrderBy='name',

# Direction of ordering (Desc/Asc)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("Desc", "Asc")]
[string]$OrderDirection='Desc',

# Maximum number of records to return
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[int]$Limit=10,

# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchExact=@{},

# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchContains=@{},

# Whether or not to show human readable display values instead of machine values
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("true","false", "all")]
[string]$DisplayValues='true'
[string]$DisplayValues='true',

[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[PSCredential]
$ServiceNowCredential,

[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceNowURL,

[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[Hashtable]
$Connection
)

$Query = New-ServiceNowQuery -OrderBy $OrderBy -OrderDirection $OrderDirection -MatchExact $MatchExact -MatchContains $MatchContains

$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues;

if ($Connection -ne $null) {
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -Connection $Connection
}
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null) {
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
}
else {
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues
}


# Set the default property set for the table view
$DefaultProperties = @('name', 'category', 'subcategory')
Expand Down
131 changes: 121 additions & 10 deletions PSServiceNow-Incidents.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,82 @@ function Get-ServiceNowIncident{
param(
# Machine name of the field to order by
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$OrderBy='opened_at',

# Direction of ordering (Desc/Asc)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("Desc", "Asc")]
[string]$OrderDirection='Desc',

# Maximum number of records to return
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[int]$Limit=10,

# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchExact=@{},

# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchContains=@{},

# Whether or not to show human readable display values instead of machine values
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("true","false", "all")]
[string]$DisplayValues='true'
[string]$DisplayValues='true',

# Credential used to authenticate to ServiceNow
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[PSCredential]
$ServiceNowCredential,

# The URL for the ServiceNow instance being used
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceNowURL,

#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[Hashtable]
$Connection
)

$Query = New-ServiceNowQuery -OrderBy $OrderBy -OrderDirection $OrderDirection -MatchExact $MatchExact -MatchContains $MatchContains

$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues;

if ($Connection -ne $null)
{
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -Connection $Connection
}
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null)
{
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
}
else
{
$result = Get-ServiceNowTable -Table 'incident' -Query $Query -Limit $Limit -DisplayValues $DisplayValues
}

# Set the default property set for the table view
$DefaultProperties = @('number', 'short_description', 'opened_at')
$DefaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet(DefaultDisplayPropertySet,[string[]]$DefaultProperties)
Expand All @@ -62,43 +109,91 @@ function Get-ServiceNowIncident{
-Comment "Comment" -ConfigurationItem "bee8e0ed6f8475001855fa0dba3ee4ea" `
-Caller "7a4b573a6f3725001855fa0dba3ee485" `
#>

function New-ServiceNowIncident{
Param(

# sys_id of the caller of the incident (user Get-ServiceNowUser to retrieve this)
[parameter(mandatory=$true)]
[parameter(ParameterSetName='SpecifyConnectionFields', mandatory=$true)]
[parameter(ParameterSetName='UseConnectionObject', mandatory=$true)]
[parameter(ParameterSetName='SetGlobalAuth', mandatory=$true)]
[string]$Caller,

# Short description of the incident
[parameter(mandatory=$true)]
[parameter(ParameterSetName='SpecifyConnectionFields', mandatory=$true)]
[parameter(ParameterSetName='UseConnectionObject', mandatory=$true)]
[parameter(ParameterSetName='SetGlobalAuth', mandatory=$true)]
[string]$ShortDescription,

# Long description of the incident
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$Description,

# sys_id of the assignment group (use Get-ServiceNowUserGroup to retrieve this)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$AssignmentGroup,

# Comment to include in the ticket
[parameter(mandatory=$false)]
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$Comment,

# Category of the incident (e.g. 'Network')
[parameter(mandatory=$false)]
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$Category,

# Subcategory of the incident (e.g. 'Network')
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$Subcategory,

# sys_id of the configuration item of the incident
[parameter(mandatory=$false)]
[string]$ConfigurationItem
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$ConfigurationItem,

# custom fields as hashtable
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$CustomFields,

# Credential used to authenticate to ServiceNow
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[PSCredential]
$ServiceNowCredential,

# The URL for the ServiceNow instance being used (eg: instancename.service-now.com)
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceNowURL,

#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[Hashtable]
$Connection
)


$Values = @{
'caller_id' = $Caller
'short_description' = $ShortDescription
Expand All @@ -109,8 +204,24 @@ function New-ServiceNowIncident{
'subcategory' = $Subcategory
'cmdb_ci' = $ConfigurationItem
}

New-ServiceNowTableEntry -Table 'incident' -Values $Values

if($CustomFields)
{
$Values += $CustomFields
}

if ($Connection -ne $null)
{
New-ServiceNowTableEntry -Table 'incident' -Values $Values -Connection $Connection
}
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null)
{
New-ServiceNowTableEntry -Table 'incident' -Values $Values -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
}
else
{
New-ServiceNowTableEntry -Table 'incident' -Values $Values
}

}

Loading

0 comments on commit 10945dc

Please sign in to comment.