Jump to content

Recommended Posts

Posted (edited)

Hi all

 

I am trying to get laptops with compatible processor for windows 11 using script but following part is not working. can anyone advise

 

 

# Gather the data from the local system$processor = Get-WmiObject -Class Win32_Processor$ProcesorName2 = $processor.Name$ProcessorModel,$Speed = $ProcesorName2 -Split "CPU"# Compare the Processor with modules in arrayif ($ProcessorModel -in $Module){Write-Host "Procesor is compatible"}else {Write-Host $ProcessorModel "is not compatible"}

 

 

I have attached the scirpt

 

Thanks in advance

hardwareinfo4.ps1

Edited by Saadi_y
Posted (edited)

From my testing, issue appears to be whitespace in the $ProcessorModel variable - updating to trim the whitespace got the if working. Updated code, last line removes the whitespace:

# Gather the data from the local  system
$processor = Get-WmiObject -Class Win32_Processor
$ProcesorName2 = $processor.Name
$ProcessorModel,$Speed = $ProcesorName2 -Split "CPU"
$ProcessorModel = $ProcessorModel.TrimEnd(" ")

 

You can also tidy the $Speed variable to remove the "@" and whitespace:

# Gather the data from the local  system
$processor = Get-WmiObject -Class Win32_Processor
$ProcesorName2 = $processor.Name
$ProcessorModel,$Speed = $ProcesorName2 -Split "CPU"
$ProcessorModel = $ProcessorModel.TrimEnd(" ")
$Speed = $Speed -replace "@",""
$Speed = $Speed.Trim()

 

There's probably a more elegant way to do things, but this was quick and got it working.

Edited by ThomL
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...