• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 888
  • Last Modified:

Powershell WMI and variables

Hi,

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?
0
Ball_Group
Asked:
Ball_Group
1 Solution
 
Chris DentPowerShell DeveloperCommented:
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

HTH

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now