This post is the second of a series of posts describing our automation efforts for provisioning Windows 10 IoT core on a Raspberry Pi. (Click here to read the first post)
To recap, KiZAN has a lab of 26 Raspberry Pi 2 boards running Windows 10 IoT core. On a regular basis, we need to re-flash, provision and configure the boards. When we perform the re-flash and provisioning process, it is manual and consumes more time than we want to spend (up to 2 days). In our first post, you learned how to find the IP address of a Windows 10 IoT core device after the initial flash. The second step in our automation journey is automatically renaming a device. In this post, you'll learn how to use PowerShell to rename a Windows 10 IoT Core Device after its initial flash.
Posts in This Series:
The first several lines establish secure credentials for the remote device. Next, I create a time-out of 5 minutes (this is in milliseconds), because it takes some time to connect to the remote session. The last line starts a new session on the $ipAddress that is passed in with the credentials to that device. This stores the current session in the $session variable to be referenced later to run scripts on the session.
Remotely Run the Rename Script
For the renaming, I felt it made sense to put the code in a separate script, then pass the script into the remote PowerShell session (separation of concerns, am I right?). I also did this to make sure the commands are run on the device, not on your own local machine. I learned this the hard way by putting a reboot in the provisioning script without using a session and restarted my own computer…but, that’s beside the point. I used the following script to change the device's name.
This script takes a parameter with the device's name and renames the device with the SetComputerName command. After the rename command has been run, it outputs "Computer name changed successfully. Please reboot the device for changes to take effect." The restart of the device will come in a later post.
To run the script remotely, include it in the following script:
The Full Code
This post showed a tutorial on Renaming a Windows 10 IoT core device via PowerShell. In the next post, you'll learn how to install WiFi drivers in Windows 10 IoT core.
Many thanks to Ryan DiChiara, one of our summer interns for doing a lot of the legwork (and writing) this post!
Check out our free, hands-on, IoT development workshop series!