I have a .NET DLL whose methods i want to call from DSC script resource. However the catch is that the .NET DLL expects STA threads only to call the methods. MTA threads will not work.
When i called the .NET method from DSC script resource, I am seeing that the method is not running because it is expecting STA whereas the Script is running in MTA.
Below is the bare bones Script resource
Script change_Ddrivelabel{
PSDscRunAsCredential=$mycred
SetScript= {
$keypath=“Software\Policies\Microsoft\Internet Explorer\LinksBar”
$valname=“Enabled”
[int] $data=0
[Microsoft.Win32.RegistryValueKind] $regtype=[Microsoft.Win32.RegistryValueKind]::DWord
[string] $lgpoerr = $null
[Reflection.Assembly]::LoadFile("D:\vamc\test-lgpo\LocalPolicy.dll")
$lgpo = new-object LocalPolicy.LGPO_Executor
$success=$lgpo.ApplyLGPO($keypath,$valname,$data,$regtype,[ref][string]$lgpoerr) #this is the method call that expects to run in STA but instead is being run in MTA.
if($success) {
"Success" | Out-File -FilePath "D:\vamc\test-lgpo\out.txt"
}
else {
$lgpoerr | Out-File -FilePath "D:\vamc\test-lgpo\out.txt"
}
}
GetScript= {
@{
GetScript=$GetScript
SetScript=$SetScript
TestScript=$TestScript
Result=""
}
}
TestScript= {
return $false
}
}
Question:- How do i force DSC to run a certain script resource in STA apartment model instead of MTA apartment model?