I'm rather new to Powershell and am working on setting up my profile.ps1 file. I have a few managed DLLs that I use often to maintain processes throughout the day which I'd like to be able to load up with quick function calls. So I created this function in my ps1 file:
function LoadSomeDll
{
[System.Reflect.Assembly]::LoadFrom("c:\wherever\SomeLib.dll")
return new-object "SomeLib.SomeObject"
}
Then, in Powershell, I do this:
PS > $myLibInstance = LoadSomeDll
The problem is that $myLibInstance, though it appears to be loaded, doesn't behave the way I expect it to or if it would if I explicitly load it without the function. Say SomeLib.SomeObject has a public string property "ConnectionString" that loads itself (from the registry, yuck) when the object is constructed.
PS > $myLibInstance.ConnectionString
//Nothing returned
But, if I do it without the function, like this:
PS > [System.Reflect.Assembly]::LoadFrom("c:\wherever\SomeLib.dll")
PS > $myOtherLibInstance = new-object "SomeLib.SomeObject"
I get this:
PS > $myOtherLibInstance.ConnectionString
StringValueOfConnectionStringProperty
Why does this happen? Is there any way that I can return an instantiated new-object from a Powershell function?
Thanks in advance.