Hi,
I have a Powershell script that is loading a .NET assembly (.EXE in my case) and calling a public method that uses the app.config to pull an encrypted connection string.
The script dynamically copies the assembly's exe.config over to the Powershell ($pshome) folder as powershell.exe.config and is able to run from my development box just fine. The problem is that it doesn't run from a standard Windows Server 2003 installation.
I verified the exe.config is being copied over to the powershell directory correctly. I've run SysInternals Process Explorer and verified that the process was accessing the config files (no file not found messages). I remotely debugged the powershell.exe instance and can see that the assembly is loading fine but cannot access ConfigurationManager.AppSettings[...] values (returns null).
I'm out of ideas. I've read that I may be able to use a separate app domain but I see no examples of doing this with Powershell.
My code does something to the effect of:
$absolute_path = "c:\foo.exe"
$config_path = $absolute_path + ".config"
copy "$config_path" "$pshome\powershell.exe.config" -Force
[Reflection.Assembly]::LoadFrom($absolute_path)
$foo = new-object MyFooAssembly.FooClass
$foo.DoSomething()
In Vista the code works, in Windows Server 2003 the code does not work.