Windows Autopilot / Get-WindowsAutoPilotInfo Script

We need to add a targeted device into Intune under Windows Autopilot Devices.
When you first switch on a device, it will begin the out-of-box setup. We need to grab the full baseboard serial number.


Microsoft has provided a PowerShell script that can be used to grab serial numbers.

See: https://www.powershellgallery.com/packages/Get-WindowsAutopilotInfo


Easiest way to install this script is to open Windows PowerShell as Administrator.

You can do this by right clicking the Start Menu -> Select Windows PowerShell (Admin)

Copy the following into PowerShell:
• Install-Script -Name Get-WindowsAutoPilotInfo

It may ask you to allow the following: Enter ‘Y’ or ‘A’ when needed.

This will install the script here: C:\Program Files\WindowsPowerShell\Scripts

If you attempt to run this script, you most likely receive a ‘ExecutionPolicy’ error. Instead of setting the execution policy as unrestricted on each device, we can create a .bat file to set it to ‘Unrestricted’ and execute the script.

PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command %~dp0Get-WindowsAutoPilotInfo.ps1 -ComputerName $env:computername -OutputFile %~dp0computers.csv -append

Save the above in a NotePad file then save as .bat – This needs to be saved in the same folder as the Get-WindowsAutoPilotInfo.ps1 script

PowerShell – This runs the following commands in PowerShell
• –NoProfile – Instead of using PowerShell Modules and other settings within a user’s document’s folder, it will skip all this and just simply run the script without using the user’s profile settings.
-ExecutionPolicy Unrestricted – This sets the execution policy to unrestricted.
-Command – This will execute the command that comes after.
%~dp0 – When this is referenced within a Windows Batch File. This will expand to the drive letter and path of that batch file.
-ComputerName $env:computername – This grabs the computer’s name.
-OutputFile – This will generate a file.
-append – If you ran the executable bat file again. It will add the result in an existing output file. (Only if there is an existing output file)

The script above will run in PowerShell, run unrestricted with no PowerShell profile. Then run the Powershell Script ‘Get-WindowsAutoPilotInfo.ps1’ in reference to the location of the Batch file, grab the computer’s name and output the result of the PowerShell into a .csv file.

If the Bat file was run again without deleting the previous .csv file, then the next serial number it grabs will be added underneath the first one in a new row. This is done with the -append.

Loading