Get-WindowsAutoPilotInfo - A quicker way...

Brass Contributor

Hi All

 

Just a Tip from me to make it easier  (if you got other ways, let me know, would be interested) 

 

 

Starting to deploy via Autopilot but first grabbing the information - so I am using a USB Drive with the following : 

 

Plug in the USB Drive.. 

 

Right Click the file ..GetAutoPilot.cmd and (run as Administrator)   (it seems everytime I plug in the USB I get D: Drive but with the updated command below its automatic )   

 

 

Prepare Files 

 

1) GetAutoPilot.cmd

2) Download a copy of Get-WindowsAutoPilotInfo.ps1

 

Contents of GetAutoPilot.cmd

 

PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command %~d0\Get-WindowsAutoPilotInfo.ps1 -ComputerName $env:computername -OutputFile %~d0\computers.csv -append

 

 

Get-WindowsAutoPilotInfo.ps1 - downloaded from powershellgallery  

https://www.powershellgallery.com/packages/Get-WindowsAutoPilotInfo/1.6

 

What it does... 

It quickly dumps the CSV file onto the USB Drive and now I have all the CSV Files that I need in one file ready to upload to intune. 

 

Then unplug and move onto the next device ...

 

Easy !  

 

Simon Allison    

 

29 Replies
Yes it must have had some updates, and can go straight to tenant now, easy, but this was setup so you dont have to use the internet as these were offline laptops, but great if you can spare a network connection, I had all 60 laptops in a row, and so then created this script and thanks all of you with trying to get it to work and workarounds, its very helpful for others.
I am using the following .cmd and it runs perfectly. I just wanted to extract the computer name as the title instead of compHash.csv in other words if the machine is called desktop001 it would save as desktop001.csv.
@ECHO OFF
echo Enabling WinRM
PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command Enable-PSRemoting -SkipNetworkProfileCheck -Force
echo Gathering AutoPilot Hash
PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command %~dp0Get-WindowsAutoPilotInfo.ps1 -ComputerName $env:computername -OutputFile %~dp0compHash.csv -append
echo Done!
pause

any idea of the slight amendment i'd need to make ?

Help would be appreciated.

your code is missing the slashes : (Copy and paste issue?) 

example:
-OutputFile %~dp0compHash.csv -append
My script:
-OutputFile %~d0\computers.csv -append

It should output the computer name , hope this helps

So thanks for your reply Simon, I have tried this before but it stops the hash recovery and creates a blank .csv with the title of computers.csv. Thanks for your help though, its not a massive problem it just would have been nice to have the title as either the serial or computer name.

@davewilliamson I've found that HP systems don't like  %~dp0compHash.csv but if I use "compHash.csv it works.  Dell doesn't have any issues running  %~dp0compHash.csv

Thanks @mdmcq5 and @davidwilliamson for your input, yes I was originally ran on Dell, if I had a HP Laptop to hand I would have found the issue, so are you saying here just using compHash.csv works for both types of device? I dont have a system to test on to try it, thanks in advance

@Simon Allison this code didn't work for me on HP:

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

 

so I just removed all the %~dp0 references, I also don't think either could define ComputerName $env:computername.  I ran the below w/out any issues on both Dell and HP

PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command Get-WindowsAutoPilotInfo.ps1 - -OutputFile compHash.csv -append

But for non-OOBE boxes, there's a new CIM error being thrown:
Get-CimInstance : A general error occurred that is not covered by a more specific error code.
At D:\Autopilot\Get-WindowsAutoPilotInfo.ps1:209 char:23
... evDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv

the error is due to new KB5013942 or
KB5011831

Once the KB(s) is uninstalled, the code runs. For me on W10 21H2 it was KB5013942. I have no idea if MS knows their update caused an issue or if there's a fix in the pipeline.

Steps

1. For OOBE device, Connect to Internet using accessibility (Click on the Boy icon next to Sound icon). Navigate to Network and Internet. Connect to Wifi with your password and make it a private network in Wifi network's properties. Minimize the window.
2. You will see the screen where Country or region selection to be made after selecting language.
3. Press Windows+R to launch the RUN box
4. Type CMD and press CTRL+Shift+Enter to launch command prompt with administrative privileges.
5. Type Start MSEdge and press Enter to launch Microsoft Edge browser.
6. Minimize Edge as we will need it later.
7. Use Alt+Tab to bring back the Command prompt window on the screen.
8. Type the following command to change the directory of the PowerShell and launch it
C:\Windows\System32>cd\
C:\>cd Program Files\WindowsPowerShell
C:\Program Files\WindowsPowerShell>PowerShell.exe

9. Run the following PowerShell script to update the existing Powershell version to 3.5
PS C:\Program Files\WindowsPowerShell> Install-Script -Name Get-WindowsAutoPilotInfo -RequiredVersion 3.5 -Force
10. Once done run the following script to export the HWID in CSV format
New-Item -Type Directory -Path "C:\HWID"
Set-Location -Path "C:\HWID"
$env:Path += ";C:\Program Files\WindowsPowerShell\Scripts"
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
Install-Script -Name Get-WindowsAutopilotInfo
Get-WindowsAutopilotInfo -OutputFile AutopilotHWID.csv
11. You can locate the CSV file named AutopilotHWID.csv in C drive in a folder named HWID
12. Use Alt+Tab to launch Microsoft Edge which you have minimized during Step 6.
13. Login to your email and send an email to yourself with AutopilotHWID.csv
14. Thank the gentleman who started this post.

@Harm_Veenstra, hi man! Did you manage to use it?
The documentation says that we need Intune admin to get the hash uploaded but when trying it says I don't have the permission.

 

 

Yes, but is the provided user an Intune Administrator role user? Does it have an Intune license assigned?

Alternatively, you could try this

https://powershellisfun.com/2022/07/09/upload-windows-autopilot-hardware-hash/

(my blog post)