|
| 1 | +Function GetWindowsAutopilotHardwareHashUsingMDMDevDetailExt01Instances(ByRef strWindowsAutopilotHardwareHash, ByVal arrMDMDevDetailExt01Instances) |
| 2 | + 'region FunctionMetadata ####################################################### |
| 3 | + ' Assuming that arrMDMDevDetailExt01Instances represents an array / collection of |
| 4 | + ' the instances of the class MDM_DevDetail_Ext01., this function obtains the |
| 5 | + ' Windows Autopilot hardware hash (i.e., a raw blob used to identify a device in |
| 6 | + ' the cloud) |
| 7 | + ' |
| 8 | + ' The function takes two positional arguments: |
| 9 | + ' - The first argument (strWindowsAutopilotHardwareHash) is populated upon success |
| 10 | + ' with a string containing the Windows Autopilot hardware hash. |
| 11 | + ' - The second argument (arrMDMDevDetailExt01Instances) is an array/collection of |
| 12 | + ' objects of class MDM_DevDetail_Ext01 |
| 13 | + ' |
| 14 | + ' The function returns a 0 if the Windows Autopilot hardware hash was obtained |
| 15 | + ' successfully. It returns a negative integer if an error occurred retrieving the |
| 16 | + ' Windows Autopilot hardware hash. Finally, it returns a positive integer if the |
| 17 | + ' Windows Autopilot hardware hash was obtained, but multiple MDM_DevDetail_Ext01 |
| 18 | + ' instances were present that contained data for the Windows Autopilot hardware |
| 19 | + ' hash. When this happens, only the first MDM_DevDetail_Ext01 instance containing |
| 20 | + ' data for the Windows Autopilot hardware hash is used. |
| 21 | + ' |
| 22 | + ' Example: |
| 23 | + ' intReturnCode = GetMDMDevDetailExt01Instances(arrMDMDevDetailExt01Instances) |
| 24 | + ' If intReturnCode >= 0 Then |
| 25 | + ' ' At least one MDM_DevDetail_Ext01 instance was retrieved successfully |
| 26 | + ' intReturnCode = GetWindowsAutopilotHardwareHashUsingMDMDevDetailExt01Instances(strWindowsAutopilotHardwareHash, arrMDMDevDetailExt01Instances) |
| 27 | + ' If intReturnCode >= 0 Then |
| 28 | + ' ' The Windows Autopilot hardware hash was retrieved successfully and is |
| 29 | + ' ' stored in strWindowsAutopilotHardwareHash |
| 30 | + ' End If |
| 31 | + ' End If |
| 32 | + ' |
| 33 | + ' Version: 1.0.20230424.0 |
| 34 | + 'endregion FunctionMetadata ####################################################### |
| 35 | + |
| 36 | + 'region License ################################################################ |
| 37 | + ' Copyright 2023 Frank Lesniak |
| 38 | + ' |
| 39 | + ' Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 40 | + ' this software and associated documentation files (the "Software"), to deal in the |
| 41 | + ' Software without restriction, including without limitation the rights to use, |
| 42 | + ' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 43 | + ' Software, and to permit persons to whom the Software is furnished to do so, |
| 44 | + ' subject to the following conditions: |
| 45 | + ' |
| 46 | + ' The above copyright notice and this permission notice shall be included in all |
| 47 | + ' copies or substantial portions of the Software. |
| 48 | + ' |
| 49 | + ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 50 | + ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 51 | + ' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 52 | + ' COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 53 | + ' AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 54 | + ' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 55 | + 'endregion License ################################################################ |
| 56 | + |
| 57 | + 'region DownloadLocationNotice ################################################# |
| 58 | + ' The most up-to-date version of this script can be found on the author's GitHub |
| 59 | + ' repository at https://github.com/franklesniak/sysadmin-accelerator |
| 60 | + 'endregion DownloadLocationNotice ################################################# |
| 61 | + |
| 62 | + 'region Acknowledgements ####################################################### |
| 63 | + ' Michael Niehaus, who wrote the script Get-WindowsAutoPilotInfo, which is where I |
| 64 | + ' learned about this WMI namespace: |
| 65 | + ' https://www.powershellgallery.com/packages/Get-WindowsAutoPilotInfo/ |
| 66 | + 'endregion Acknowledgements ####################################################### |
| 67 | + |
| 68 | + 'region DependsOn ############################################################## |
| 69 | + ' TestObjectForData() |
| 70 | + ' TestObjectIsAnyTypeOfInteger() |
| 71 | + 'endregion DependsOn ############################################################## |
| 72 | + |
| 73 | + Dim intFunctionReturn |
| 74 | + Dim intReturnMultiplier |
| 75 | + Dim intTemp |
| 76 | + Dim intCounterA |
| 77 | + Dim strInterimResult |
| 78 | + Dim strOldInterimResult |
| 79 | + Dim strResultToReturn |
| 80 | + Dim intCountOfHardwareHashes |
| 81 | + |
| 82 | + Err.Clear |
| 83 | + |
| 84 | + intFunctionReturn = 0 |
| 85 | + intReturnMultiplier = 128 |
| 86 | + strInterimResult = "" |
| 87 | + strResultToReturn = "" |
| 88 | + intCountOfHardwareHashes = 0 |
| 89 | + |
| 90 | + If TestObjectForData(arrMDMDevDetailExt01Instances) <> True Then |
| 91 | + intFunctionReturn = intFunctionReturn + (-1 * intReturnMultiplier) |
| 92 | + Else |
| 93 | + On Error Resume Next |
| 94 | + intTemp = arrMDMDevDetailExt01Instances.Count |
| 95 | + If Err Then |
| 96 | + On Error Goto 0 |
| 97 | + Err.Clear |
| 98 | + intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier) |
| 99 | + Else |
| 100 | + On Error Goto 0 |
| 101 | + If TestObjectIsAnyTypeOfInteger(intTemp) = False Then |
| 102 | + intFunctionReturn = intFunctionReturn + (-3 * intReturnMultiplier) |
| 103 | + Else |
| 104 | + If intTemp < 0 Then |
| 105 | + intFunctionReturn = intFunctionReturn + (-4 * intReturnMultiplier) |
| 106 | + ElseIf intTemp = 0 Then |
| 107 | + intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier) |
| 108 | + Else |
| 109 | + For intCounterA = 0 To (intTemp - 1) |
| 110 | + strOldInterimResult = strInterimResult |
| 111 | + On Error Resume Next |
| 112 | + strInterimResult = arrMDMDevDetailExt01Instances.ItemIndex(intCounterA).DeviceHardwareData |
| 113 | + If Err Then |
| 114 | + On Error Goto 0 |
| 115 | + Err.Clear |
| 116 | + strInterimResult = strOldInterimResult |
| 117 | + Else |
| 118 | + On Error Goto 0 |
| 119 | + If TestObjectForData(strInterimResult) <> True Then |
| 120 | + strInterimResult = strOldInterimResult |
| 121 | + Else |
| 122 | + ' Found a result with a real hardware hash |
| 123 | + If TestObjectForData(strResultToReturn) = False Then |
| 124 | + strResultToReturn = strInterimResult |
| 125 | + End If |
| 126 | + intCountOfHardwareHashes = intCountOfHardwareHashes + 1 |
| 127 | + End If |
| 128 | + End If |
| 129 | + Next |
| 130 | + End If |
| 131 | + End If |
| 132 | + End If |
| 133 | + End If |
| 134 | + |
| 135 | + If intFunctionReturn >= 0 Then |
| 136 | + ' No error has occurred yet |
| 137 | + If intCountOfHardwareHashes = 0 Then |
| 138 | + ' No result found |
| 139 | + intFunctionReturn = intFunctionReturn + (-5 * intReturnMultiplier) |
| 140 | + Else |
| 141 | + intFunctionReturn = intCountOfHardwareHashes - 1 |
| 142 | + End If |
| 143 | + End If |
| 144 | + |
| 145 | + If intFunctionReturn >= 0 Then |
| 146 | + strWindowsAutopilotHardwareHash = strResultToReturn |
| 147 | + End If |
| 148 | + |
| 149 | + GetWindowsAutopilotHardwareHashUsingMDMDevDetailExt01Instances = intFunctionReturn |
| 150 | +End Function |
0 commit comments