Forum Discussion

SimonAllison's avatar
SimonAllison
Iron Contributor
Jul 05, 2018

Get-WindowsAutoPilotInfo - A quicker way...

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 😧 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    

 

  • SanderKoop's avatar
    SanderKoop
    Copper Contributor

    SimonAllison 

    Try this, if you have an admin account with access to Autopilot:

    @echo off

    ECHO Enabling WinRM
    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "Enable-PSRemoting -SkipNetworkProfileCheck -Force"
    echo WinRM enabled.

    ECHO Get NuGet provider
    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force"

    ECHO Update PowerShellGet module
    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "Install-Module -Name PowerShellGet -Force -AllowClobber"

    ECHO Install Get-WindowsAutoPilotInfo.ps1 script
    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "Install-Script -Name Get-WindowsAutoPilotInfo -Force"

    ECHO Run Get-WindowsAutoPilotInfo.ps1 script
    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& 'C:\Program Files\WindowsPowerShell\Scripts\Get-WindowsAutoPilotInfo.ps1' -Online -Assign"

    :END
    echo Script execution completed.
    pause

  • arvind1727's avatar
    arvind1727
    Copper Contributor
    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.
  • davewilliamson's avatar
    davewilliamson
    Copper Contributor
    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.
    • SimonAllison's avatar
      SimonAllison
      Iron Contributor

      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

      • davewilliamson's avatar
        davewilliamson
        Copper Contributor
        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.
  • Jaid_Maijer's avatar
    Jaid_Maijer
    Copper Contributor

    SimonAllison 

     

    The problem where i ran into was that you cannot run the Script when you are in a Public Network.

    you need to change it to Private.

     

    Then it runs ok.

     

    Thanks alot. 🙂

  • SimonAllison 

     

    Hello, thanks for the tip.

    I have added the following command on the cmd as it does not work if Windows management service is disabled and it was on my machines : 

    net start WManSvc

     

    Thanks,

    Yohan.

  • firebladez's avatar
    firebladez
    Copper Contributor

    SimonAllison - do you have a link to the files that I can put onto a usb stick please? struggling to get this to work... ta

      • Robaxn's avatar
        Robaxn
        Copper Contributor

        SimonAllison Hi was having difficulty getting info in the computers.csv but ran Winrm quickconfig.

        Now I get "default String" under device serial no. : nothing in windows ; and a very long string of letters under hardware hash. No column for computer name.

        Any thoughts?

         

         

  • mac-e's avatar
    mac-e
    Copper Contributor
    Slight improvement to your batch file, added -append and set the drive letters to be the drive the bat file is executed from:

    PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command %~dp0\Get-WindowsAutoPilotInfo.ps1 -ComputerName $env:computername -OutputFile %~dp0\computers.csv -append
  • BoostedBishop's avatar
    BoostedBishop
    Copper Contributor
    if you add a -append to your cmd it will keep all the hardware IDs in the same csv, making it easier to upload to intune

Resources