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 Profile photo of 37mm 37mm 1 year, 9 months ago.

  • Author
    Posts
  • #29172
    Profile photo of 37mm
    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
    Profile photo of Dave Wyatt
    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
    Profile photo of 37mm
    37mm
    Participant

    Thank you!

You must be logged in to reply to this topic.