Skip to content

Commit e727475

Browse files
committed
Get MDM_DevDetail_Ext01 class instances, HW hash
1 parent b20be37 commit e727475

File tree

2 files changed

+251
-0
lines changed

2 files changed

+251
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Function GetMDMDevDetailExt01Instances(ByRef arrMDMDevDetailExt01Instances)
2+
'region FunctionMetadata #######################################################
3+
' This function retrieves the available instances as objects of the class
4+
' MDM_DevDetail_Ext01. This class is one of several that provides device-specific
5+
' parameters relevant to the Open Mobile Alliance (OMA) device management (DM;
6+
' together: OMA-DM) server.
7+
'
8+
' The MDM_DevDetail_Ext01 class contains two useful properties:
9+
' - DeviceHardwareData: A string that contains the device's unique identifier
10+
' (hardware hash). This property was added in Windows 10 version 1703. It
11+
' returns a base64 encoded string of the hardware parameters of a device.
12+
' - WLANMACAddress: A string that contains the MAC address of the device's active
13+
' wireless network adapter. This property was added in Windows 10 version 1511.
14+
'
15+
' The function takes one positional argument (arrMDMDevDetailExt01Instances), which
16+
' is populated upon success with a collection of instances of the type
17+
' MDM_DevDetail_Ext01
18+
'
19+
' The function returns 0 if MDM_DevDetail_Ext01 instances were retrieved
20+
' successfully, and there was one MDM_DevDetail_Ext01 instance (as expected). If no
21+
' MDM_DevDetail_Ext01 objects could be retrieved, then the function returns a
22+
' negative number. If there are unexpectedly multiple instances of
23+
' MDM_DevDetail_Ext01, then the function returns a positive number equal to the
24+
' number of WMI instances retrieved minus one.
25+
'
26+
' Example:
27+
' intReturnCode = GetMDMDevDetailExt01Instances(arrMDMDevDetailExt01Instances)
28+
' If intReturnCode = 0 Then
29+
' ' The MDM_DevDetail_Ext01 instance was retrieved successfully and is
30+
' ' available at arrMDMDevDetailExt01Instances.ItemIndex(0)
31+
' ElseIf intReturnCode > 0 Then
32+
' ' More than one MDM_DevDetail_Ext01 instance was retrieved, which is
33+
' ' unexpected.
34+
' Else
35+
' ' An error occurred and no MDM_DevDetail_Ext01 instances were retrieved
36+
' End If
37+
'
38+
' Version: 1.0.20230424.0
39+
'endregion FunctionMetadata #######################################################
40+
41+
'region License ################################################################
42+
' Copyright 2023 Frank Lesniak
43+
'
44+
' Permission is hereby granted, free of charge, to any person obtaining a copy of
45+
' this software and associated documentation files (the "Software"), to deal in the
46+
' Software without restriction, including without limitation the rights to use,
47+
' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
48+
' Software, and to permit persons to whom the Software is furnished to do so,
49+
' subject to the following conditions:
50+
'
51+
' The above copyright notice and this permission notice shall be included in all
52+
' copies or substantial portions of the Software.
53+
'
54+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55+
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
56+
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
57+
' COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
58+
' AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
59+
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60+
'endregion License ################################################################
61+
62+
'region DownloadLocationNotice #################################################
63+
' The most up-to-date version of this script can be found on the author's GitHub
64+
' repository at https://github.com/franklesniak/sysadmin-accelerator
65+
'endregion DownloadLocationNotice #################################################
66+
67+
'region Acknowledgements #######################################################
68+
' Michael Niehaus, who wrote the script Get-WindowsAutoPilotInfo, which is where I
69+
' learned about this WMI namespace:
70+
' https://www.powershellgallery.com/packages/Get-WindowsAutoPilotInfo/
71+
'
72+
' Microsoft, for publishing some details on the MDM_DevDetail_Ext01 class:
73+
' https://learn.microsoft.com/en-us/windows/win32/dmwmibridgeprov/mdm-devdetail-ext01
74+
'
75+
' Microsoft, for publishing details on the DevDetail CSP:
76+
' https://learn.microsoft.com/en-us/windows/client-management/mdm/devdetail-csp
77+
'endregion Acknowledgements #######################################################
78+
79+
'region DependsOn ##############################################################
80+
' ConnectLocalMDMWMIBridgeNamespace()
81+
' GetMDMDevDetailExt01InstancesUsingWMINamespace()
82+
'endregion DependsOn ##############################################################
83+
84+
Dim intFunctionReturn
85+
Dim intReturnMultiplier
86+
Dim intReturnCode
87+
Dim objSWbemServicesMDMWMIBridgeNamespace
88+
89+
intFunctionReturn = 0
90+
intReturnMultiplier = 1
91+
92+
intReturnCode = ConnectLocalMDMWMIBridgeNamespace(objSWbemServicesMDMWMIBridgeNamespace)
93+
If intReturnCode < 0 Then
94+
intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier)
95+
Else
96+
intReturnCode = GetMDMDevDetailExt01InstancesUsingWMINamespace(arrMDMDevDetailExt01Instances, objSWbemServicesMDMWMIBridgeNamespace)
97+
intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier)
98+
End If
99+
100+
GetMDMDevDetailExt01Instances = intFunctionReturn
101+
End Function
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
Function GetMDMDevDetailExt01InstancesUsingWMINamespace(ByRef arrMDMDevDetailExt01Instances, ByVal objWMINamespace)
2+
'region FunctionMetadata #######################################################
3+
' Assuming that objWMINamespace represents a successful connection to the mobile
4+
' device management (MDM) WMI Bridge Namespace ("root\cimv2\mdm\dmmap"), this
5+
' function retrieves the available instances as objects of the class
6+
' MDM_DevDetail_Ext01. This class is one of several that provides device-specific
7+
' parameters relevant to the Open Mobile Alliance (OMA) device management (DM;
8+
' together: OMA-DM) server.
9+
'
10+
' The MDM_DevDetail_Ext01 class contains two useful properties:
11+
' - DeviceHardwareData: A string that contains the device's unique identifier
12+
' (hardware hash). This property was added in Windows 10 version 1703. It
13+
' returns a base64 encoded string of the hardware parameters of a device.
14+
' - WLANMACAddress: A string that contains the MAC address of the device's active
15+
' wireless network adapter. This property was added in Windows 10 version 1511.
16+
'
17+
' The function takes two positional arguments:
18+
' - The first argument (arrMDMDevDetailExt01Instances) is populated upon success
19+
' with a collection of instances of the class MDM_DevDetail_Ext01
20+
' - The second argument (objWMINamespace) is a WMI Namespace connection argument
21+
' that must already be connected to the WMI namespace root\cimv2\mdm\dmmap
22+
'
23+
' The function returns 0 if MDM_DevDetail_Ext01 instances were retrieved
24+
' successfully, and there was one MDM_DevDetail_Ext01 instance (as expected). If no
25+
' MDM_DevDetail_Ext01 objects could be retrieved, then the function returns a
26+
' negative number. If there are unexpectedly multiple instances of
27+
' MDM_DevDetail_Ext01, then the function returns a positive number equal to the
28+
' number of WMI instances retrieved minus one.
29+
'
30+
' Note: Requires Windows 10 or newer, and a client operating system (not Windows
31+
' Server)
32+
'
33+
' Example:
34+
' intReturnCode = ConnectLocalMDMWMIBridgeNamespace(objSWbemServicesMDMWMIBridgeNamespace)
35+
' If intReturnCode = 0 Then
36+
' ' Successfully connected to the local computer's MDM WMI Bridge Namespace
37+
' intReturnCode = GetMDMDevDetailExt01InstancesUsingWMINamespace(arrMDMDevDetailExt01Instances, objSWbemServicesMDMWMIBridgeNamespace)
38+
' If intReturnCode = 0 Then
39+
' ' The MDM_DevDetail_Ext01 instance was retrieved successfully and is
40+
' ' available at arrMDMDevDetailExt01Instances.ItemIndex(0)
41+
' ElseIf intReturnCode > 0 Then
42+
' ' More than one MDM_DevDetail_Ext01 instance was retrieved, which is
43+
' ' unexpected.
44+
' Else
45+
' ' An error occurred and no MDM_DevDetail_Ext01 instances were retrieved
46+
' End If
47+
' End If
48+
'
49+
' Version: 1.0.20230424.0
50+
'endregion FunctionMetadata #######################################################
51+
52+
'region License ################################################################
53+
' Copyright 2023 Frank Lesniak
54+
'
55+
' Permission is hereby granted, free of charge, to any person obtaining a copy of
56+
' this software and associated documentation files (the "Software"), to deal in the
57+
' Software without restriction, including without limitation the rights to use,
58+
' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
59+
' Software, and to permit persons to whom the Software is furnished to do so,
60+
' subject to the following conditions:
61+
'
62+
' The above copyright notice and this permission notice shall be included in all
63+
' copies or substantial portions of the Software.
64+
'
65+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66+
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
67+
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
68+
' COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
69+
' AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
70+
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71+
'endregion License ################################################################
72+
73+
'region DownloadLocationNotice #################################################
74+
' The most up-to-date version of this script can be found on the author's GitHub
75+
' repository at https://github.com/franklesniak/sysadmin-accelerator
76+
'endregion DownloadLocationNotice #################################################
77+
78+
'region Acknowledgements #######################################################
79+
' Michael Niehaus, who wrote the script Get-WindowsAutoPilotInfo, which is where I
80+
' learned about this WMI namespace:
81+
' https://www.powershellgallery.com/packages/Get-WindowsAutoPilotInfo/
82+
'
83+
' Microsoft, for publishing some details on the MDM_DevDetail_Ext01 class:
84+
' https://learn.microsoft.com/en-us/windows/win32/dmwmibridgeprov/mdm-devdetail-ext01
85+
'
86+
' Microsoft, for publishing details on the DevDetail CSP:
87+
' https://learn.microsoft.com/en-us/windows/client-management/mdm/devdetail-csp
88+
'endregion Acknowledgements #######################################################
89+
90+
'region DependsOn ##############################################################
91+
' TestObjectForData()
92+
' TestObjectIsAnyTypeOfInteger()
93+
'endregion DependsOn ##############################################################
94+
95+
Dim intFunctionReturn
96+
Dim intReturnMultiplier
97+
Dim arrWorkingMDMDevDetailExt01Instances
98+
Dim intTemp
99+
100+
Err.Clear
101+
102+
intFunctionReturn = 0
103+
intReturnMultiplier = 1
104+
105+
If TestObjectForData(objWMINamespace) <> True Then
106+
intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier)
107+
Else
108+
On Error Resume Next
109+
Set arrWorkingMDMDevDetailExt01Instances = objWMINamespace.InstancesOf("MDM_DevDetail_Ext01")
110+
If Err Then
111+
On Error Goto 0
112+
Err.Clear
113+
intFunctionReturn = intFunctionReturn + (-3 * intReturnMultiplier)
114+
Else
115+
intTemp = arrWorkingMDMDevDetailExt01Instances.Count
116+
If Err Then
117+
On Error Goto 0
118+
Err.Clear
119+
intFunctionReturn = intFunctionReturn + (-4 * intReturnMultiplier)
120+
Else
121+
On Error Goto 0
122+
If TestObjectIsAnyTypeOfInteger(intTemp) = False Then
123+
intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier)
124+
Else
125+
If intTemp < 0 Then
126+
intFunctionReturn = intFunctionReturn + (-6 * intReturnMultiplier)
127+
Else
128+
' intTemp >= 0
129+
intFunctionReturn = intTemp - 1
130+
' -1 would be returned if there are no MDM_DevDetail_Ext01 instances
131+
End If
132+
End If
133+
End If
134+
End If
135+
End If
136+
137+
If intFunctionReturn >= 0 Then
138+
On Error Resume Next
139+
Set arrMDMDevDetailExt01Instances = objWMINamespace.InstancesOf("MDM_DevDetail_Ext01")
140+
If Err Then
141+
On Error Goto 0
142+
Err.Clear
143+
intFunctionReturn = (-7 * intReturnMultiplier)
144+
Else
145+
On Error Goto 0
146+
End If
147+
End If
148+
149+
GetMDMDevDetailExt01InstancesUsingWMINamespace = intFunctionReturn
150+
End Function

0 commit comments

Comments
 (0)