I have a script that has 2 parts that I have an issue with. Part #1 is a series of variables, that have users that meet some criteria using Get-ADUser. Part #2, I wanted to add the system arrays from part one into a list, so that in part #3 add the data is added to one big array along with a $tag so that in part #4 (not shown) everything can be processed at once.
The important thing is that all variables in part #1 end up with a tag in a single array, and that it's easy to add to when more variables are added to part #1. The thinking behind this is that people can add to part #1, refer to it in part #2, and don't have to repeat the code in parts #3 and #4.
THE PROBLEM:
On line 2 of Part #3 I can't split out the $collection array into the array and the tag, to add to the $data array.
#1
...
$O365_TransitionGroupMembers = $O365_TransitionGroupMembers | Select-Object -Unique
#2
$collection = `
(($VIPUser),"O365_VIP"),
(($O365_TransitionGroupMembers),"O365_Transition")
...
#3
$collection | ForEach-Object {
$expression,$tag = $_.split(",")
$data = ForEach ($User in $expression) {
#Create new object for passing back the required information
$Result = New-Object PSObject
$Result | Add-Member -MemberType NoteProperty -name DistinguishedName -value NotSet
...
$Result.Tag = $tag
...
EDIT:
Both $collection and the $vars in part 1 are system arrays, the part 1 $vars look like get-aduser. The $collection looks like:
14:11 C:\Users\d>$collection | fl
Length : 106 LongLength : 106 Rank : 1 SyncRoot : {CN=XXX\, XXX,OU=XXX,OU=XXX,OU=Domain Objects,DC=XXX,DC=XXX,DC=XXX, CN=XXX\, XXX,OU=XXX,OU=XXX,OU=Domain Objects,DC=XXX,DC=XXX,DC=XXX, CN=XXX,OU=Resources,OU=XXX,OU=Domain Objects,DC=XXX,DC=XXX,DC=XXX, CN=XXX\, XXX,OU=XXX,OU=XXX,OU=Domain Objects,DC=XXX,DC=XXX,DC=XXX...} IsReadOnly : False IsFixedSize : True IsSynchronized : False Count : 106
O365_VIP
Length : 600 LongLength : 600 Rank : 1 SyncRoot : {CN=XXX\, XXX C,OU=XXX,OU=Users,OU=ME-DXB-IIR,OU=Domain Objects,DC=XXX,DC=XXX,XXX=net, CN=XXX\, XXXv C,OU=XXX,OU=Users,OU=ME-DXB-IIR,OU=Domain Objects,DC=XXX,DC=XXX,DC=XXX, CN=XXX\, XXX C,OU=XXX,OU=Users,OU=ME-DXB-IIR,OU=Domain Objects,DC=XXX,DC=XXX,DC=XXX, CN=XXX\, XXXOU=Contractors,OU=Users,OU=ME-DXB-IIR,OU=Domain Objects,DC=emea,DC=CorpLAN,DC=net...} IsReadOnly : False IsFixedSize : True IsSynchronized : False Count : 600O365_Transition
14:16 C:\Users\shielsd>$collection[0]
...
SamAccountName : XXX
SID : S-1-5-XXX-XXX-XXX-XXX-XXX
Surname : XXX
UserPrincipalName : XXX.XXX@XXX.XXX
DistinguishedName : CN=XXX\, XXX,OU=XXX,OU=XXXXXX,OU=Domain
Objects,DC=XXX,DC=XXX,DC=XXX
Enabled : True
ExtensionAttribute15 : XXX;XXX;O365_VIP
GivenName : XXX
Name : XXX, XXX
ObjectClass : user
ObjectGUID : XXX-XXX-XXX-XXX-XXX
SamAccountName : XXX
SID : S-1-5-21-XXX-XXX-XXX-XXX
Surname : XXX
UserPrincipalName : XXX.XXX@XXX.comO365_VIP
The error I receive is:
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADUser] does not contain a method named 'split'. At line:2 char:5 + $expression,$tag = $_.split(",") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (split:String) [], RuntimeException