True or false

This topic contains 3 replies, has 2 voices, and was last updated by  Graham Beer 3 years, 3 months ago.

  • Author
  • #23624

    Graham Beer


    Hopefully this is easy for someone ! I'm new to this so go easy !

    I want to check through the WMI if the machine is Virtual and depending if it is or not give the Boolan result. (For SCCM package)

    I've got this so far, but cant figure out how to get "True" or "False" out of it.
    Get-CimInstance -Class Win32_ComputerSystem | Where-Object{$_.Manufacturer -like '*Virtual*'}

  • #23625

    Graham Beer

    Think i might have cracked it,

    $result = Get-CimInstance -Class Win32_ComputerSystem
    if ($result.Manufacturer -like "*virtual*") { "True" }

    look good ?

  • #23627

    Tim Pringle

    Hey Graham,

    That looks about right if you're wanting to actually return the text "True", as opposed to a boolean 0 or 1.

    If you're using SCCM though, unless you've got hardware inventories switched off, you can get this already from V_R_System, without the need to use PowerShell at all. Either directly against the SQL database as TransactSQL, or as part of a WQL query within SCCM itself. With the WQL approach, you can use a dynamic collection which will automatically be updated as new machines become available, and old ones removed.

  • #23628

    Graham Beer

    Thanks Tim, an exercise to learn powershell really ! 🙂

You must be logged in to reply to this topic.