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

This topic contains 2 replies, has 2 voices, and was last updated by  37mm 2 years, 1 month ago.

  • Author
    Posts
  • #29172

    37mm
    Participant

    $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

  • #29173

    Dave Wyatt
    Moderator

    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
    
  • #29179

    37mm
    Participant

    Thank you!

You must be logged in to reply to this topic.