Skip to content

Commit 9e50c4a

Browse files
committed
Get Windows Autopilot hardware hash
1 parent e727475 commit 9e50c4a

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Function GetWindowsAutopilotHardwareHash(ByRef strWindowsAutopilotHardwareHash)
2+
'region FunctionMetadata #######################################################
3+
' This function obtains the Windows Autopilot hardware hash (i.e., a raw blob used
4+
' to identify a device in the cloud)
5+
'
6+
' The function takes one positional argument (strWindowsAutopilotHardwareHash),
7+
' which is populated upon success with a string containing the Windows Autopilot
8+
' hardware hash.
9+
'
10+
' The function returns a 0 if the Windows Autopilot hardware hash was obtained
11+
' successfully. It returns a negative integer if an error occurred retrieving the
12+
' Windows Autopilot hardware hash. Finally, it returns a positive integer if the
13+
' Windows Autopilot hardware hash was obtained, but multiple MDM_DevDetail_Ext01
14+
' instances were present that contained data for the Windows Autopilot hardware
15+
' hash. When this happens, only the first MDM_DevDetail_Ext01 instance containing
16+
' data for the Windows Autopilot hardware hash is used.
17+
'
18+
' Example:
19+
' intReturnCode = GetWindowsAutopilotHardwareHash(strWindowsAutopilotHardwareHash)
20+
' If intReturnCode >= 0 Then
21+
' ' The Windows Autopilot hardware hash was retrieved successfully and is
22+
' ' stored in strWindowsAutopilotHardwareHash
23+
' End If
24+
'
25+
' Version: 1.0.20230424.0
26+
'endregion FunctionMetadata #######################################################
27+
28+
'region License ################################################################
29+
' Copyright 2023 Frank Lesniak
30+
'
31+
' Permission is hereby granted, free of charge, to any person obtaining a copy of
32+
' this software and associated documentation files (the "Software"), to deal in the
33+
' Software without restriction, including without limitation the rights to use,
34+
' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
35+
' Software, and to permit persons to whom the Software is furnished to do so,
36+
' subject to the following conditions:
37+
'
38+
' The above copyright notice and this permission notice shall be included in all
39+
' copies or substantial portions of the Software.
40+
'
41+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42+
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
43+
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
44+
' COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
45+
' AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
46+
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47+
'endregion License ################################################################
48+
49+
'region DownloadLocationNotice #################################################
50+
' The most up-to-date version of this script can be found on the author's GitHub repository
51+
' at https://github.com/franklesniak/sysadmin-accelerator
52+
'endregion DownloadLocationNotice #################################################
53+
54+
'region Acknowledgements #######################################################
55+
' Michael Niehaus, who wrote the script Get-WindowsAutoPilotInfo, which is where I
56+
' learned about this WMI namespace:
57+
' https://www.powershellgallery.com/packages/Get-WindowsAutoPilotInfo/
58+
'endregion Acknowledgements #######################################################
59+
60+
'region DependsOn ##############################################################
61+
' GetMDMDevDetailExt01Instances()
62+
' GetWindowsAutopilotHardwareHashUsingMDMDevDetailExt01Instances()
63+
'endregion DependsOn ##############################################################
64+
65+
Dim intFunctionReturn
66+
Dim arrMDMDevDetailExt01Instances
67+
Dim strResult
68+
69+
intFunctionReturn = 0
70+
71+
intFunctionReturn = GetMDMDevDetailExt01Instances(arrMDMDevDetailExt01Instances)
72+
If intFunctionReturn >= 0 Then
73+
' At least one MDM_DevDetail_Ext01 instance was retrieved successfully
74+
intFunctionReturn = GetWindowsAutopilotHardwareHashUsingMDMDevDetailExt01Instances(strResult, arrMDMDevDetailExt01Instances)
75+
If intFunctionReturn >= 0 Then
76+
' The computer manufacturer was retrieved successfully and is stored in strResult
77+
strWindowsAutopilotHardwareHash = strResult
78+
End If
79+
End If
80+
81+
GetWindowsAutopilotHardwareHash = intFunctionReturn
82+
End Function

0 commit comments

Comments
 (0)