• Stars
    star
    374
  • Rank 110,449 (Top 3 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Speed up PowerShell with simplified multithreading

Build status

Invoke-Parallel

This function will take in a script or scriptblock, and run it against specified objects(s) in parallel. It uses runspaces, as there are many situations where jobs or PSRemoting are not appropriate.

Instructions

# Download and unblock the file(s).
# Dot source the file.
    . "\\Path\To\Invoke-Parallel.ps1"


# Get help for the function
    Get-Help Invoke-Parallel -Full


# Use Invoke-Parallel with variables in your session

    $Number = 2
    1..10 | Invoke-Parallel -ImportVariables -ScriptBlock { $Number * $_ }


# Use the $Using Syntax, currently restricted to PowerShell v3 and later

    $Path = 'C:\temp\'

    'Server1', 'Server2' | Invoke-Parallel {

        #Create a log file for this server, use the root $Path
        $ThisPath = Join-Path $Using:Path "$_.log"
        "Doing something with $_" | Out-File -FilePath $ThisPath -Force

    }


# Import modules found in the current session

    #From https://psremoteregistry.codeplex.com/releases/view/65928
    Import-Module PSRemoteRegistry

    $ServerList | Invoke-Parallel -ImportModules -ScriptBlock {

        $Key = 'Software\Microsoft\Windows\CurrentVersion\Policies\System'
        Get-RegValue -ComputerName $_ -Hive LocalMachine -Key $Key |
            Select ComputerName, Value, Data

    }


# Want to time out items that take too long?

    1..5 | Invoke-Parallel -RunspaceTimeout 2 -ScriptBlock {

        "Starting $_"
        Start-Sleep -Seconds $_
        "If you see this, we didn't timeout $_"
    }


# Is one thread freezing up when you time it out, and preventing your scripting from moving on?

    $ServerList | Invoke-Parallel -RunspaceTimeout 10 -NoCloseOnTimeout -ScriptBlock {

            Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_ | select -Property PSComputerName, Caption, Version

    }

Some outdated notes and details are available on the TechNet Galleries submission.

Help!

Would love contributors, suggestions, feedback, and other help! Split this out at the suggestion of @vors to help enable collaboration.

Notes

More Repositories

1

PowerShell

Various PowerShell functions and scripts
PowerShell
934
star
2

PSDeploy

Simple PowerShell based deployments
PowerShell
343
star
3

PSSQLite

PowerShell module to query SQLite databases
PowerShell
287
star
4

PSDepend

PowerShell Dependency Handler
PowerShell
273
star
5

PSSlack

PowerShell module for simple Slack integration
PowerShell
266
star
6

PSExcel

A simple Excel PowerShell module
PowerShell
243
star
7

BuildHelpers

Helper functions for PowerShell CI/CD scenarios
PowerShell
208
star
8

SecretServer

Secret Server PowerShell Module
PowerShell
87
star
9

PSStackExchange

PowerShell module to query Stack Exchange API
PowerShell
80
star
10

PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
PowerShell
45
star
11

PSHTMLTable

PowerShell module to spice up ad hoc notifications and reports
PowerShell
37
star
12

Git-Presentation

Presentation materials for Git and GitHub TechSession
33
star
13

WritingModules

Material accompanying PowerShell + DevOps Summit session
PowerShell
31
star
14

PSDiskPart

DiskPart PowerShell Module
PowerShell
31
star
15

Infoblox

Infoblox PowerShell Module
PowerShell
30
star
16

PSNeo4j

Simple Neo4j PowerShell Wrapper
PowerShell
29
star
17

ADGrouper

Define dynamic AD security group membership via yaml
PowerShell
18
star
18

Dots

A janky, neo4j based CMDB glued together with PowerShell
PowerShell
15
star
19

Citrix.NetScaler

PowerShell module for working with Citrix NetScaler REST API
PowerShell
15
star
20

PSRT

PowerShell wrapper for Request Tracker
PowerShell
10
star
21

TireFire

A janky PowerShell module to simplify managing notes and their metadata
PowerShell
7
star
22

PSStash

Atlassian Stash PowerShell Module
PowerShell
7
star
23

PSPagerDuty

Simple PowerShell PagerDuty module
PowerShell
7
star
24

PSLDAPQueryLogging

PowerShell module to simplify configuring AD LDAP diagnostic logging
PowerShell
7
star
25

PSPuppetDB

Simple module for querying the PuppetDB API
PowerShell
6
star
26

Wait-Path

Wait for a path to exist
PowerShell
5
star
27

CommunityLightningDemos2017

Proposals, and eventually demo material for Community Lightning Demos
PowerShell
5
star
28

PSSensu

Simple PowerShell module for working with the Sensu Go API
PowerShell
3
star
29

SessionMaterials

Materials or links to materials from sessions I've participated in
PowerShell
3
star
30

AppVeyor-DSC-Test

POC to test DSC configurations on a fresh VM from AppVeyor
PowerShell
2
star
31

AppVReporting

App-V Reporting PowerShell Module
PowerShell
2
star
32

RamblingCookieMonster.github.io

CSS
2
star
33

lisa-kitchen-demo

Example used for Test-Kitchen demo
PowerShell
2
star
34

wip

Stuff that doesn't have a home yet
PowerShell
1
star
35

zAppVeyor-Explore

PowerShell
1
star