0

I'm trying to create a table with two arrays and I'm not sure whats the best way to make this happen. Here is my code

$nomatchsam += $enabled.SamAccountName
$nomatch10 += $enabled.extensionAttribute10

I'd like to take these arrays and do something like this

% $nomatchsam |New-Object PSObject -Property @{

SamAccountName = $_;
extensionAttribute10 = $nomatch1
}

This is not working anyone know what I'm doing wrong?

JoeRod
  • 899
  • 8
  • 20
  • 30

2 Answers2

2

Your syntax is wrong so far as I know. It should be something more like:

$NewObject = New-Object PSObject -Property @{
    SamAccountName = $nomatchsam
    extensionAttribute10 = $nomatch1
}
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
0
1..1000 | %{$NewObject = New-Object PSObject -Property @{
    SamAccountName = $enabled.SamAccountName
    extensionAttribute10 = $enabled.extensionAttribute10
}}
$NewObject
JoeRod
  • 899
  • 8
  • 20
  • 30
  • 1
    the `1..1000 | %{}` loop is pointless. You just created the exact same object 1000 times. – TheMadTechnician Aug 11 '14 at 16:40
  • how else can I iterate through? Your code didn't iterate. – JoeRod Aug 11 '14 at 19:02
  • You have your arrays already existing. You don't need to iterate. Yours doesn't iterate either, it quite literally performs the exact same action 1000 times. – TheMadTechnician Aug 11 '14 at 19:11
  • 1..(($enabled.SamAccountName).count) worked, I cannot get your code to work but mine is working fine. I had to remove the arrays and it worked. – JoeRod Aug 11 '14 at 19:29