Friday 20 January 2017

Ignoring Self-signed Certificates

When using Windows PowerShell as a client, to avoid SSL Certificate trust issues if using HTTPS, enter this function in the PowerShell window:

Sunday 13 November 2016

Oracle Database Query From Powershell

  • Download Oracle Data Provider for .NET (ODP.NET). (Just search for “Oracle ODP.NET”.)
    • Select “Download the latest ODP.NET production release.”
    • Select “64-bit ODAC Downloads”
    • Select “ODP.NET_Managed_ODAC12cR4.zip”
  • Extract the ZIP file to C:\, which creates C:\ODP.NET_Managed_ODAC12cR4.
  • Run cmd as administrator, navigate to C:\ODP.NET_Managed_ODAC12cR4, and run:
    install_odpm.bat C:\oracle\instantclient_10_2 both
In Powershell, add the DLL and set up a database connection and a query:
Script:
Add-Type -Path "C:\Users\User1\ODP.NET_Managed_ODAC12cR4\odp.net\managed\common\Oracle.ManagedDataAccess.dll"
$username = Read-Host -Prompt "Enter database username"
$password = Read-Host -Prompt "Enter database password"
$datasource = Read-Host -Prompt "Enter database TNS name"
$query = "SELECT first_name, last_name FROM users WHERE last_name = 'Lastname' ORDER BY last_name"
$connectionString = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource
$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
$connection.open()
$command=$connection.CreateCommand()
$command.CommandText=$query
$reader=$command.ExecuteReader()
while ($reader.Read()) {
$reader.GetString(1) + ', ' + $reader.GetString(0)
}
$connection.Close()
Expected Output:

User1_Firstname, Lastname
User2_Firstname, Lastname
User3_Firstname, Lastname

Thursday 3 November 2016

Learning VSphere 6.5 -- Installing and Configuring ESXI 6.5 -- Part 1


Object Oriented Scripting in Powershell

Object Oriented Development in PowerShell. PsClass is currently implemented in Powershell in a single file. Makes it simple to use. It supports the following Object Oriented concepts.


  • Inheritance
  • Polymorphism
  • Encapsulation
  • Constructors with parameters
  • Notes – read-write variables
  • Methods – scriptblocks
  • Properties with Get scriptblocks and optional Set scriptblocks
  • Static and Private Notes and Methods

Wednesday 19 October 2016

Invoke a GUI from Remote Input



Input from remote and Invoke a GUI script

cmd.exe /C "pushd \\remoteserver\FolderName && Filename && popd"