[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Powershell WMI and variables


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?
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



Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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