This function will test if the hardware is Dell. The function will return $true if the hardware is Dell otherwise $false for any other vendor.
<#
.SYNOPSIS
Test if the hardware running is Dell
.DESCRIPTION
This test will return $true or $false depending on if the manufacturer of the hardware returned from WMI contains the string Dell.
#>
function Test-IsHardwareDell {
[cmdletbinding()]
param ()
# Try to get the manufacturer
Write-Verbose -Message 'Running WMI query to get Win32_ComputerSystem.Manufacturer'
try {
$Manufacturer = (Get-CimInstance -ClassName Win32_ComputerSystem -ErrorAction Stop | Select-Object -ExpandProperty Manufacturer -ErrorAction Stop)
}
catch {
# Exception running Get-Module
$Message = $_.Exception.message
Write-Error -Message 'Exception running WMI query:'
Write-Error -Message $Message
return $False
}
# Make sure an object was returned
if ( $Manufacturer ) {
Write-Verbose -Message "WMI query returned manufacturer '$($Manufacturer)'"
} else {
Write-Verbose -Message 'WMI query did not return any hardware manufacturer'
return $False
}
# Compare the manufacturer
if ( $Manufacturer -like '*Dell*') {
Write-Verbose -Message 'Manufacturer matched Dell'
return $True
} else {
Write-Verbose -Message 'Manufacturer did not match Dell'
return $False
}
}
Call the function without any arguments:
Test-IsHardwareDell