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.