how to force DSC script resource to run under STA apartment

This topic contains 2 replies, has 2 voices, and was last updated by  vamsee 1 year, 8 months ago.

  • Author
  • #58327


    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{
    SetScript= {
    $keypath="Software\Policies\Microsoft\Internet Explorer\LinksBar"
    [int] $data=0
    [Microsoft.Win32.RegistryValueKind] $regtype=[Microsoft.Win32.RegistryValueKind]::DWord
    [string] $lgpoerr = $null

    $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= {
    TestScript= {
    return $false

    Question:- How do i force DSC to run a certain script resource in STA apartment model instead of MTA apartment model?

  • #58337

    Don Jones

    I'm fairly certain you can't. Not without rewriting the LCM. Aside from the general bad-idea-ness of Script resources in terms of maintainability and modularity, the closest workaround I could think of would be to launch PowerShell.exe, since there's a switch that let's you specify.

  • #58361


    I found a simple way to solve this. See the below code
    Script somescriptResourceName{
    SetScript= {


You must be logged in to reply to this topic.