This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rs = [runspacefactory]::CreateRunspacePool(1,5) | |
$rs.Open() | |
$ps = [powershell]::Create() | |
$Ps.RunspacePool = $rs | |
[void]$ps.AddScript({ | |
Write-Output 'Beginning Statement' | |
}).AddStatement().AddScript({ | |
Param ($Name) | |
Get-Process -Name $Name | |
}).AddParameter('Name','PowerShell').AddStatement().AddScript({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type -AssemblyName System.Drawing | |
$hash = [hashtable]::Synchronized(@{}) | |
$hash.text = "" | |
$window = New-Object System.Windows.Forms.Form | |
$window.Width = 1000 | |
$window.Height = 1000 | |
$windowTextBox = New-Object System.Windows.Forms.TextBox | |
$windowTextBox.Location = New-Object System.Drawing.Size(10,10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an array of computers to do work against | |
$Computers = “computer01”,”computer02”,”computer03”,”computer04”,”computer05” | |
# Create an empty array that we'll use later | |
$RunspaceCollection = @() | |
# This is the array we want to ultimately add our information to | |
[Collections.Arraylist]$qwinstaResults = @() | |
# Create a Runspace Pool with a minimum and maximum number of run spaces. (http://msdn.microsoft.com/en-us/library/windows/desktop/dd324626(v=vs.85).aspx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an array of computers to do work against | |
$Computers = “computer01”,”computer02”,”computer03”,”computer04”,”computer05” | |
# Create an empty array that we'll use later | |
$RunspaceCollection = @() | |
# This is the array we want to ultimately add our information to | |
$qwinstaResults = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList)) | |
# Create a Runspace Pool with a minimum and maximum number of run spaces. (http://msdn.microsoft.com/en-us/library/windows/desktop/dd324626(v=vs.85).aspx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
10 tips for better PowerShell | |
-Various tips and tricks with using PowerShell | |
The Art of Runspaces in PowerShell | |
-Using runspaces for multithreading | |
Event Everything! (PowerShell events) | |
-Covering everything from WMI events to .Net events using PowerShell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
This will return the rectangle position of a process window. | |
Values of the Rectangle in relation to pixel location on window: | |
Left; // x position of upper-left corner | |
Top; // y position of upper-left corner | |
Right; // x position of lower-right corner | |
Bottom; // y position of lower-right corner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Measure-Command { | |
$sessionstate = [system.management.automation.runspaces.initialsessionstate]::CreateDefault() | |
$runspacepool = [runspacefactory]::CreateRunspacePool(1, 10, $sessionstate, $Host) | |
$runspacepool.Open() | |
$ScriptBlock = { | |
Param ($File) | |
$tempHash = @{} | |
ForEach ($Item in $File) { | |
$RawFile = [activator]::CreateInstance([System.IO.StreamReader],@($Item, [System.Text.Encoding]::UTF8,$True,524288)).ReadToEnd() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Register the event subscription for the forwarded event | |
Register-EngineEvent -SourceIdentifier This.Nothing -Action { | |
Write-Host ("Date: {0}" -f $event.messagedata) -BackgroundColor Black -ForegroundColor Yellow | |
} | |
Start-Job -Name TestJob -ScriptBlock { | |
While ($True) { | |
Register-EngineEvent -SourceIdentifier This.Nothing -Forward | |
Start-Sleep -seconds 5 | |
New-Event -SourceIdentifier This.Nothing -Message ("[{0}] From PSJob" -f (Get-Date)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Module Builder | |
$Domain = [AppDomain]::CurrentDomain | |
$DynAssembly = New-Object System.Reflection.AssemblyName(([guid]::NewGuid().ToString())) | |
$AssemblyBuilder = $Domain.DefineDynamicAssembly($DynAssembly, [System.Reflection.Emit.AssemblyBuilderAccess]::Run) # Only run in memory | |
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(([guid]::NewGuid().ToString()), $False) | |
#endregion Module Builder | |
#region STRUCTs | |
#Order of creating these Structs is important | |
#region MyStruct | |
$Attributes = 'AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, BeforeFieldInit' |