I’m having issues utilizing the MOLDatabaseQuery functions to drop users from oracle databases.
i’ve written a script utilizing the functions from the MOL toolmaking book.
the first half of the script does work fine, it searches and does identify when an account exists. the issue is when i try to invoke-moldatabasequery it fails, no error displayed, no real info for trouble-shooting so i’m just completely stumped
any assitstance would be greatly appreciated
function Get-MOLDatabaseData { [CmdletBinding()] param ( [string]$connectionString, [string]$query, [switch]$isSQLServer ) if ($isSQLServer) { Write-Verbose 'in SQL Server mode' $connection = New-Object -TypeName ` System.Data.SqlClient.SqlConnection } else { Write-Verbose 'in OleDB mode' $connection = New-Object -TypeName ` System.Data.OleDb.OleDbConnection } $connection.ConnectionString = $connectionString $command = $connection.CreateCommand() $command.CommandText = $query if ($isSQLServer) { $adapter = New-Object -TypeName ` System.Data.SqlClient.SqlDataAdapter $command } else { $adapter = New-Object -TypeName ` System.Data.OleDb.OleDbDataAdapter $command } $dataset = New-Object -TypeName System.Data.DataSet $adapter.Fill($dataset) $dataset.Tables[0] $connection.close() } function Invoke-MOLDatabaseQuery { [CmdletBinding(SupportsShouldProcess=$True, ConfirmImpact='Low')] param ( [string]$connectionString, [string]$query, [switch]$isSQLServer ) if ($isSQLServer) { Write-Verbose 'in SQL Server mode' $connection = New-Object -TypeName ` System.Data.SqlClient.SqlConnection } else { Write-Verbose 'in OleDB mode' $connection = New-Object -TypeName ` System.Data.OleDb.OleDbConnection } $connection.ConnectionString = $connectionString $command = $connection.CreateCommand() $command.CommandText = $query if ($pscmdlet.shouldprocess($query)) { $connection.Open() $command.ExecuteNonQuery() $connection.close() } } $path = Split-Path -parent $MyInvocation.MyCommand.Definition $input = $path + "\oracledblist.csv" $cred = get-credential $pw = $cred.getnetworkcredential().password $csv = Import-Csv $input Start-Transcript oracle.txt $user = Read-Host "User to process" foreach ($db in $csv) { $database = $db.Database $string = $db.connection_string + "User ID=$($cred.Username);Password=$pw;" $dbdata = Get-MOLDatabasedata -connectionstring $string -query "select * from dba_users where username = '$user'" if ($dbdata) { Write-Host "$($dbdata.username) found on $database" try { $query = "DROP USER $($dbdata.username) CASCADE" Write-Host $query $drop = Invoke-MOLDatabaseQuery -connectionstring $string -query $query Write-Verbose $drop Write-Host "$user dropped" } catch { Write-Host "Error Dropping user" write-host "$_" } } else { Write-Host no account found on $database } } Stop-Transcript