-1

I am looking to use a powershell script to WMI query the computer during post-install of the imaging sequence via MDT/SCCM. Actively there are multiple VB scripts to accomplish parts of the System Properties area (Manufacturer, Model, InstallDate, SerialNumber, etc.), and would like to consolidate this into a single script that does it all.

Running Powershell ISE as Administrator, so that wouldn't be causing for any permissions issues; the model information returns Macbook as I am testing on Windows 10 through Bootcamp.

Clear-Host
$Model = (Get-WmiObject -Class:Win32_ComputerSystem).Model
$RegKey = “HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\OEMInformation”
New-Item -Path $RegKey -Name Model -Type String -Value $Model –Force

After I ran the script, these were the results (shown below).

Name     Property
-----    --------
Model    (default) : MacBookPro11,1

However the value is not written to the registry. How could I go about the writing of the informaiton to the registry, while also allowing for multiple variables to be aligned in addition? All the values (subkeys) would need to be created and be placed at the same Registry Path of "OEMInformation".

Aim to include for Manufacturer, Model, Name, InstallDate, SystemType as well.

2 Answers2

1

If I understand you correctly, you're able to write to the registry, but you're unsure how to write multiple items to the same "path".

The Windows registry is contstructed by "Keys" and one or multiple values. Your "new-item" line above actually sets a value but you don't specify one so it looks like the "magic" default value is used. In order to set multiple ones in the same path, you'd use the Cmdlet Set-ItemProperty, for example using:

Set-ItemProperty -Path $RegKey -Name "Model" -value $Model

You can then have multiple "properties" in that path using the same technique (just use a different value for the "Name" parameter.

Trondh
  • 3,221
  • 1
  • 25
  • 34
  • The powershell return says that it is written, however when looking at the registry I see no entry for a string "Model" or the value of "MacBookPro11,1" to be accompanied to it. Would the "Set-ItemProperty" also create the string key (sorry if I am confusing) if one does not exist already? – Ed Montgomery Oct 28 '17 at 19:20
  • it would. Google "Set-itemproperty" "registry" and you should find a host of examples. – Trondh Oct 28 '17 at 19:24
  • Was able to determine that it was originally writing to the wrong destination, that is why I wasn't seeing it. However, if the return value for "$model" is a string with spaces in it, how can that be stored to allow for the entry to be written to registry? `$Model = (Get-WmiObject -Class:Win32_ComputerSystem).Model` return value is `HP Elitebook x360` – Ed Montgomery Oct 28 '17 at 20:35
  • It's still just a string, regardless of it having spaces. Did you try to run the code above? – Trondh Oct 29 '17 at 14:16
-1

I was able to get this resolved, thank you @Trondh for the assistance.

$Model = (Get-WmiObject -Class:Win32_ComputerSystem).Model
$RegPath = 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\OEMInformation'

New-Item $RegPath -Force | New-ItemProperty -Name Model -Value $Model -Force | Out-Null