If I have some code that does this:
$corpall = Get-ADUser -filter * -properties company, extensionattribute8 $members = @() $members = $corpall | where {($_.company -like "blah*" -OR $_.company -like "bleh*") -AND ($_.extensionAttribute8 -like "NonExempt")}
and then I pass $members to a function like this:
AddMembersToGroup $members $group
The function looks like this:
function AddMembersToGroup { param($members, $group) if ($members.count -gt 0) { ForEach ($mbr in $members) { try { Add-ADGroupMember -Identity $group -Members $mbr } catch { Write-Verbose “ $($group.name) : $($mbr.displayname) : $($_.Exception.Message)” } } } Set-ADGroup -Server $server -Identity $group -Replace @{info="last updated on $date"} }
If there’s only one object in $members (which was defined as an array), will the AddMembersToGroup function still see $members as an array with one object, or will it see it as a single object?
submitted by /u/mkoch7811
[link] [comments]
The post passing an array to a function appeared first on How to Code .NET.