Assign a variable to a computer name , What am I doing wrong

$a = Get-ADComputer -filter * | select name

$b = ($a|Select -ExpandProperty Name) -join “,”

Get-WmiObject -namespace root\wmi –class MSStorageDriver_FailurePredictStatus -ComputerName $b | Select pscomputername, PredictFailure | Format-Table –Autosize

This bit here:

$b = ($a|Select -ExpandProperty Name) -join ","

Is creating a single string variable which contains a bunch of computer names, separated by commas. What Get-WmiObject actually wants is an array of computer names. This is easy, as all you have to do is get rid of the -join operation (which is what turns an array into a separated string.) This should work:

$b = Get-ADComputer -filter * | select-object -ExpandProperty Name

Thank you!