# Invoke-PSThread ## SYNOPSIS Enables the ability to leverage multithreading within powershell whilst reducing the complexity to get started. ## SYNTAX ### Runspace (Default) ``` Invoke-PSThread -RunspaceDefinition [-ApartmentState ] [-AssemblyList ] [-ContinueOnError ] [-FunctionList ] [-ModuleList ] [-Runspace ] [-RunspaceParameters ] [-SynchronizedHashtable ] [-ThreadOption ] [-VariableList ] [-WaitForAvailableRunspace ] [] ``` ### RunspacePool ``` Invoke-PSThread -InputObjectList -RunspaceDefinition [-ApartmentState ] [-AssemblyList ] [-ContinueOnError ] [-FunctionList ] [-MaximumRunspaces ] [-ModuleList ] [-RunspaceParameters ] [-RunspacePool ] [-SynchronizedHashtable ] [-ThreadOption ] [-VariableList ] [-WaitForAvailableRunspace ] [] ``` ### Await ``` Invoke-PSThread -ThreadList [-Await ] [-ContinueOnError ] [-LoopDuration ] [-LoopTimeout ] [-WaitForAvailableRunspace ] [] ``` ## DESCRIPTION This function aims to remove the enormous complexity out of multithreading within powershell. See the fully working examples below. ## EXAMPLES ### Example 1 Create a runspace. ``` [ScriptBlock]$RunspaceDefinition = { Param ( $SynchronizedHashtable ) [System.Threading.Thread]::CurrentThread.Priority = [System.Threading.ThreadPriority]::Lowest $SynchronizedHashtable.UIDefinitionContent = @' '@ $SynchronizedHashtable.UIDefinitionStringReader = New-Object -TypeName 'System.IO.StringReader' -ArgumentList @($SynchronizedHashtable.UIDefinitionContent) $SynchronizedHashtable.UIDefinitionXMLReader = [System.Xml.XmlReader]::Create($SynchronizedHashtable.UIDefinitionStringReader) $SynchronizedHashtable.UIDefinitionXMLDocument = New-Object -TypeName 'System.XML.XMLDocument' $SynchronizedHashtable.UIDefinitionXMLDocument.LoadXML(($SynchronizedHashtable.UIDefinitionContent -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^