Powershell WMI and variables

Posted on 2011-05-07
Last Modified: 2012-05-11

Im currently creating a PS scripts, which determines the model of the computer, and then do some stuff with it, depending on which model it is.
But just for testing purpose i've created a Write-Host to view the output.

Im having a few problems regarding WMI and variables/output.

Heres my code:
$computerModel = Get-WmiObject Win32_Computersystem | Select-Object Model
Write-Host $computerModel

For my point of view it looks okay, but the output does not in my eyes:
@{Model=Latitude E6420}

How am i able to just get "Latitude E6420" in my variable?
Question by:Ball_Group
    1 Comment
    LVL 70

    Accepted Solution

    Despite you selecting a single attribute you still have an Object there. That's why you end up with the hash as output. You want either:
    # PowerShell 2 only
    $computerModel = Get-WmiObject Win32_Computersystem | Select-Object -ExpandProperty Model

    Open in new window

    Or this:
    $computerModel = (Get-WmiObject Win32_Computersystem).Model

    Open in new window



    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Why Use PowerShell? Recently, I was asked to come up with a quick way to find out what versions all of our SQL servers were currently running. Well, we have several thousand so taking a manual approach simply wasn't an option. We also didn't have t…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now