Created
March 13, 2023 19:56
-
-
Save iversond/ff83cfc515b264a0566ae9658fa934dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#PSScriptInfo | |
.SYNOPSIS | |
Apply the PeopleTools 8.60 Upgrade Project | |
.DESCRIPTION | |
Automate the Change Assistant job that applies the PTU860 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:\ca | |
.PARAMETER CA_PATH | |
(Optional) Change Assistant Installation Directory. Defaults to C:\Program Files\PeopleSoft\Change Assistant | |
.PARAMETER ORACLE_CLIENT_HOME | |
(Optional) Location of Oracle Client. Defaults to c:\oracle\product\19 | |
.PARAMETER STEP | |
(Optional) The CA Step to resume - an integer from the output log | |
.EXAMPLE | |
applyPT860.ps1 -database HRDEV -pt_version 8.60.04 | |
#> | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true)][String]$DATABASE, | |
[Parameter(Mandatory=$true)][String]$PT_VERSION, | |
[Parameter()][String]$CA_BASE = "C:\ca", | |
[Parameter()][String]$CA_PATH = "C:\Program Files\PeopleSoft\Change Assistant", | |
[Parameter()][String]$ORACLE_CLIENT_HOME = "c:\oracle\product\19", | |
[Parameter()][int]$STEP = 0 | |
) | |
# Valid values: "Stop", "Inquire", "Continue", "Suspend", "SilentlyContinue" | |
$ErrorActionPreference = "Stop" | |
$DebugPreference = "SilentlyContinue" | |
$VerbosePreference = "SilentlyContinue" | |
function set_ca_paths { | |
$CLIENT_LOCATION="C:\PT${PT_VERSION}_Client_ORA" | |
$SQLPLUS_LOCATION="${ORACLE_CLIENT_HOME}\BIN\sqlplus.exe" | |
if (!(Test-Path $CA_BASE\output)) { New-Item -Path $CA_BASE\output -ItemType Directory } | |
if (!(Test-Path $CA_BASE\staging)) { New-Item -Path $CA_BASE\staging -ItemType Directory } | |
if (!(Test-Path $CA_BASE\download)) { New-Item -Path $CA_BASE\download -ItemType Directory } | |
} | |
function configure_ca { | |
$env:ORACLE_HOME=$ORACLE_CLIENT_HOME | |
$env:PATH="${env:ORACLE_HOME}\bin;${env:PATH}" | |
$env:TNS_ADMIN="${env:ORACLE_HOME}\network\admin" | |
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 "${CLIENT_LOCATION}\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 "${CLIENT_LOCATION}" ` | |
-NPAH "${CLIENT_LOCATION}" ` | |
-NPCH "${CLIENT_LOCATION}" ` | |
-NSQRF "'-ZIF${CLIENT_LOCATION}\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 PTU860 -OUT c:\temp\$DATABASE-ptu860-start.log -WARNINGSOK Y -EXONERR Y | |
# } else { | |
# .\changeassistant.bat -MODE UM -ACTION PTUAPPLY -TGTENV $DATABASE -UPD PTU860 -OUT c:\temp\$DATABASE-ptu860-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 PTU860 -OUT c:\temp\$DATABASE-ptu860-$STEP.log -WARNINGSOK Y -EXONERR Y -RESETJOB N -RESUMEJOB COMPLETECONTINUE | |
# } else { | |
# .\changeassistant.bat -MODE UM -ACTION PTUAPPLY -TGTENV $DATABASE -UPD PTU860 -OUT c:\temp\$DATABASE-ptu860-$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.60 | |
Set-Location $CA_PATH | |
.\changeassistant.bat ` | |
-MODE UM -ACTION ENVUPDATE ` | |
-TGTENV $DATABASE ` | |
-PSH "${CLIENT_LOCATION}" ` | |
-PAH "${CLIENT_LOCATION}" ` | |
-PCH "${CLIENT_LOCATION}" ` | |
-SQRF "'-ZIF${CLIENT_LOCATION}\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