update
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
param (
|
||||
)
|
||||
|
||||
New-ITDServiceNowSession -Environment Production -Credential $Secret:SNowVMCred -Verbose
|
||||
|
||||
Get-ITDServiceNowRecord -ItemType 'Catalog task' -Number 'SCTASK0258692'
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(ParameterSetName = 'Email')]
|
||||
[string]
|
||||
$Email,
|
||||
|
||||
[Parameter(ParameterSetName = 'UserName')]
|
||||
[string]
|
||||
$UserName
|
||||
)
|
||||
|
||||
#Get-Module ITD.ServiceNow -ListAvailable | select modulebase
|
||||
|
||||
New-ITDServiceNowSession -Environment Test -Credential $Secret:SNowVMCred
|
||||
|
||||
Get-ITDServiceNowSession
|
||||
|
||||
|
||||
switch($PSCmdlet.ParameterSetName){
|
||||
'Email' { Get-ITDServiceNowUser -Email $Email}
|
||||
'UserName' { Get-ITDServiceNowUser -Username $UserName }
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
$Url = "https://northdakotatest.service-now.com"
|
||||
$HeaderAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Secret:SNowVMCred.UserName, $Secret:SnowVMCred.GetNetworkCredential().Password)))
|
||||
$SNOWSessionHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
|
||||
$SNOWSessionHeader.Add('Authorization', ('Basic {0}' -f $HeaderAuth))
|
||||
$SNOWSessionHeader.Add('Accept', 'application/json')
|
||||
$Type = "application/json"
|
||||
|
||||
|
||||
$PSUJobId = 123456
|
||||
$DomainName = 'nd.gov'
|
||||
$RequestedBy = 'zmeier@nd.gov'
|
||||
$StartDateTime = Get-Date
|
||||
|
||||
New-ITDServiceNowSession -Environment Test -Credential $Secret:SNowVMCred
|
||||
Get-ITDServiceNowSession
|
||||
Write-Verbose -Message "Prep variables" -Verbose
|
||||
|
||||
$TemplateName = 'NDIT-SPS-Server Add/Chg/Del'
|
||||
$RequestedByUsername = 'khellman'
|
||||
$Category = 'Systems Platforms - Systems'
|
||||
$ShortDescription = 'test'
|
||||
$Description = 'test'
|
||||
$Priority = 3
|
||||
$Impact = 3
|
||||
$Justification = 'justification'
|
||||
$Implementation = 'implementation'
|
||||
$RiskImpactAnalysis = 'riskimpactanalysis'
|
||||
$BackoutPlan = 'backoutplan'
|
||||
$TestPlan = 'testplan'
|
||||
$WhoIsImpacted = 'whoimpacted'
|
||||
$ChangeManagerUsername = 'khellman'
|
||||
$ChangeCoordinatorUsername = 'khellman'
|
||||
$AssignmentGroup = 'NDIT-Computer Systems Windows'
|
||||
$AssignedToUsername = 'khellman'
|
||||
$StartTime = Get-Date
|
||||
$EndTime = $StartTime.AddMinutes(1)
|
||||
|
||||
$ChgTemplateStd = Get-ITDServiceNowChangeTemplateStandard -Name $TemplateName
|
||||
$ChgTemplateStdSysId = $ChgTemplateStd.sys_id.value
|
||||
Write-Warning -Message ("ChgTemplateStdSysId = " + $ChgTemplateStdSysId)
|
||||
|
||||
Write-Verbose -Message "Start NewRecord" -Verbose
|
||||
[PSCustomObject]$NewRecord = @{
|
||||
category = $Category;
|
||||
u_subcategory = $Subcategory
|
||||
impact = $Impact;
|
||||
urgency = $Urgency;
|
||||
short_description = $ShortDescription;
|
||||
description = $Description;
|
||||
justification = $Justification;
|
||||
implementation_plan = $Implementation;
|
||||
risk_impact_analysis = $RiskImpactAnalysis;
|
||||
backout_plan = $BackoutPlan;
|
||||
test_plan = $TestPlan
|
||||
u_who_is_impacted = $WhoIsImpacted;
|
||||
start_date = (Get-Date -Date $StartTime -AsUTC).ToString('yyyy-MM-dd HH:mm:ss')
|
||||
end_date = (Get-Date -Date $EndTime -AsUTC).ToString('yyyy-MM-dd HH:mm:ss')
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Start RequestedBy" -Verbose
|
||||
If ($RequestedBy) {
|
||||
$ReqBy = Get-ITDServiceNowUser -Username $RequestedBy
|
||||
If (@($ReqBy).count -gt 1) {
|
||||
Write-Error "Multiple requested users found, creation failed." -ErrorAction Stop
|
||||
}
|
||||
Else {
|
||||
$NewRecord += @{requested_by = $ReqBy.sys_id }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Start AssignmentGroup" -Verbose
|
||||
If ($AssignmentGroup) {
|
||||
$AssGroup = Get-ITDServiceNowUserGroup -Name $AssignmentGroup
|
||||
If (@($AssGroup).count -gt 1) {
|
||||
Write-Error "Multiple assignment groups found, creation failed." -ErrorAction Stop
|
||||
}
|
||||
Else {
|
||||
$NewRecord += @{assignment_group = $AssGroup.sys_id }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Start ChgManagerName" -Verbose
|
||||
$ChgManagerUsername = Get-ITDServiceNowUser -Username $ChangeManagerUsername
|
||||
If (@($ChgManagerUsername).count -gt 1) {
|
||||
Write-Error "Multiple users found for ChangeManagerUsername, creation failed." -ErrorAction Stop
|
||||
}
|
||||
Else {
|
||||
$NewRecord += @{u_change_manager = $ChgManagerUsername.sys_id }
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Start ChgCoordName" -Verbose
|
||||
$ChgCoordUsername = Get-ITDServiceNowUser -Username $ChangeCoordinatorUsername
|
||||
If (@($ChgCoordUsername).count -gt 1) {
|
||||
Write-Error "Multiple users found for ChangeCoordinator, creation failed." -ErrorAction Stop
|
||||
}
|
||||
Else {
|
||||
$NewRecord += @{u_change_coordinator = $ChgCoordUsername.sys_id }
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Start AssignedTousername" -Verbose
|
||||
If ($AssignedToUsername) {
|
||||
$AssTo = Get-ITDServiceNowUser -Username $AssignedToUsername
|
||||
If (@($AssTo).count -gt 1) {
|
||||
Write-Error "Multiple assignment users found, incident creation failed." -ErrorAction Step
|
||||
}
|
||||
Else {
|
||||
$NewRecord += @{assigned_to = $AssTo.sys_id }
|
||||
}
|
||||
}
|
||||
$Uri = ($Url + "/api/sn_chg_rest/change/standard/$ChgTemplateStdSysId")
|
||||
Write-Verbose -Message "Standard CHG Template SysId = $Uri" -Verbose
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Post';
|
||||
Uri = $Uri;
|
||||
Body = $NewRecord | ConvertTo-Json;
|
||||
Headers = $SnowSessionHeader
|
||||
ContentType = "application/json"
|
||||
}
|
||||
|
||||
#Write-Output $InvokeRestMethodParams
|
||||
$result = (Invoke-RestMethod @InvokeRestMethodParams).result
|
||||
|
||||
Write-Output $result
|
||||
#>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string]
|
||||
$SCTaskNum
|
||||
)
|
||||
#RitmSearch ('variables.208bd5b31b0d0dd04d8943b1b24bcb69%3DInfra.ActiveDirectory.Object')
|
||||
#$RitmSearch = Get-ITDServiceNowRecord -ItemType 'Request Item' -Filter ('active%3Dtrue^variables.208bd5b31b0d0dd04d8943b1b24bcb69%3DInfra-ActiveDirectory.Object') -Verbose
|
||||
|
||||
New-ITDServiceNowSession -Environment Production -Credential $Secret:SNowVMCred
|
||||
|
||||
# search Generic Active Directory Service Account tasks
|
||||
$SCTaskSearch = Get-ITDServiceNowRecord -ItemType 'Catalog Task' -Filter ('active=true^variables.208bd5b31b0d0dd04d8943b1b24bcb69=Infra-ActiveDirectory.Object') -Verbose
|
||||
Write-Verbose -Message ("SCTaskSearch found: " + @($SCTaskSearch).count) -Verbose
|
||||
|
||||
ForEach ($SCTask in $SCTaskSearch) {
|
||||
# get ritm and look for addl comments about AD
|
||||
$RitmToReview = Get-ITDServiceNowRecord -ItemType 'Request Item' -SysId $SCTask.request_item.value -IncludeCustomVariable
|
||||
$task_short_description_search = 'Admin task to gather Server Information'
|
||||
$StringSearchStart = "Please create a new nd.gov Active Directory service account with the following details, following guidelines found in KB0016867.*"
|
||||
If ($RitmToReview.customvariable.additional_comments.value -like $StringSearchStart -and $SCTask.short_description -eq $task_short_description_search ){
|
||||
Write-Verbose -Message ($SCTask.Number + " match, update short_description")
|
||||
Update-ITDServiceNowRecord -ItemType "Catalog Task" -Number $SCTask.number -Values @{
|
||||
short_description = 'Active Directory Service Account Provisioning'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user