Insert values in PowerShell Variable into Oracle Database Table
2
votes
1
answer
577
views
I have created a script in PowerShell (utilising the PowerShell dbaTools) which collect information about SQ Server Estate in our environment. I need to insert the result from the PowerShell directly from the script into Oracle Database table.
Example:
#GET DISK INFO:
$DiskInfo=Get-DbaDiskSpace -ComputerName $Servers | Select @{label='SERVER_NAME';expression={$_.ComputerName}}, @{label='DISK_DRIVE_NAME';expression={$_.Label}}, @{label='CAPACITY_GB_MSR';expression={$_.SizeInGB}}, @{label='USED_GB_MSR';expression={$_.SizeInGB - $_.FreeInGB}},@{label='FREE_SPACE_GB_MSR';expression={$_.FreeInGB}}, @{label='DISK_DRIVE_LETTER_CODE';expression={$_.Name}}, @{label='LINUX_MOUNT_POINT_PATH';expression={'N/A'}} |Out-GridView
Result in $DiskInfo variable:
Now I need to update the DiskInfo table in the Oracle database with the info in the PowerShell variable above (If not exist).
1. My first challenge is I can't seem to find any script that provides a good test for connection to Oracle. I have tried several scripts from online but none seems to be working.
I have tried the connection script from following links and all seems to be erroring out:
https://purple.telstra.com.au/blog/using-powershell-to-query-oracle-dbs-without-using-the-oracle-client-oracle-data-provider-for-net
https://forums.oracle.com/ords/apexds/post/powershell-and-odp-net-how-do-run-update-and-commit-command-0848
https://www.experts-exchange.com/questions/29247739/Insert-Update-oracle-DB-tables-in-PowerShell.html
2. How do I take the value from the PowerShell variable and insert it in the right columns accordingly?
Thank you in advance for any direction or guidance.

Asked by Ali
(345 rep)
Feb 28, 2024, 04:48 AM
Last activity: Feb 29, 2024, 02:57 AM
Last activity: Feb 29, 2024, 02:57 AM