Verify IIS Installation:
Ensure that IIS is installed on the server. The class Win32_PerfRawData_W3SVC_WebService is specific to IIS, and if IIS is not installed or running, this class will not return data.
To check if IIS is installed:
Open Server Manager → Go to Manage → Add Roles and Features → Verify that Web Server (IIS) is installed.
IIS performance counters must be enabled for the Win32_PerfRawData_W3SVC_WebService class to retrieve data.
To verify and enable IIS performance counters:
Open Command Prompt as an administrator.
Run the following commands to enable the counter :
lodctr /e:W3SVC
After enabling the counters, restart the WMI service to refresh the data
net stop winmgmt
net start winmgmt
Get-WmiObject -Namespace root\cimv2 -Class Win32_PerfRawData_W3SVC_WebService | Where-Object {$_.Name -eq "_Total"}