Created
April 20, 2016 22:13
-
-
Save sirsql/0c2bea1ac43c999472a8335a1efaf993 to your computer and use it in GitHub Desktop.
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
Function Convert-Size { | |
[cmdletbinding()] | |
Param ( | |
[parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)] | |
[Alias("Length")] | |
[int64]$Size | |
) | |
Begin { | |
If (-Not $ConvertSize) { | |
Write-Verbose ("Creating signature from Win32API") | |
$Signature = @" | |
[DllImport("Shlwapi.dll", CharSet = CharSet.Auto)] | |
public static extern long StrFormatByteSize( long fileSize, System.Text.StringBuilder buffer, int bufferSize ); | |
"@ | |
$Global:ConvertSize = Add-Type -Name SizeConverter -MemberDefinition $Signature -PassThru | out-null | |
} | |
Write-Verbose ("Building buffer for string") | |
$stringBuilder = New-Object Text.StringBuilder 1024 | |
} | |
Process { | |
Write-Verbose ("Converting {0} to upper most size" -f $Size) | |
$ConvertSize::StrFormatByteSize( $Size, $stringBuilder, $stringBuilder.Capacity ) | Out-Null | |
$stringBuilder.ToString() | |
} | |
} | |
Function Get-Test { | |
return 1; | |
} | |
#Here's where I'm falling down | |
#Tried passing as comma list, semi-comma list, CR list | |
#Saw that the Start-RSJob accepts string, but there doesn't seem to be any delimiter handling | |
[string]$Functionlist = @" | |
Convert-Size | |
Get-Test | |
"@ | |
Get-ChildItem $PWD -Directory | Start-RSJob -Name {$_.Name} -ScriptBlock { | |
[int64]$Bytes = (Get-ChildItem -Path $_.FullName -Force -Recurse | Measure-Object -Property length -Sum).Sum | |
[pscustomobject]@{ | |
Name = $_.Name | |
Size = Convert-Size -Size $Bytes | |
Size_bytes = $Bytes | |
} | |
Start-Sleep -Seconds (Get-Random -InputObject (1..5)) | |
} -FunctionsToLoad $Functionlist -Throttle 10 | Wait-RSJob -ShowProgress | | |
Receive-RSJob | Sort-Object -Property Size_bytes -Descending | |
Get-RSJob | Remove-RSJob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's where I'm falling down
Tried passing as comma list, semi-comma list, CR list
Saw that the Start-RSJob accepts string, but there doesn't seem to be any delimiter handling