# SPDX-License-Identifier: MIT # Set the maximum number of threads for the RunspacePool to the number of threads on the machine $maxthreads = [int]$env:NUMBER_OF_PROCESSORS # Create a new session state for parsing variables into our runspace $hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null $InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault() # Add the variable to the session state $InitialSessionState.Variables.Add($hashVars) # Get every private function and add them to the session state $functions = Get-ChildItem function:\ | Where-Object {$_.name -like "*winutil*" -or $_.name -like "*WPF*"} foreach ($function in $functions){ $functionDefinition = Get-Content function:\$($function.name) $functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition $initialSessionState.Commands.Add($functionEntry) } # Create the runspace pool $sync.runspace = [runspacefactory]::CreateRunspacePool( 1, # Minimum thread count $maxthreads, # Maximum thread count $InitialSessionState, # Initial session state $Host # Machine to create runspaces on ) # Open the RunspacePool instance $sync.runspace.Open() # Create classes for different exceptions class WingetFailedInstall : Exception { [string] $additionalData WingetFailedInstall($Message) : base($Message) {} } class ChocoFailedInstall : Exception { [string] $additionalData ChocoFailedInstall($Message) : base($Message) {} } class GenericException : Exception { [string] $additionalData GenericException($Message) : base($Message) {} } $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^`n"*($paneltotal))+"`n" # Iterate through organizedData by panel, category, and application $count = 0 foreach ($panel in ($organizedData.Keys | Sort-Object)) { $blockXml += "`n`n" $panelcount++ foreach ($category in ($organizedData[$panel].Keys | Sort-Object)) { $count++ if ($columncount -gt 0) { $panelcount2 = [Int](($count)/$maxcount-0.5) if ($panelcount -eq $panelcount2 ) { $blockXml +="`n`n`n" $blockXml += "`n`n" $panelcount++ } } $blockXml += "`n`n" $blockXml += "`n`n" $panelcount++ } } $appInfo = $organizedData[$panel][$category][$appName] if ("Toggle" -eq $appInfo.Type) { $blockXml += "`n`n" } elseif ("Combobox" -eq $appInfo.Type) { $blockXml += "`n" # If it is a digit, type is button and button length is digits } elseif ($appInfo.Type -match "^[\d\.]+$") { $blockXml += "