Created
May 12, 2015 17:52
-
-
Save brianddk/9519483db6e3abdb2c6f to your computer and use it in GitHub Desktop.
Raw Redirect in Powershell
This file contains hidden or 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
| $list = @() | |
| $psi = New-Object System.Diagnostics.ProcessStartInfo | |
| $psi.FileName = "C:\pcDrDan\Cygwin\bin\ls.exe" | |
| $psi.Arguments = "-l *.txt".Split(" ") | |
| $psi.WorkingDirectory = $pwd.Path | |
| $psi.UseShellExecute = $false | |
| $psi.ErrorDialog = $false | |
| $psi.RedirectStandardError = $false | |
| $psi.RedirectStandardInput = $false | |
| $psi.RedirectStandardOutput = $true | |
| $proc = [System.Diagnostics.Process]::Start($psi) | |
| $h = @{ "proc" = $proc; "psi" = $psi} | |
| $list += @(,$h) | |
| <# | |
| $psi = New-Object System.Diagnostics.ProcessStartInfo | |
| $psi.FileName = "C:\Windows\system32\findstr.exe" | |
| $psi.Arguments = "/i nov".Split(" ") | |
| $psi.WorkingDirectory = $pwd.Path | |
| $psi.UseShellExecute = $false | |
| $psi.ErrorDialog = $false | |
| $psi.RedirectStandardError = $false | |
| $psi.RedirectStandardInput = $true | |
| $psi.RedirectStandardOutput = $false | |
| $proc = [System.Diagnostics.Process]::Start($psi) | |
| $h = @{ "proc" = $proc; "psi" = $psi} | |
| $list += @(,$h) | |
| $list[0]."proc".StandardOutput.BaseStream.CopyTo($list[1]."proc".StandardInput.BaseStream) | |
| #> | |
| $out = New-Object System.IO.StreamWriter(".\rdi2.txt") | |
| $list[0]."proc".StandardOutput.BaseStream.CopyTo($out.BaseStream) | |
| $out.Close() | |
| <# | |
| $wmidiskblock = { | |
| Param($ComputerName = "LocalHost") | |
| Get-WmiObject -ComputerName $ComputerName -Class win32_logicaldisk | Where-Object {$_.drivetype -eq 3} | |
| } | |
| $Computers = @("arun-pc","JNJKRYSFPS01","psgusbrfps01") | |
| #Start all jobs | |
| ForEach($Computer in $Computers) | |
| { | |
| $Computer | |
| Start-Job -scriptblock $wmidiskblock -ArgumentList $Computer | |
| } | |
| Get-Job | Wait-Job | |
| $out = Get-Job | Receive-Job | |
| $out |export-csv wmi.csv | |
| #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment