Creating a DSC module to install Oracle Client and disable enable UAC
Tags: devops, dsc, howto, oracle
Published: 2018-09-18 02:43:12

---
title: Creating a DSC module to install Oracle Client and disable enable UAC
published: true
tags: DevOps,DSC,How-To,Oracle
canonical_url: https://www.briannipper.com/2018/08/creating-dsc-module-to-install-oracle.html
---

You ever get a task and think, how hard can this be? Then you begin down what turns into a seemingly never ending journey.  
  
Welcome to mixing old and new technologies.  
  
I found myself in the position of needing to install the Oracle Client on a Windows VM running in Azure using Desired State Configuration (a.k.a. DSC) and, well, let's just say it was an interesting journey.  
  
Listed directly after this is the snippet of the DSC which I'm posting here in hopes that others who have a similar need may stumble across this and save themselves from headache.  
  
I'll provide a break down of the major pieces. I have intentionally left the logging pieces in the script so that any who would be so bold as to cut and paste without reading over at least have a log to dig into.  
  
A few important prerequisites to using this script.

- You'll need a DSC module that downloads the Oracle Client Package, the one I used was for 11gR2 and includes an answer file for the client.

  - These items will be specific to your situation.
- Your Local Configuration Manager (a.k.a. LCM) should be set to allow DSC to reboot.
- This script WILL disable UAC and if for some odd reason after the reboot the script did NOT continue running UAC is LEFT in a disabled state...

**!! WARNING !! UAC SHOULD NOT BE LEFT DISABLED**

Be sure you understand what this script is doing and how to diagnose the state of the VM once the script runs.
  
  
  

Script InsallOracleWithAnswerFile {

TestScript = {

$oraclePathTest = Test-Path HKLM:\SOFTWARE\Wow6432Node\ORACLE\KEY\_OraClient11g\_home1;

$regVal = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA;

if (($oraclePathTest) -and ($regVal.EnableLUA -eq 1)) {

return $True

}

else {

return $False

}

}

SetScript = {

$continueProcessing = $True;

$logTimestamp = Get-Date -Format yyMMddHHmm;

$logPath = "C:\MyFolder\OracleInstallStatus";

$logFile = "$logPath\install-$logTimestamp.log";

Add-Content -Path $logFile -Value "-- Begin Overall Oracle Install With Awnser --";

Add-Content -Path $logFile -Value "-- Opening - Get Curernt UAC VALUE --";

$regVal = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA;

Add-Content -Path $logFile -Value "UAC Reg Key:";

Add-Content -Path $logFile -Value $regVal;
  

if ($regVal.EnableLUA -eq "1") {

Add-Content -Path $logFile -Value "-- Change UAC to disable (i.e. 0) --";

Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -Value 0;

Add-Content -Path $logFile -Value "-- Set Global Falg to trigger Reboot --";

$global:DSCMachineStatus = 1;

$continueProcessing = $False;

}
  

if ($continueProcessing) {

Add-Content -Path $logFile -Value "-- Begin Check for Oracle Install --";

$oracleRegPath = "HKLM:\SOFTWARE\Wow6432Node\ORACLE\KEY\_OraClient11g\_home1";

Add-Content -Path $logFile -Value "Oracle Reg Path:";

Add-Content -Path $logFile -Value $oracleRegPath;

$oraclePathTest = Test-Path $oracleRegPath;

Add-Content -Path $logFile -Value "Results of Testing Reg Path";

Add-Content -Path $logFile -Value $oraclePathTest;

if ($oraclePathTest -eq $False) {

$params = "-silent -nowelcome -noconsole -waitforcompletion -noconfig -responseFile C:\MyFolder\OraclePackage\Oracle11gClientx86\11g\x86\client\response\client\_030514.rsp";

$oracleClientExe = "C:\MyFolder\OraclePackage\Oracle11gClientx86\11g\x86\client\setup.exe";

Add-Content -Path $logFile -Value "--- Starting Oracle Install ---";

Start-Process -FilePath $oracleClientExe -ArgumentList $params -Wait -Passthru;

Add-Content -Path $logFile -Value "--- Finish Oracle Install ---";

}

else {

Add-Content -Path $logFile -Value "Oracle Reg Key was found so NOT running install."

}
  

Add-Content -Path $logFile -Value "-- Secondary - Get Current UAC Value --";

$regVal = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA;

Add-Content -Path $logFile -Value "UAC Reg Key:";

Add-Content -Path $logFile -Value $regVal;

if ($regVal.EnableLUA -eq "0") {

Add-Content -Path $logFile -Value "-- Change UAC to enable (i.e. 1) --";

Set-ItemProperty -Path registry::HKEY\_LOCAL\_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA -Value 1;

}
  

Add-Content -Path $logFile -Value "-- Set Global Falg to trigger Reboot --";

$global:DSCMachineStatus = 1;

}
  

Add-Content -Path $logFile -Value "-- FINISH Overall Oracle Install with Answer --"

}

GetScript = {@{Result = "InsallOracleWithAnswerFile"}}

DependsOn = "[Archive]OraclePackageExtract"

}

  

### Test Script

In short the test script is confirming two things.

1. Is the Oracle Client installed based on the expected registry key being present.
2. Is UAC in the ENABLED state, also checked by looking at the expected registry key value.

If either of these conditions are FALSE there is a need to run the set script.

  

### Set Script

This is where it gets ~~hairy~~ interesting.

I'll skip commenting on the logging as it should be clear what the logs are doing, an interesting point about the way the logging is done is that it can indicate how many times this script is run since the log is written to a file with a date time stamp as the name which I found handy since I put myself into an infinite loop a few times.

  

Since I'll have to essentially provide myself a circuit breaker I set a continue flag at the start that I can use later on.

  

Due to the way the Oracle Installer works, even WITH the answer file you'll still get a UAC prompt before you can begin the install, thus the first part of this set script will obtain the value of the UAC via a registry call.

  

Once I have the UAC value I check to see the state of the value, in the case where it is ON (i.e. 1) I want to disable it so I change the registry value, also setting my continue flag to false and set the environment variable to tell DSC to reboot after this script is completed. Namely...  
$gobal:DSCMachineStatus = 1;

  

At this point I'm checking my flag to ensure that I SKIP attempting to install the oracle client, this is because even thought we updated the registry it does go into effect until we reboot and thus no need to run the Oracle Installer.

  

So we log that we can't install the oracle client and continue on.

  

The next bit also results in NOT applying changes since the UAC value in the registry is technically STILL 1 because UAC isn't ACTUALLY persisted until reboot.

  

I am being sloppy at the end and RESETTING the DSCMachineStatus. Meh.

  

So now we reboot.

  

Now running through the script a second time AFTER the reboot we will be left in a state where the UAC IS disabled but we DO NOT have the Oracle Client installed, so when we run through the set script the oracle install WILL occur.

  

We finish out the second run by enabled UAC and another reboot.

  

When the system comes up on the third time UAC is ENABLED and Oracle Client is installed.

  

Do please let me know if you run into issues with this script in the comments.