Table of Contents
Here’s a PowerShell script that performs the Microsoft Intune
Get-WindowsAutopilotInfo script, exports the HardwareID, and then sends it to a remote share.
If you’re planning a mass rollout or migration of devices into Microsoft Intune, you’ll find this script quite useful. We faced a scenario where hundreds of devices enrolled in an existing Microsoft Intune tenant had to migrate to a new tenant—a not-so-easy task. The script came to our rescue, capturing all the devices’ HardwareIDs instantly. It also left a copy on the local machine, preparing us for any contingencies. I hope you find it equally as helpful.
1. PowerShell Script Breakdown
In this PowerShell script, the “Main script code here” is checking if the
Get-WindowsAutoPilotInfo.ps1 script is installed, and if it’s not then it will proceed to install the required script.
The script then sets some verables:
$GroupTag – if you are using GroupTags for your AutoPilot automation, set this.
$OutputFolderPath – Replace this with the desired folder path to store the HardwareID.csv
It then executes the
Get-WindowsAutoPilotInfo.ps1 script and stores it to the local directory. After exporting the HardwareID to a .CSV, the script will attempt to copy the HardwareID and log file to the specified share location.
If any error occurs during the HardwareID gathering, exporting, or file copying operations, appropriate log messages are written, and an error is thrown using the
Remember to set the following variable:
$LogFilePath – Replace with the desired local folder path
$RemoteServer – Replace with the name or IP address of the remote server
$RemoteSharePath – Replace with the desired remote folder path
$RemoteLogFilePath – Replace with the desired remote folder path
Don’t forget to ensure you have the correct share permissions set on the remote share location.
Feel free to further customize the script as per your requirements.
Here’s a detailed three-point breakdown of executing the
b. Setting Variables
In this initial step, you’ll be setting up the necessary variables for the script execution. Variables in PowerShell are prefixed with a dollar sign (
$). An example of setting variables for the script could look like this:
c. Script Execution and Export
Once the variables are set, the next step is to execute the
Get-WindowsAutopilotInfo-RemoteLocation.ps1 script. The script will then export the logs and
HardwareID.csv to a temporary location. An example of this step might look like this:
d. Copy Files to Remote Server
The final step involves copying the logs and
HardwareID.csv file from the temporary location to a remote server location. This can be achieved using the
Copy-Item cmdlet in PowerShell. Here’s an example:
In this example, replace
"C:\Temp\HardwareID.csv" with the actual path of the
HardwareID.csv file on your local machine, and replace
"\\RemoteServer\Path\" with the actual path of the location on the remote server where you want to copy the file to.
This three-step breakdown provides a comprehensive overview of how to execute the
Get-WindowsAutopilotInfo-RemoteLocation.ps1 script and handle the output effectively.