venerdì 13 agosto 2021

GPO - Filtri WMI per pc DESKTOP e PORTATILI

 Ciao a tutti,

sto preparando alcune GPO che vorrei applicare solo ai portatili in azienda (e a dir la verità neppure a tutti!!!).

Il mio primo scoglio e' proprio come distinguere un desktop da un portatile.

Per fare questo ho pensato di usare i WMI filtering, tramite cui è possibile recuperare alcune informazioni sul computer

Facendo riferimento a questa pagina:

https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem

Ho identificato due proprietà che mi possono essere utili:

PCSystemType e PCSystemTypeEx

La seconda e' disponibile solo da Windows 8.1 e Windows 2012 R2 in poi.

Quindi se:

PCSystemType=1 o 3 si tratta di PC Desktop (a dir la verita non so in quale categoria ricadano le workstation mobili!)

PCSystemType=2 si tratta di laptop

Sotto riporto un estratto dal sito su queste 2 proprieta

PCSystemType

Type of the computer in use, such as laptop, desktop, or Tablet.

Unspecified (0)

Desktop (1)

Mobile (2)

Workstation (3)

Enterprise Server (4)

SOHO Server (5) Small Office and Home Office (SOHO) Server

Appliance PC (6)

Performance Server (7)

Maximum (8)


PCSystemTypeEx

Type of the computer in use, such as laptop, desktop, or Tablet.

Windows Server 2012, Windows 8, Windows Server 2008 R2, Windows 7, Windows Server 2008 and Windows Vista not supported.

This property is not supported before Windows 8.1 and Windows Server 2012 R2.

Unspecified (0)

Desktop (1)

Mobile (2)

Workstation (3)

Enterprise Server (4)

SOHO Server (5)

Appliance PC (6)

Performance Server (7)

Slate (8)

Maximum (9)


Adesso devo definire la query per decidere la classe

DESKTOP

Namespace: root\CIMv2

Select * from Win32_ComputerSystem WHERE (PCSystemType = 1) or (PCSystemType = 3)

LAPTOP

Namespace: root\CIMv2

Select * from Win32_ComputerSystem WHERE (PCSystemType = 2)


Adesso devo aprire GPMC ed andare in WMI Filter e scegliere NEW.

Namespace: root\CIMv2

Description: PC DESKTOP

Query: Select * from Win32_ComputerSystem WHERE (PCSystemType = 1) or (PCSystemType = 3)

Fare lo stesso, modificando la query, per i portatili.

Direi che abbiamo finito.

NOTE

Inizialmente avevo pensato di usare questa query: Select * from Win32_Battery WHERE (BatteryStatus <> 0), ma il risultato sarebbe stato che un desktop con attaccato un UPS sarebbe passato per un portatile. :)


APPENDICE

WIN32-SYSTEMENCLOSURE

A dir la verita ci sarebbe anche un'altra proprieta che sarebbe utile allo scopo, ma per semplicita' ho preferito usare quella precedente.

Ad ogni modo va considerata come alternativa.

https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-systemenclosure

ChassisTypes

This value comes from the Type member of the System Enclosure or Chassis structure in the SMBIOS information.

Other (1)

Unknown (2)

Desktop (3)

Low Profile Desktop (4)

Pizza Box (5)

Mini Tower (6)

Tower (7)

Portable (8)

Laptop (9)

Notebook (10)

Hand Held (11)

Docking Station (12)

All in One (13)

Sub Notebook (14)

Space-Saving (15)

Lunch Box (16)

Main System Chassis (17)

Expansion Chassis (18)

SubChassis (19)

Bus Expansion Chassis (20)

Peripheral Chassis (21)

Storage Chassis (22)

Rack Mount Chassis (23)

Sealed-Case PC (24)

Tablet (30)

Convertible (31)

Detachable (32)


QUERY x LAPTOP

Namespace: root\CIMv2

Query:  select * from Win32_SystemEnclosure where ChassisTypes = "{8}" or ChassisTypes = "{9}" or ChassisTypes = "{10}" or ChassisTypes = "{11}" or ChassisTypes = "{12}" or ChassisTypes = "{14}" or ChassisTypes = "{18}" or ChassisTypes = "{21}"


WMI

WMI e' l'acronimo di Windows management instrumentation.

Cosa puo fare?

WMI (Windows Management Instrumentation) è un insieme di interfacce che permettono di interagire con le informazioni di sistema, interrogarle e modificarle.

Nel nostro caso abbiamo bisogno di trovare quella particolare classe che contiene la proprieta che consente di capire se il pc in questione e' un desktop oppure un portatile.

E' possibile interrogare WMI tramite powershell. Un tool grafico che ho utilizzato e' WmiExplorer.

Il problema e' che non sempre le proprieta sono chiare ed occorre fare qualche ricerca per trovare cio di cui abbiamo bisogno


NOTE

wmic, tool di interrogazione WMI e stato rimpiazzato da Get-WmiObject (powershell)

Get-WmiObject e' stato rimpiazzato, dalla versione 3.0 di powershell da Get-CimInstance


ESEMPI POWERSHELL

Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -Property *

Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -Property pcsystemtype


REFERENCE

https://www.linkedin.com/pulse/wmi-filtering-gpos-philip-cumiskey

https://social.technet.microsoft.com/Forums/en-US/8f802a56-a66e-495f-9e6f-48bfca341343/gpo-wmi-filter-for-laptops?forum=winserverGP

https://docs.microsoft.com/it-it/windows/win32/cimwin32prov/win32-operatingsystem

https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-systemenclosure

https://docs.microsoft.com/it-it/windows/win32/cimwin32prov/win32-computersystem

https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.pcsystemtype?view=powershellsdk-1.1.0

https://docs.microsoft.com/it-it/powershell/scripting/samples/collecting-information-about-computers?view=powershell-7.1

https://powershell.one/wmi/root/cimv2/win32_computersystem

https://docs.microsoft.com/it-it/dotnet/framework/wcf/diagnostics/wmi/

http://www.dotnethell.it/articles/WMI.aspx

https://github.com/vinaypamnani/wmie2/releases


Nessun commento:

Posta un commento