Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Powershell script to run the PeopleTools 8.56 Upgrade job headlessly. A few assumptions with the script: All manual steps are marked as complete.; your PT Client installs are at c:\client-8.xx.xx
<#PSScriptInfo
.SYNOPSIS
Apply the PeopleTools 8.56 Upgrade Project
.DESCRIPTION
Automate the Change Assistant job that applies the PTU856 project to a database.
.PARAMETER DATABASE
Which database to encrypt the password
.PARAMETER PT_VERSION
PeopleTools version to apply
.PARAMETER CA_BASE
(Optional) Base folder for CA's output, staging, download folders. Defaults to C:\City-CA
.PARAMETER CA_PATH
(Optional) Change Assistant Installation Directory. Defaults to C:\ca\ca-${PT_VERSION}
.PARAMETER ORACLE_CLIENT_HOME
(Optional) Location of Oracle Client. Defaults to c:\oracle\product\12.1.0\client_1
.PARAMETER STEP
(Optional) The CA Step to resume - an integer from the output log
.EXAMPLE
applyPT856Upgrade.ps1 -database HRDEV -pt_version 8.56.06
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][String]$DATABASE,
[Parameter(Mandatory=$true)][String]$PT_VERSION,
[Parameter()][String]$CA_BASE = "C:\ca",
[Parameter()][String]$CA_PATH = "${CA_BASE}\ca-${PT_VERSION}",
[Parameter()][String]$ORACLE_CLIENT_HOME = "c:\oracle\product\12.1.0\client_1",
[Parameter()][int]$STEP = 0
)
# Valid values: "Stop", "Inquire", "Continue", "Suspend", "SilentlyContinue"
$ErrorActionPreference = "Stop"
$DebugPreference = "SilentlyContinue"
$VerbosePreference = "SilentlyContinue"
function set_ca_paths {
$CLIENT_LOCATION="C:\client-${PT_VERSION}"
$SQLPLUS_LOCATION="${ORACLE_CLIENT_HOME}\BIN\sqlplus.exe"
if (!(Test-Path $CA_BASE\output)) { New-Item -Path $CA_PATH\output -ItemType Directory }
if (!(Test-Path $CA_BASE\staging)) { New-Item -Path $CA_PATH\staging -ItemType Directory }
if (!(Test-Path $CA_BASE\download)) { New-Item -Path $CA_PATH\download -ItemType Directory }
}
function configure_ca {
Set-Location $CA_PATH
& "${CA_PATH}\changeassistant.bat" `
-MODE UM -ACTION OPTIONS `
-OUT "${CA_BASE}\output\ca.log" `
-REPLACE Y `
-EXONERR Y `
-SWP False `
-MCP 5 `
-PSH "${CLIENT_LOCATION}" `
-STG "${CA_BASE}\staging" `
-OD "${CA_BASE}\output" `
-DL "c:\client-${PT_VERSION}\PTU" `
-SQH "${SQLPLUS_LOCATION}" `
-EMYN N
if (!($LASTEXITCODE -eq 0)) {
Write-Output "Error configuring Change Assistant. Check database name: [${DATABASE}] (did you use upper case?)"
Set-Location $START_LOCATION
Exit 1
}
}
function set_new_ps_home {
# Configure environment here with New PS_HOME
Set-Location $CA_PATH
.\changeassistant.bat `
-MODE UM -ACTION ENVUPDATE `
-TGTENV $DATABASE `
-NPYN Y `
-NPSH "c:\client-${PT_VERSION}" `
-NPAH "c:\client-${PT_VERSION}" `
-NPCH "c:\client-${PT_VERSION}" `
-NSQRF "'-ZIFC:\client-${PT_VERSION}\sqr\pssqr.ini'"
if (!($LASTEXITCODE -eq 0)) {
Write-Output "Error configuring New PS_HOME for ${DATABASE}. Open Change Assistant to review the configuration."
Set-Location $START_LOCATION
Exit 1
}
}
function apply_ptu_project {
Set-Location $CA_PATH
if ($STEP -eq 0) {
Write-Host "Starting new PeopleTools Upgrade job for ${DATABASE}"
# if ($VERBOSE -eq "true") {
.\changeassistant.bat -MODE UM -ACTION PTUAPPLY -TGTENV $DATABASE -UPD PTU856 -OUT c:\temp\$DATABASE-ptu856-start.log -WARNINGSOK Y -EXONERR Y
# } else {
# .\changeassistant.bat -MODE UM -ACTION PTUAPPLY -TGTENV $DATABASE -UPD PTU856 -OUT c:\temp\$DATABASE-ptu856-start.log -WARNINGSOK Y -EXONERR Y | select-string "Running"
# }
} else {
Write-Host "Resuming PeopleTools Upgrade job for ${DATABASE}"
}
$status = "running"
Do {
# if ($VERBOSE -eq "true") {
.\changeassistant.bat -MODE UM -ACTION PTUAPPLY -TGTENV $DATABASE -UPD PTU856 -OUT c:\temp\$DATABASE-ptu856-$STEP.log -WARNINGSOK Y -EXONERR Y -RESETJOB N -RESUMEJOB COMPLETECONTINUE
# } else {
# .\changeassistant.bat -MODE UM -ACTION PTUAPPLY -TGTENV $DATABASE -UPD PTU856 -OUT c:\temp\$DATABASE-ptu856-$STEP.log -WARNINGSOK Y -EXONERR Y -RESETJOB N -RESUMEJOB COMPLETECONTINUE | select-string "Running"
# }
Write-Host "Change Assistant Exit Code: ${LASTEXITCODE}"
switch ($LASTEXITCODE) {
0 {
Write-Output "Change Assistant reported no more steps to run."
$status = "done"
break
}
1 {
Write-Output "Error in PeopleTools upgrade job. Open Change Assistant to review the error."
Write-Host "Command to open CA: set-location '${CA_PATH}'; .\changeassistant.bat"
Write-Host "Error on Step: `n`t" ${STEP} "(" ")"
Set-Location $START_LOCATION
Exit 1
}
2 {
# Add Code in here to capture the CA output, determine the manual stop, and handle appropriately
# For now, continue for a vanilla upgrade
Write-Host "Manual Stop Encountered"
Write-Host "Manual Stop " " Completed"
Write-Host "Step: " $STEP
}
3 {
Write-Output "Change Assistant failed to get a lock on the environment."
Write-Host "Command to open CA: set-location '${CA_PATH}'; .\changeassistant.bat"
Write-Host "Error on Step: `n`t" ${STEP} "(" ")"
Exit 3
}
Default {
Write-Output "Unknown Error Occured. Exiting."
Write-Host "Command to open CA: set-location '${CA_PATH}'; .\changeassistant.bat"
Write-Host "Error on Step: `n`t" ${STEP} "(" ")"
Exit 4
}
}
$STEP++
} while ($status -eq "running")
}
function remove_new_ps_home {
# Configure environment here by removing New PS_HOME and setting the regular PS_HOME to 8.56
Set-Location $CA_PATH
.\changeassistant.bat `
-MODE UM -ACTION ENVUPDATE `
-TGTENV $DATABASE `
-PSH "c:\client-${PT_VERSION}" `
-PAH "c:\client-${PT_VERSION}" `
-PCH "c:\client-${PT_VERSION}" `
-SQRF "'-ZIFC:\client-${PT_VERSION}\sqr\pssqr.ini'" `
-NPYN N
if (!($LASTEXITCODE -eq 0)) {
Write-Output "Error removing New PS_HOME for ${database}. Open Change Assistant to review the configuration."
Set-Location $START_LOCATION
Exit 1
}
}
$START_LOCATION = $(Get-Location)
if ($STEP -eq 0) {
. set_ca_paths
. configure_ca
. set_new_ps_home
}
. apply_ptu_project
. remove_new_ps_home
Set-Location $START_LOCATION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.