|
| 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