Confused about this script - regex split method and new-object error

Hi there - i am studying workflow basics and looking at training from pluralsight/trainsignal specifically Jeff Hicks ’ Powershell v3 New Features Deep Dive in the lesson on workflow and inlinescript i see the following script:

Workflow Get-Admin{
Param=(
[string]$Name=“administrator”
)

$properties=Inlinescript {
$hash=@{“Computername”=$PSComputername}
$text= net user $using:name |
where-object -filterscript {$_ -match “Password |Last Logon”}
#define a regex of at least 2 spaces
[regex]$rx="\s{2, }"
foreach($item in $text) {
#split each line
$data = $rx.Split($item)
$hash.Add($data[0],$data[1])
} #foreach
#write $hash as the output of InlineScript
} #inlinescript

$result = New-Object -type PSObject -property $properties
$result

} #endworkflow

Get-Admin

I am not understanding the $data = $rx.Split($item) part - why is he doing that? the output of net user “username” is already split ? not sure what the line he is using actually does . also when i try to run this script in ISE it complains about

New-Object : Cannot convert ‘System.Management.Automation.PSDataCollection`1[Syst
em.Management.Automation.PSObject]’ to the type ‘System.Collections.IDictionary’
required by parameter ‘Property’. Specified method is not supported.

also getting At line:2 char:1

  • Param=(

Cannot find the ‘Param=’ command. If this command is defined as a workflow, ensure it is defined before the workflow tha
+ CategoryInfo : ParserError: (:slight_smile: [], ParseException
+ FullyQualifiedErrorId : CommandNotFound

There should be no equal sign after Param in line 2.

$rx is defined (and commented in his code) as “at least two spaces”. So the split on $item occurs where it encounters at least two spaces. {2,} is a modifier that says minimum of 2, no maximum.

Thank you sir for that - do you know why i am getting an error with the New-Object cmdlet?
Also was looking at workflow sessions - i cannot understand why someone would run the following like:
Invoke-Command -session $whatever scriptblock{do something}

over My-workflow -paramater something -pscomputername $computers
why do one over the other: you can run both with -asjob and -persist or whatever - and still suspend the job if its long running and get the results from a different session?