True or false

Welcome Forums General PowerShell Q&A True or false

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
3 years, 7 months ago.

  • Author
    Posts
  • #23624

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Think i might have cracked it,

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

    look good ?

  • #23627

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Thanks Tim, an exercise to learn powershell really ! 🙂

The topic ‘True or false’ is closed to new replies.