Skip to content

Instantly share code, notes, and snippets.

@sirsql
Created April 20, 2016 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirsql/0c2bea1ac43c999472a8335a1efaf993 to your computer and use it in GitHub Desktop.
Save sirsql/0c2bea1ac43c999472a8335a1efaf993 to your computer and use it in GitHub Desktop.
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
@sirsql
Copy link
Author

sirsql commented Apr 20, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment