True or false

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Graham Beer Graham Beer 1 year, 8 months ago.

  • Author
    Posts
  • #23624
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi,

    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
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Think i might have cracked it,

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

    look good ?

  • #23627
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    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
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Thanks Tim, an exercise to learn powershell really ! 🙂

You must be logged in to reply to this topic.