Manual
  • BluSapphire Manuals
  • BluSapphire
    • Detections
      • Creating "Detections" Using BluSapphire Portal
    • Roles & Permissions
    • Knowledge Base
  • BluGenie
    • Full Function List
      • Add-BluGenieFirewallRule
      • Clear-BlugenieMemory
      • Connect-BluGenieToSystem
      • Convert-BluGenieSID2UserName
      • Convert-BluGenieSize
      • Convert-BluGenieUserName2SID
      • Convert-BluGenieUTCtoLocal
      • ConvertFrom-Yaml
      • ConvertTo-BluGenieDate
      • ConvertTo-Yaml
      • Disable-BluGenieAllFirewallRules
      • Disable-BluGenieFirewallRule
      • Enable-BluGenieAllFirewallRules
      • Enable-BluGenieFirewallRule
      • Enable-BluGenieWinRMoverWMI
      • Expand-BluGenieArchivePS2
      • Format-BluGenieEvent
      • Get-BluGenieADGroupMembers
      • Get-BluGenieADGroups
      • Get-BluGenieADMachineInfo
      • Get-BluGenieAuditProcessTracking
      • Get-BluGenieAutoRuns
      • Get-BluGenieChildItemList
      • Get-BluGenieCOMObjectInfo
      • Get-BluGenieCurrentSessionAliases
      • Get-BluGenieCurrentSessionFunctions
      • Get-BluGenieCurrentSessionVariables
      • Get-BluGenieErrorAction
      • Get-BluGenieFileADS
      • Get-BluGenieFilePermissions
      • Get-BluGenieFileSnapshot
      • Get-BluGenieFileStreams
      • Get-BluGenieFirewallRules
      • Get-BluGenieHashInfo
      • Get-BluGenieHelp
      • Get-BluGenieHostingVersion
      • Get-BluGenieIPrange
      • Get-BluGenieLiteralPath
      • Get-BluGenieLoadedRegHives
      • Get-BluGenieLockingProcess
      • Get-BluGenieMRUActivityView
      • Get-BluGenieProcessList
      • Get-BluGenieRegistry
      • Get-BluGenieRegistryProcessTracking
      • Get-BluGenieRegSnapshot
      • Get-BluGenieRunSpaceSessionAliases
      • Get-BluGenieRunSpaceSessionFunctions
      • Get-BluGenieRunSpaceSessionVariables
      • Get-BluGenieSchTaskInfo
      • Get-BluGenieScriptDirectory
      • Get-BluGenieServiceList
      • Get-BluGenieServiceStatus
      • Get-BluGenieSessionAliasList
      • Get-BluGenieSessionFunctionList
      • Get-BluGenieSessionVariableList
      • Get-BluGenieSettings
      • Get-BluGenieSignature
      • Get-BluGenieSystemInfo
      • Get-BluGenieToolsDirectory
      • Get-BluGenieTranscriptsDir
      • Get-BluGenieTranscriptsFile
      • Get-BluGenieTrapData
      • Get-BluGenieWindowsTitle
      • Get-BluGenieWindowsUpdates
      • Install-BluGenieHarvester
      • Install-BluGenieSysMon
      • Invoke-BluGenieAnalyzer
      • Invoke-BluGenieFileBrowser
      • Invoke-BluGenieLoadAllProfileHives
      • Invoke-BluGenieNetStat
      • Invoke-BluGenieParallel
      • Invoke-BluGenieProcess
      • Invoke-BluGenieProcessHash
      • Invoke-BluGeniePSQuery
      • Invoke-BluGeniePython
      • Invoke-BluGenieSQLLQuery
      • Invoke-BluGenieThreadLock
      • Invoke-BluGenieUnLoadAllProfileHives
      • Invoke-BluGenieWalkThrough
      • Invoke-BluGenieWipe
      • Invoke-BluGenieYara
      • Invoke-PSipcalc
      • Invoke-PSnmap
      • Invoke-SQLiteBulkCopy
      • Invoke-SqliteQuery
      • Invoke-WalkThrough
      • Join-BluGenieObjects
      • New-BluGenieCommand
      • New-BluGenieHelpMenu
      • New-BluGenieService
      • New-BluGenieSessionInfo
      • New-BluGenieTimeStamp
      • New-BluGenieUID
      • New-SQLiteConnection
      • Open-BluGenieLog
      • Open-BluGenieLogDir
      • Open-BluGenieScriptDir
      • Open-BluGenieToolDir
      • Open-BluGenieTransDir
      • Out-DataTable
      • Publish-BluGenieArtifact
      • Publish-BluGenieFirewallRules
      • Remove-BluGenieFile
      • Remove-BluGenieFirewallRule
      • Remove-BluGenieModule
      • Remove-BluGenieService
      • Resolve-BluGenieDnsName
      • Send-BluGenieItem
      • Set-BluGenieAuditProcessPol
      • Set-BluGenieCommands
      • Set-BluGenieCores
      • Set-BluGenieDebugger
      • Set-BluGenieFirewallGPOStatus
      • Set-BluGenieFirewallStatus
      • Set-BluGenieJobId
      • Set-BluGenieJobMemory
      • Set-BluGenieJobTimeout
      • Set-BluGenieNoBanner
      • Set-BluGenieNoExit
      • Set-BluGenieNoSetRes
      • Set-BluGenieParallelCommands
      • Set-BluGeniePostCommands
      • Set-BluGeniePrefetch
      • Set-BluGenieProcessCPUAffinity
      • Set-BluGenieProcessPriority
      • Set-BluGenieRange
      • Set-BluGenieRemoteDesktopProcess
      • Set-BluGenieScriptCredentials
      • Set-BluGenieServiceJob
      • Set-BluGenieSessionInfo
      • Set-BluGenieSettingsPriority
      • Set-BluGenieSystems
      • Set-BluGenieThreadCount
      • Set-BluGenieTrapping
      • Set-BluGenieUpdateMods
      • Set-BluGenieVerbose
      • Show-BluGenieGUI
      • Show-BluGenieMore
      • Start-BluGenieNewProcess
      • Start-BluGenieRunSpace
      • Stop-BluGenieService
      • Test-BluGenieIsFileLocked
      • Test-BluGenieIsMutexAvailable
      • Trace-BluGenieFireWallStatus
      • Update-BluGenieFirewallProfileStatus
      • Update-BluGenieSysinternals
      • Update-Sqlite
      • Write BluGenieVerboseMsg
    • Functions by Category
      • Discovery
        • Registry
        • File/Folder
        • Process
        • System
        • Network
        • ActiveDirectory
      • Execution
        • Registry
        • File/Folder
        • Process
        • System
        • Network
        • Tools
      • Support
    • Artifacts
      • Example Template
      • Tactical Artifacts by Category
        • Combination Query
          • Query Autorun locations for any item nested that is not digitally signed
        • EventLog Query
          • Query for Process execution from unusual directories
          • Query suspicious programs processed by the Task Scheduler using the Event Log
          • Query for unusual instances of rundll32.exe via the Event Log
          • Query for Unusual Instances of rundll32.exe making outbound network connections using SysMon Data
          • Query Suspicious Powershell Command Line Executions
          • Query the Windows System Log for 104, 517, 1102
        • File and Folder Query
          • Query for malicious file types in all users and system temp directories
          • Query Malicious file types from any directory not including the default OS and Install directories
          • Query all users for their Powershell Profile content for Powershell, Powershell_ISE, and VS Code
          • Query to Determine if any lolbin files are installed outside the normal OS and Program Files dir's
        • Network Query
          • Query for Unusual Windows Network Activity
        • Process Query
          • Query for all Processes not running from the Windows and Program Files.* Directories
        • Registry Query
          • Query Information from the Registry on Recentdocs, Recentapps
          • Query Registry for a list of mounted USB storage devices, including external memory cards
          • Query the Most Recently Used items from the Registry
          • Query the Most Recently Open and Saved File information from the Registry
          • Query all Run, RunOnce, and RunOnceEx Registry Keys
          • Query Command list from the MRU Registry List
          • Query Startup Services from the Registry
          • Query Map Network Drives from the Registry
          • Query Shell Folders and User Shell Folders from both the HKLM and HKU Registry Information
          • Query Typed Urls from the Registry
          • Query Current Control Set Services information from the Registry
          • Query Accessibility Features from Image File Execution Options from the Registry
          • Query the Registry for Commands that are automatically executed each time cmd.exe is run
          • Query the Registry for Mounted Device information
          • Query the Registry for Browser Helper Objects (BHO)
          • Query the Registry for Explore Run commands
          • Query the Registry for Winlogon Helper Dll's
          • Query the Registry for Active Setup information
          • Query the Registry for Bypassing UAC Mechanisms from the User-Accessible information
          • Query the Registry for User-Logon, and Startup Scripts
          • Query the Registry for the most common MRU information for All User Hives, including offline users
          • Query the Registry for any user, using the SysInternals Tools
Powered by GitBook
On this page
  • Invoke-BluGenieParallel
  • SYNOPSIS
  • SYNTAX
  • DESCRIPTION
  • EXAMPLES
  • PARAMETERS
  1. BluGenie
  2. Full Function List

Invoke-BluGenieParallel



Invoke-BluGenieParallel

SYNOPSIS

Function to control parallel processing using runspaces

SYNTAX

Invoke-BluGenieParallel [[-ScriptBlock] <ScriptBlock>] [-InputObject <PSObject>] [-Parameter <PSObject>] [-ImportVariables] [-ImportModules] [-ImportFunctions] [-Throttle <Int32>] [-SleepTimer <Int32>] 
[-RunspaceTimeout <Int32>] [-NoCloseOnTimeout] [-MaxQueue <Int32>] [-AppendLog] [-LogFile <String>] [-Quiet] [-Walkthrough] [<CommonParameters>]

Invoke-BluGenieParallel [-ScriptFile <Object>] [-InputObject <PSObject>] [-Parameter <PSObject>] [-ImportVariables] [-ImportModules] [-ImportFunctions] [-Throttle <Int32>] [-SleepTimer <Int32>] [-RunspaceTimeout 
<Int32>] [-NoCloseOnTimeout] [-MaxQueue <Int32>] [-AppendLog] [-LogFile <String>] [-Quiet] [-Walkthrough] [<CommonParameters>]

DESCRIPTION

Function to control parallel processing using runspaces

Note that each runspace will not have access to variables and commands loaded in your session or in other runspaces by default.
This behaviour can be changed with parameters.

EXAMPLES

EXAMPLE 1

Each example uses Test-ForPacs.ps1 which includes the following code:
param($computer)

   if(test-connection $computer -count 1 -quiet -BufferSize 16){
       $object = [pscustomobject] @{
           Computer=$computer;
           Available=1;
           Kodak=$(
               if((test-path "\\$computer\c$\users\public\desktop\Kodak Direct View Pacs.url") -or (test-path "\\$computer\c$\documents and settings\all users\desktop\Kodak Direct View Pacs.url") ){"1"}else{"0"}
           )
       }
   }
   else{
       $object = [pscustomobject] @{
           Computer=$computer;
           Available=0;
           Kodak="NA"
       }
   }

   $object

EXAMPLE 2

Invoke-BluGenieParallel -scriptfile C:\public\Test-ForPacs.ps1 -inputobject $(get-content C:\pcs.txt) -runspaceTimeout 10 -throttle 10
Pulls list of PCs from C:\pcs.txt,
   Runs Test-ForPacs against each
   If any query takes longer than 10 seconds, it is disposed
   Only run 10 threads at a time

EXAMPLE 3

Invoke-BluGenieParallel -scriptfile C:\public\Test-ForPacs.ps1 -inputobject c-is-ts-91, c-is-ts-95
Runs against c-is-ts-91, c-is-ts-95 (-computername)
   Runs Test-ForPacs against each

EXAMPLE 4

$stuff = [pscustomobject] @{
ContentFile = "windows\system32\drivers\etc\hosts"
   Logfile = "C:\temp\log.txt"
}

$computers | Invoke-BluGenieParallel -parameter $stuff {
   $contentFile = join-path "\\$_\c$" $parameter.contentfile
   Get-Content $contentFile |
       set-content $parameter.logfile
}

This example uses the parameter argument.  This parameter is a single object.  To pass multiple items into the script block, we create a custom object (using a PowerShell v3 language) with properties we want to pass in.

Inside the script block, $parameter is used to reference this parameter object.  This example sets a content file, gets content from that file, and sets it to a predefined log file.

EXAMPLE 5

$test = 5
1..2 | Invoke-BluGenieParallel -ImportVariables {$_ * $test}

Add variables from the current session to the session state.  Without -ImportVariables $Test would not be accessible

EXAMPLE 6

$test = 5
1..2 | Invoke-BluGenieParallel {$_ * $Using:test}

Reference a variable from the current session with the $Using:<Variable> syntax.  Requires PowerShell 3 or later. Note that -ImportVariables parameter is no longer necessary.

PARAMETERS

ScriptBlock

-ScriptBlock <ScriptBlock>
   Scriptblock to run against all computers.
   
   You may use $Using:<Variable> language in PowerShell 3 and later.
   
       The parameter block is added for you, allowing behaviour similar to foreach-object:
           Refer to the input object as $_.
           Refer to the parameter parameter as $parameter
   
   <Type>String<Type>
   
   Required?                    false
   Position?                    1
   Default value                
   Accept pipeline input?       false
   Accept wildcard characters?  false

ScriptFile

-ScriptFile <Object>
   File to run against all input objects.  Must include parameter to take in the input object, or use $args.  Optionally, include parameter to take in parameter.  Example: C:\script.ps1
   
   <Type>String<Type>
   
   Required?                    false
   Position?                    named
   Default value                
   Accept pipeline input?       false
   Accept wildcard characters?  false

InputObject

-InputObject <PSObject>
   Run script against these specified objects.
   
   <Type>String<Type>
   
   Required?                    false
   Position?                    named
   Default value                
   Accept pipeline input?       true (ByValue)
   Accept wildcard characters?  false

Parameter

-Parameter <PSObject>
   This object is passed to every script block.  You can use it to pass information to the script block; for example, the path to a logging folder
   
       Reference this object as $parameter if using the scriptblock parameterset.
   
   <Type>String<Type>
   
   Required?                    false
   Position?                    named
   Default value                
   Accept pipeline input?       false
   Accept wildcard characters?  false

ImportVariables

-ImportVariables [<SwitchParameter>]
   If specified, get user session variables and add them to the initial session state
   
   <Type>SwitchParameter<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

ImportModules

-ImportModules [<SwitchParameter>]
   If specified, get loaded modules and pssnapins, add them to the initial session state
   
   <Type>SwitchParameter<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

ImportFunctions

-ImportFunctions [<SwitchParameter>]
   If specified, get loaded functions, and add them to the initial session state
   
   <Type>SwitchParameter<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

Throttle

-Throttle <Int32>
   Maximum number of threads to run at a single time.
   
   <Type>Int<Type>
   
   Required?                    false
   Position?                    named
   Default value                50
   Accept pipeline input?       false
   Accept wildcard characters?  false

SleepTimer

-SleepTimer <Int32>
   Milliseconds to sleep after checking for completed runspaces and in a few other spots.  I would not recommend dropping below 200 or increasing above 500
   
   <Type>Int<Type>
   
   Required?                    false
   Position?                    named
   Default value                1000
   Accept pipeline input?       false
   Accept wildcard characters?  false

RunspaceTimeout

-RunspaceTimeout <Int32>
   Maximum time in seconds a single thread can run.  If execution of your code takes longer than this, it is disposed.  Default: 0 (seconds)
   
   WARNING:  Using this parameter requires that maxQueue be set to throttle (it will be by default) for accurate timing.  Details here:
   http://gallery.technet.microsoft.com/Run-Parallel-Parallel-377fd430
   
   <Type>Int<Type>
   
   Required?                    false
   Position?                    named
   Default value                0
   Accept pipeline input?       false
   Accept wildcard characters?  false

NoCloseOnTimeout

-NoCloseOnTimeout [<SwitchParameter>]
   Do not dispose of timed out tasks or attempt to close the runspace if threads have timed out. This will prevent the script from hanging in certain situations where threads become non-responsive, at the 
   expense of leaking memory within the PowerShell host.
   
   <Type>Int<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

MaxQueue

-MaxQueue <Int32>
   Maximum number of powershell instances to add to runspace pool.  If this is higher than $throttle, $timeout will be inaccurate
   
   If this is equal or less than throttle, there will be a performance impact
   
   The default value is $throttle times 3, if $runspaceTimeout is not specified
   The default value is $throttle, if $runspaceTimeout is specified
   
   <Type>Int<Type>
   
   Required?                    false
   Position?                    named
   Default value                0
   Accept pipeline input?       false
   Accept wildcard characters?  false

AppendLog

-AppendLog [<SwitchParameter>]
   Append to existing log
   
   <Type>SwitchParameter<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

LogFile

-LogFile <String>
   Path to a file where we can log results, including run time for each thread, whether it completes, completes with errors, or times out.
   
   <Type>String<Type>
   
   Required?                    false
   Position?                    named
   Default value                
   Accept pipeline input?       false
   Accept wildcard characters?  false

Quiet

-Quiet [<SwitchParameter>]
   Disable progress bar
   
   <Type>SwitchParameter<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

Walkthrough

-Walkthrough [<SwitchParameter>]
   An automated process to walk through the current function and all the parameters
   
   <Type>SwitchParameter<Type>
   
   Required?                    false
   Position?                    named
   Default value                False
   Accept pipeline input?       false
   Accept wildcard characters?  false

CommonParameters

PreviousInvoke-BluGenieNetStatNextInvoke-BluGenieProcess

Last updated 3 years ago

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see .

about_CommonParameters