Gather Hardware Hash and receive via Mail

I wrote a script to gather the Windows 10 AutoPilot hardware hash and receive this via e-mail. The current user’s Outlook profile sends the e-mail. The e-mail is available in sent items if you want to view it later.


The user is local admin on the device where you want to gather the Windows 10 Autopilot information from.

Outlook is installed and configured on the target device.

The script

This is the script and its syntax:

$Path = 'C:\temp\AutoPilotinfo.csv'
$ScriptPath = 'C:\temp\Autopilot.ps1'

$command = {
Set-ExecutionPolicy -ExecutionPolicy Bypass -Force
#Set Variables
$Path = 'C:\temp\AutoPilotinfo.csv'

if (!(Test-Path 'C:\temp')) {
    <# Action to perform if the condition is true #>
    New-Item -Path  C:\temp -Type directory 

## Install NUGEt
$installedPackageProvider = Get-PackageProvider
if ($installedPackageProvider.Name -notmatch "NuGet") {
    Install-PackageProvider -Name NuGet -force
     Write-Host("Install powershell module NuGet")

# Check if AutoPilotScript is installed
$InstalledScripts = Get-InstalledScript
If ($ -notcontains "Get-WindowsAutoPilotInfo") {
    Install-Script -Name Get-WindowsAutoPilotInfo -force
# collect Windows Autopilot info and Output to CSV
Get-WindowsAutoPilotInfo -OutputFile $Path

if (!(Test-Path 'C:\temp')) {
    <# Action to perform if the condition is true #>
    New-Item -Path  C:\temp -Type directory 
## Create ScriptFile
Set-Content -Path $ScriptPath -Value $command

#Run Script as admin to gather autopilot info
Start-Process Powershell -Verb RunAs -ArgumentList "-File $($ScriptPath) -ExPolicy ByPass" -Wait

#Send Mail via Outlook
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.Subject = "hardware Hash $($env:USERNAME)"
$Mail.Body = "This is the hardwarehash for $($env:USERNAME)"


Change the “$Mail.To” variable to the e-mailaddress where you want to send the e-mail to.


Make sure the Powershell script is available on the device:

After that, run it with Powershell:

You get a UAC prompt because some Powershell Modules are installed and you need admin permissions to run the script.

You see a Powershell windows pop-up and after that, when you check the send items of the user, a new send e-mail appears:

And of course, lastly, you see the hardware hash in my mailbox:

And that is how you can gather the hardware hash and receive it via mail. Just let your users run the script and you will see the hardware hashes in your mailbox.

Furthermore: You could also create a PowerApp which impersonates the mailbox and adds the hardware hashes automatically.


Microsoft Docs about AutoPilot

Other Posts:

Search for specific Mailbox Permissions
Bulk Remove Teams User

4 thoughts on “Gather Hardware Hash and receive via Mail”

  1. Niels
    I got the script to run and send a email but no attachment is being sent. Ran the script from the device and Autopilot is installed.

  2. I’m getting this when i run the script now.
    Cannot find this file. Verify the path and file name are correct.
    At line:48 char:1
    + $Mail.Attachments.add($Path)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException

    • Hi David,

      Thanks for your message. Did you change the path in the script? DOes the file exist on the machine? Did you run the script as admin?



Leave a Comment