I have a list of computer names and I need a report of their OU, their mangedby attribute and their name. I have created a stack with each setting I want but they are not lining up. For 650 computers the count attribute for both the managedby and OU stack are 650 but when I output the data to a txt file I only get 603 lines from the ManagedBy. This would be fine if the data lined up when combined but blank data does not appear to alter the stack when I add it to a txt file. My code is below. After I generate the stacks I export them to a txt file where I Have a macro that can truncate the data for me. Any help would be appreciated.
$stackDN = New-Object System.Collections.Stack
$stackMB = New-Object System.Collections.Stack
$stackNE = New-Object System.Collections.Stack
foreach($computer in $computers){
try{
Get-ADComputer -Identity $computer -Server $domain -Properties * -ErrorAction Stop
$object = Get-ADComputer -Identity $computer -Server $domain -Properties *
$stackDN.Push($object.DistinguishedName)
$mb = $object.ManagedBy
$stackMB.Push($object.ManagedBy)
$stackMB.push('MB not listed')
}
catch{
$stackNE.Push($computer)
}
}
$stackDN | Out-File -FilePath H:\dn.txt
$stackMB | out-file -FilePath H:\mb.txt
$stackNE | out-file -FilePath H:\ne.txt'