How to get Powershell to add types from an assembly it just loaded

I loaded an assembly using Add-Type:

$Typename = '\crtwfaadvlkv0.d2dbfg.com\PRODUCTION\Vision\Apps\VisionPipeline\Oracle.ManagedDataAccess.dll'
Add-Type -LiteralPath $TypeName

and confirmed it was loaded

[appdomain]::CurrentDomain.GetAssemblies() | Sort-Object -Property FullName | Select-Object -Property FullName
(partial results)

Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342


Next I want to load the classes defined in the assembly so I can use them, but this errors out:

$oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassThru
Add-Type : Cannot add type. The assembly 'Oracle.ManagedDataAccess' could not be found.
At line:1 char:14
+ ... oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassTh ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Oracle.ManagedDataAccess:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand

Add-Type : Cannot add type. One or more required assemblies are missing.
At line:1 char:14
+ ... oracletpe = Add-Type -AssemblyName 'Oracle.ManagedDataAccess' -PassTh ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand 	

So, it looks like PowerShell can’t find the assembly it just loaded. What am I doing wrong?

After loading the assembly dll, you create a New-Object:

https://devblogs.microsoft.com/scripting/use-oracle-odp-net-and-powershell-to-simplify-data-access/

That looks promising and I’ll give it a shot although I wonder if you know the answer to my question why PoSH can’t find the assembly it just loaded?

I used the code sample in the linked article and got further. I was able to create the object but not open the connection. Said TNS could not resolve the connect identifier, even though both ORACLE_HOME and TNS_ADMIN are correctly set and the tnsnames file has the correct entries (also used by other connection types (e.g. Microsoft Oracle connector in SSIS) that work OK)

Any help would be great but I think this is an oracle question

Oracle is a pain. Luckily, I have not had to deal with it in a couple years. The below discusses the TNSName.ORA and other items to successfully connect:

https://purple.telstra.com/blog/using-powershell-to-query-oracle-dbs-without-using-the-oracle-client-oracle-data-provider-for-net

As far as the assembly question, after the dll is loaded and the assemblies are available, you typically are creating a New-Object or referencing it with an accelerator (e.g. [myobject]::mymethod). I believe the -AssemblyName parameter is load a specific assembly from within a dll. This is not my strong suite, it’s not often that I’ve had to rely on loading a DLL to something in Powershell, especially as it’s become much more main stream with the community developing module wrappers to take the guesswork out of things like this.