I am new to PowerShell and am a beginner level programmer. I have been trying to tweak a PowerShell script to schedule SQL queries on Oracle Database. However, while I run the below on the PowerShell ISE, I get an error:
Add-Type -Path C:\Oracle\Oracle_Home\product\11.2.0\client_1\odp.net\bin\2.x\Oracle.DataAccess.dll
$username = "username"
$password = "password"
$datasource = "HOST:PORT/Instance"
$connectionString = "User Id=$username;Password=$password;Data Source=$datasource"
$query = "SELECT FULL_NAME FROM PER_PEOPLE_X WHERE EMPLOYEE_NUMBER = 'AB123'"
$connection = New-Object Oracle.DataAccess.Client.OracleConnection("$connectionString")
$connection.open()
$command = New-Object Oracle.DataAccess.Client.OracleCommand
$command.Connection = $connection
$command.CommandText = $query
$ds = New-Object system.Data.DataSet
$da = New-Object Oracle.DataAccess.Client.OracleDataAdapter($command)
[void]$da.fill($ds)
return $ds.Tables[0] | SELECT FULL_NAME Export-CSV "C:\test.csv" -NoTypeInformation
$connection.Close()
Below is the error message that states there is an issue loading Oracle.DataAccess.dll (even though I do see the file on that directory):
Add-Type: Could not load file or assembly
'file:///C:\Oracle\Oracle_Home\product\11.2.0\client_1\odp.net\bin\2.x\Oracle.DataAccess.dll' or one of its dependencies. An
attempt was made to load a program with an incorrect format.
At line:1 char:1
+ Add-Type -Path C:\Oracle\Oracle_Home\product\11.2.0\client_1\odp.net\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], BadImageFormatException
+ FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.AddTypeCommand