Mass generating *.mof Files

Welcome Forums DSC (Desired State Configuration) Mass generating *.mof Files

This topic contains 3 replies, has 2 voices, and was last updated by

1 year, 6 months ago.

  • Author
  • #76199

    Points: 0
    Rank: Member


    I'm trying to mass generate *.mof Files for servers.
    I made a script, which generates one Dsc configuration per server out of json file.
    After the config is created, i try to mass execute these configurations.
    If i run them sequentially, it takes around 30 seconds for 20 servers. If i try to use a RunspacePool for a parallel execution with 10 threads it takes up to a minute for the same amount of servers. Can anyone explain, why it's slower with Runspaces?

    #This is a modified version of the version from
    # Create an array of computers to do work against
    $Scripts = Get-ChildItem -Path C:\Dsc_Configurations
    # Create an empty array that we'll use later
    $RunspaceCollection = @()
    # This is the array we want to ultimately add our information to
    [Collections.Arraylist]$qwinstaResults = @()
    # Create a Runspace Pool with a minimum and maximum number of run spaces. (
    $RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, 5)
    # Open the RunspacePool so we can use it
    # Define a script block to actually do the work
    $ScriptBlock = {
        $queryResults = & C:\Dsc_Configurations\$Script
    # Create PowerShell objects, then for each one add the unique computer name.
    Foreach ($Script in $Scripts)
        write-host $Script
        # Create a PowerShell object to run add the script and argument.
        # We first create a Powershell object to use, and simualtaneously add our script block we made earlier, and add our arguement that we created earlier
        $Powershell = [PowerShell]::Create().AddScript($ScriptBlock).AddArgument($Script)
        # Specify runspace to use
        # This is what let's us run concurrent and simualtaneous sessions
        $Powershell.RunspacePool = $RunspacePool
        # Create Runspace collection
        # When we create the collection, we also define that each Runspace should begin running
        [Collections.Arraylist]$RunspaceCollection += New-Object -TypeName PSObject -Property @{
            Runspace   = $PowerShell.BeginInvoke()
            PowerShell = $PowerShell  
        } #/New-Object
    } #/ForEach
    # Now we need to wait for everything to finish running, and when it does go collect our results and cleanup our run spaces
    # We just say that so long as we have anything in our RunspacePool to keep doing work. This works since we clean up each runspace as it completes.
    While ($RunspaceCollection)
        # Just a simple ForEach loop for each Runspace to get resolved
        Foreach ($Runspace in $RunspaceCollection.ToArray()) 
            # Here's where we actually check if the Runspace has completed
            If ($Runspace.Runspace.IsCompleted)
                # Since it's completed, we get our results here
                # Here's where we cleanup our Runspace
            } #/If
        } #/ForEach
    } #/While
  • #76253

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Probably just the additional threading overhead. Without really looking at your machine and seeing how memory, processor, and disk are all interacting at the time, it's tough to say with any certainty. But runspaces do involve a certain amount of additional overhead.

  • #76397

    Points: 0
    Rank: Member

    Ok, is it somehow possible to minimize this overhead?

    Im trying to find a simple solution to mass build(maybe 5-10 a day) of 500 mof files, later maybe once a day.
    What is the best way to do that?

  • #76752

    Points: 0
    Rank: Member

    On my 8Gb/4Core buildserver, it take me around 0.75 seconds to build a *.mof file.
    That's acceptable for me, but if anyone have a better/faster idea for the build process, let me know 🙂
    Thank you

The topic ‘Mass generating *.mof Files’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort