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 supposed to return false