Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell: Why don't these assignments match?

$
0
0

Okay, I admit it; I'm a total n00b. Take a look at this code scrap:

$colItems = Get-WmiObject -Class "Win32_ComputerSystem" -Namespace "root\CIMV2"

foreach ($objItem in $colItems) {
    Write-Host $objItem.Manufacturer
    [Environment]::SetEnvironmentVariable("Manufacturer", "$objItem.Manufacturer", "Machine")
    Write-Host $objItem.Model
    [Environment]::SetEnvironmentVariable("Model", "$objItem.Model", "Machine")
}

Write-Host $env:Manufacturer
Write-Host $env:Model

The results are: 

Dell Inc.
OptiPlex 7010

(Double-backslash)CO-ITS-025407\root\CIMV2:Win32_ComputerSystem.Name="CO-ITS-025407".Manufacturer
(Double-backslash)CO-ITS-025407\root\CIMV2:Win32_ComputerSystem.Name="CO-ITS-025407".Model

In other words, attempting to assign the WMI object attribute value results in two different outcomes. I need thevalue, not the path to the value. What gives? :(

Thanks.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>