Database Reference
In-Depth Information
11. Get help for OracleConnect (output matches function comments):
PS > Get-Help OracleConnect
12. Make a connection with a TNS entry name of LOCALDEV :
PS > Connect-OracleTNS LOCALDEV HR pass
13. See how many rows would have been updated using WhatIf :
PS > OracleInvoke -sql "UPDATE HR.EMPLOYEES SET MANAGER_ID = 114
WHERE MANAGER_ID = 108" -WhatIf
What if: Performing operation "OracleInvoke" on Target "LOCALDEV".
5 row(s) affected
14. Disconnect using -Verbose :
PS > OracleDisconnect -verbose
VERBOSE: Closed connection to Data Source=LOCALDEV;User Id=HR;
15. Optionally remove the module when inished with it:
PS > Remove-Module Oracle.DataAccess
How it works...
PowerShell modules provide better componentization than normal script iles. First, any script
level variable in a module won't conlict with any same-named variable outside the module
and module variables cannot be accessed outside the module. Second, modules allow
selectively exporting certain commands as public while keeping other helper type functions
private to the module. Another module beneit (among others) is easily adding and removing
modules by name without worrying about the ilename.
First we "installed" the module under My Documents\WindowsPowerShell\Modules ,
where the subfolder name is the name of the module and the module ilename matches
the module folder name. We could have modiied the PSModulePath environment variable
to point to another location, such as a company name under Program Files. If we wanted to
temporarily install the module we could also add it via its full ilename.
An OdpVersion module parameter deines which .NET version of the ODP.NET assembly
to load and the load call is made at the end of the module, automatically loading ODP.NET
when the module is imported so functions are ready for use. Note that when the module is
imported, -ArgumentList 2 is used; unlike with script or function parameters, we can't use
named parameters when importing modules. Also note the -Prefix Oracle , which preixes
Oracle to the names of the nouns in the names of the imported members; Get-DataTable
becomes Get-OracleDataTable for example. This helps in avoiding name conlicts and
aids in function description, meaning, and grouping. Public module functions should follow a
Verb-Noun naming convention and use standard PowerShell verbs or a warning will be output
when the module is imported.
 
Search WWH ::




Custom Search