If this has been answered please kindly point me to the solution, however, at this time I am unable to find a answer to this in the existing posts.
I am currently working with background jobs in powershell as to breakup a heavy process into parallel processes, to reduce the duration. The overall concept is working, however, I am running into an issue with passing a parent collection of ADgroup objects that are returned from Get-ADGroup into a job's script block.
The collection is passed just fine, however, the issue is some properties, namely description and member, have property entries on the object, but the values are missing once inside the script block. I verified that these values are there prior to entering the script block. I also verified that the scriptb lock is interpreting the type of object being passed correctly inside the script block but these values are empty once inside.
Oddly, if I serialize the object with ConvertTo-Json, the values are their in this format, just not in the .NET object form. I am wondering if it has to do with the serialization of the object when passed to the script block?
One last note, if I create a custom object and populate it with property and values from the ADGroup object and then hand that to the script block, everything is fine. I tried passing the object via the "$Using:var" construct as well as passing it explicitly via an argument list and defining type specific params in the script block.
Hopefully someone with a better understanding of the underlying architecture can shed some light on this. Below is a simplified version of what I am doing, outputting values to the file just to see what I am getting inside the script block, I can get SAM, but no Description or Member
$adgroups = Get-ADGroup -Server $domain -Properties Description, member -SearchBase $ou -LDAPFilter "(samaccountname=*)"
$ps = [powershell]::create()
[void]$ps.AddScript({
Param([ADGroup[]]$groups)
foreach ($group in $groups) {
"SAM: $($group.samAccountName)" | Out-File output.txt
"Description: $($group.description)" | Out-File output.txt -append
"Members: $($group.member)" | Out-File output.txt -append
}
}).AddParameter('groups', $adgroups)
$ps.Invoke()
$ps.Dispose()
Again, the property values are there before entering the script block, but only the values are empty once inside the script block.