php – Object of class variant could not be converted to string

exception or error:

I’m receiving an error when pulling the Chassis Types from WMI

//Create new WMI connection
$WbemLocator = new COM ("WbemScripting.SWbemLocator");

//Connect to host
$WbemServices = $WbemLocator->ConnectServer('localhost', 'root\\cimv2');

//Set Impersonation Level
$WbemServices->Security_->ImpersonationLevel = 3;

//Get Chassis Types
$enclosure = $WbemServices->execQuery("Select ChassisTypes from Win32_SystemEnclosure ");

foreach($enclosure AS $e){
    $type = $e->ChassisTypes; //Type of device
}

Output:

Recoverable fatal error: Object of class variant could not be converted to string in…

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *