Function faster than Workflow -> why ?


hi everyone,

i'm in little trouble because learned workflow , in general workflow faster function in case slower, , don't understand why. here code:

-------------------------------------------------

                  

workflow get-users
{
  [cmdletbinding(confirmimpact = 'low')]
  param
  (
    [parameter(mandatory = $true, position = 0)]
    [validatenotnull()]
    [psobject[]]$users,

    [parameter(mandatory = $true, position = 1)]
    [validatenotnull()]
    [string]$server,

    [parameter(mandatory = $true, position = 2)]
    [validatenotnull()]
    [pscredential]$cred
  )

  foreach -parallel ($user in $users.values)
  {
    $prop = get-aduser -identity $user -properties department, extensionattribute4, extensionattribute6, extensionattribute7 -server $server -credential $cred
    write-output $prop | out-file c:\users\public\scripts\$($prop.samaccountname).txt -append -encoding utf8  }

}
function get-fvusers
{
  [cmdletbinding(confirmimpact = 'low')]
  param
  (
    [parameter(mandatory = $true, position = 0)]
    [validatenotnull()]
    [psobject[]]$users,

    [parameter(mandatory = $true, position = 1)]
    [validatenotnull()]
    [string]$server,

    [parameter(mandatory = $true, position = 2)]
    [validatenotnull()]
    [pscredential]$cred
  )

  foreach ($user in $users.values)
  {
    $prop = get-aduser -identity $user -properties department, extensionattribute4, extensionattribute6, extensionattribute7 -server $server -credential $cred
    write-output $prop | out-file c:\users\public\scripts\$($prop.samaccountname).txt -append -encoding utf8
  }
}

measure-command -expression {
  get-users -users $dynarray -server $server -cred $cred
}

measure-command -expression {
  get-fvusers -users $dynarray -server $server -cred $cred
}

------------------------------------------------

the function @ least 4 5 times faster workfow. have got ideas ?

thank you,

arnaud h.



hi arnaud,

can't know in case, when parallel processing slower linear, means overhead of creating new runspace greater cost of performing payload.

also, please note assigning same position index each parameter pointless. try assigning incrementing (0, 1, 2) ones parameters. don't think has impact on performance, it's coding practice.

cheers,
fred


there's no place 127.0.0.1



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL