I’m getting computers that are part of a security group and outputting them to an hash table. However, the first two of the three entries are duplicates, even if I “Write-Host” foreach loop to show the status of what computer the scripts is processing.
Does anyone know if there is a gotcha I need to be handling somewhere?
The green text is each unique computer being handled by the foreach, with the yellow being the hash table output that’s in question.
You’re creating a psobject based on $hash, but $hash is only being populated if two conditions are met (the computer responds to pings, and you were able to fetch the folders under \computer\c$\users).
Depending on what you want to happen when computers who do NOT respond to pings or whose Users folders can’t be accessed, you would need to revise the code slightly. The simplest fix would be to put the New-Object call directly after the assignment to $hash. Something like this:
Dave, thank you! I took your advice and added some custom entries within an “else” and had that generate a different hash entry indicating remote connectivity failure.
I have the PSObject created in the right spot thanks to your advice.