# 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{$_.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 '^@christitustech Runspace : @DeveloperDurp MicroWin : @KonTy GitHub : ChrisTitusTech/winutil Version : $($sync.version) "@ Show-CustomDialog -Message $authorInfo -Width 400 }) $sync["Form"].ShowDialog() | out-null Stop-Transcript