My First PowerShell Module – PSOraenv

Most of my experience with Oracle has been on Linux, but recently I began working with it on Windows as well. It came to my attention very quickly that oraenv, my beloved friend in Oracle administration, is not present on Windows installations. When you have more than one database installed on a single server, or perhaps ASM (which has its own Oracle home), manually swapping back and forth to work with the different pieces gets really old really fast. For this reason, and because I’ve been anxious to learn how to make my own PowerShell modules, I created PSOraenv. Its purpose is to closely mirror the capabilities of oraenv and allow a similar level of simple, yet powerful, command-line flexibility on Windows systems. Let me give you some examples.

By default, the necessary environment variables for Oracle aren’t set when you fire up PowerShell or Command Prompt. (It seems to default to the most recently installed product.) Using my cmdlet Get-OraEnv, we can verify that they start empty.

In order to see what options are available to us, we run my cmdlet Get-OraSID to pull back a list of the database SID’s and associated Oracle homes on the local machine.

Now that we know what SID’s are available to us, my cmdlet Set-OraEnv can be used.

Now, if we run Get-OraEnv again, we can see that the environment variables have indeed been set.

And, just to prove that actually matters, sqlplus can verify which database we are currently working with. (My sandbox system defaults to lkftest2.)

And there you have it! We have easily viewed which databases are on the local server and quickly swapped to the one that’s needed. It’s just as easy to swap back to the lkfowler2 SID if needed.

This module can be installed from PowerShell Gallery using Install-Module, like the example below.

(You can also find the PowerShell Gallery page at

If you’re interested to see what’s in the code, that has been placed below. I welcome any comments, feedback, and functionality requests. Hope you enjoy!