How to properly get System Model in PowerShell and set it as a parameter?

I need to use PowerShell to properly get the System Model of a PC and use the model number as a parameter so that I can run tasks specific to the model number. My code is a little more complex due to the fact that some of the methods returns values like ‘Not Available’, 'To be filled by O.E.M.'or ‘System Product Manufacturer’ - in these instances I do not want the $Model parameter to be ‘Not Available’, 'To be filled by O.E.M.'or ‘System Product Manufacturer’.

I have the following, but it doesn’t work as desired

    $BaseBoardManufacturer = Get-WmiObject Win32_BaseBoard | Select Manufacturer
if ((-not ([string]::IsNullOrWhiteSpace($BaseBoardManufacturer))) -and ($BaseBoardManufacturer.Manufacturer -ne 'Not Available') -or ($BaseBoardManufacturer.Manufacturer -ne 'System manufacturer'))
    {
        [String]$Manufacturer = ($BaseBoardManufacturer.Manufacturer).ToString()
    }
    
    $ProductManufacturer = Get-WmiObject -Class:Win32_ComputerSystemProduct | select Vendor
    if ((-not ([string]::IsNullOrWhiteSpace($ProductManufacturer))) -and ($ProductManufacturer.Vendor -ne 'Not Available') -or ($ProductManufacturer.Vendor -ne 'System manufacturer') -or ($ProductManufacturer.Vendor -ne 'To be filled by O.E.M.'))
    {
        [String]$Manufacturer = ($ProductManufacturer.Vendor).ToString()
    }
    
    $SystemManufacturer = Get-WmiObject -Class:Win32_ComputerSystem | select Manufacturer
    if ((-not ([string]::IsNullOrWhiteSpace($SystemManufacturer))) -and ($SystemManufacturer.Manufacturer -ne 'Not Available') -or ($SystemManufacturer.Manufacturer -ne 'System manufacturer') -or ($SystemManufacturer.Manufacturer -ne 'To be filled by O.E.M.'))
    {
        [String]$Manufacturer = ($SystemManufacturer.Manufacturer).ToString()
    }
    
    $BaseBoardProduct = Get-WmiObject Win32_BaseBoard | Select Product
    if ((-not ([string]::IsNullOrWhiteSpace($BaseBoardProduct))) -and ($BaseBoardProduct.Product -ne 'Not Available'))
    {
        [String]$Model = ($BaseBoardProduct.Product).ToString()
    }
    
    $ProductVersion = Get-WmiObject -Class:Win32_ComputerSystemProduct | select Version
    if ((!($ProductVersion.Version -ne 'System Version')) -xor (!($ProductVersion.Version -ne 'To be filled by O.E.M.')) -and (-not ([string]::IsNullOrWhiteSpace($ProductVersion))))
    {
        [String]$Model = ($ProductVersion.Version).ToString()
    }
    
    $SystemModel = Get-WmiObject -Class:Win32_ComputerSystem | select Model
    if ((-not ([string]::IsNullOrWhiteSpace($SystemModel))) -and ($SystemModel.Model -ne 'System Product Name') -or ($SystemModel.Model -ne 'To be filled by O.E.M.'))
    {
        [String]$Model = ($SystemModel.Model).ToString()
    }
    
    $SystemManufacturer = Get-WmiObject -Class:Win32_ComputerSystem | select Manufacturer
    if ((-not ([string]::IsNullOrWhiteSpace($SystemManufacturer))) -and ($SystemManufacturer.Manufacturer -ne 'Not Available') -or ($SystemManufacturer.Manufacturer -ne 'System manufacturer') -or ($SystemManufacturer.Manufacturer -ne 'To be filled by O.E.M.'))
    {
        [String]$Manufacturer = ($SystemManufacturer.Manufacturer).ToString()
    }
    
    if ($Manufacturer -like '*Lenovo*')
    {
        $ProductVersion = Get-WmiObject -Class:Win32_ComputerSystemProduct | select Version
    [String]$Model = ($ProductVersion.Version).ToString()
    }

I want e.g.

    ((!($ProductVersion.Version -ne 'System Version')) -or (!($ProductVersion.Version -ne 'To be filled by O.E.M.')) -and (-not ([string]::IsNullOrWhiteSpace($ProductVersion))))

to return false when the ProductVersion returns ‘To be filled by O.E.M.’ or ‘System Version’, but it returns true!

I’ve tried

    ((!($ProductVersion.Version -ne 'System Version')) -xor (!($ProductVersion.Version -ne 'To be filled by O.E.M.')) -and (-not ([string]::IsNullOrWhiteSpace($ProductVersion))))

and

    if ((-not ($SystemModel.Model -eq 'System Product Name')) -or (-not ($SystemModel.Model -eq 'To be filled by O.E.M.')) -and (-not ([string]::IsNullOrWhiteSpace($SystemModel))))

but I get ‘System Version’ set as the parameter instead of the Model Number, in other words the argument returns true when it is suppoesed to return false

Arthur,
Welcome to the forum. :wave:t4:

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

Thanks

https://learn.microsoft.com/en-us/answers/questions/1182527/how-to-properly-get-system-model-in-powershell-and

$BaseBoardProduct = Get-WmiObject Win32_BaseBoard | Where-Object {$_.Product -ne 'Not Available'} | Select-Object -ExpandProperty Product
if (-not ([string]::IsNullOrWhiteSpace($BaseBoardProduct)))
{
    $Model = $BaseBoardProduct
}

$ProductVersion = Get-WmiObject -Class:Win32_ComputerSystemProduct | Where-Object {$_.Version -ne 'System Version' -and $_.Version -ne 'To be filled by O.E.M.'} | Select-Object -ExpandProperty Version
if (-not ([string]::IsNullOrWhiteSpace($ProductVersion)))
{
    $Model = $ProductVersion
}

$SystemModel = Get-WmiObject -Class:Win32_ComputerSystem | Where-Object {$_.Model -ne 'System Product Name' -and $_.Model -ne 'To be filled by O.E.M.'} | Select-Object -ExpandProperty Model
if (-not ([string]::IsNullOrWhiteSpace($SystemModel)))
{
    $Model = $SystemModel
}

$SystemManufacturer = Get-WmiObject -Class:Win32_ComputerSystem | Where-Object {$_.Manufacturer -ne 'Not Available' -and $_.Manufacturer -ne 'System manufacturer' -and $_.Manufacturer -ne 'To be filled by O.E.M.'} | Select-Object -ExpandProperty Manufacturer
if (-not ([string]::IsNullOrWhiteSpace($SystemManufacturer)))
{
    $Manufacturer = $SystemManufacturer
}

if ($Manufacturer -like '*Lenovo*')
{
    $ProductVersion = Get-WmiObject -Class:Win32_ComputerSystemProduct | Select-Object -ExpandProperty Version
    $Model = $ProductVersion
}

solves my issue!

BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

Thanks for sharing