Loading...

Running a PowerShell Shutdown script on Windows Lab Services machines.

Running a PowerShell Shutdown script on Windows Lab Services machines.

We love to hear about all the types of classes being taught using Azure Lab Services. Recently, a school informed us they were teaching an introduction to networking class using nested virtualization. While they loved the contained nature of using Azure Lab Services, students were occasionally changing the IP address of their lab VM instead of the Hyper-V VM.  Once the changes have been saved the students can no longer connect to the VM and any work is lost.  While there isn't a way to fix existing issues, there is a way to help prevent those issues by setting up a shutdown script.  The script in this article will only change the IP address and DNS address to dynamic, so if the student sets a static ip it will be reverted.  If there are other areas where students may accidentally make changes then modify the PowerShell script to handle those specific changes.

There are two parts to this, the PowerShell script and setting up the Local Group Policy to run the script at shutdown.  First create a PowerShell script on the template VM.  In this example the code would be:

 

 

 

 

 

 

$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled ='true'"; $wmi.EnableDHCP(); $wmi.SetDNSServerSearchOrder();

 

 

 

 

 

 

This script will reset the ip address and dns server ip to dynamic..

The second part is to configure the operating system to execute the script on shut down.  This is done using the Local Group Policy.

  • Open the Local Group Policy editor (gpedit.msc)
  • Under Local Computer Policy / Computer Configuration / Windows Settings / Scripts (Startup/Shutdown)
  • Open the Shutdown property.
  • Select PowerShell scripts from the top tabs.
  • Add the location and file for the PowerShell script above.
  • Change the run order (below the script) to be “Run Windows PowerShell scripts first”

 GPOShutdown.png

 

Publish the template and if any student changes the host virtual machine ip address it will be changed back to dynamic on shutdown.  This script will be executed on O.S. shutdown and any of the lab settings (O.S. idle, disconnect, not connected).

 

Good Luck,

Roger

 

Published on:

Learn more
Azure Lab Services articles
Azure Lab Services articles

Azure Lab Services articles

Share post:

Related posts

ISSUE RESOLVED: Azure Lab Services - lab plan outage - September 12, 2024

Hello, Azure Lab Services is currently experiencing an outage affecting customers using Lab Plans for their service. Customers using Lab Accou...

1 year ago

Azure Lab Services - Upcoming maintenance update on October 12, 2024

Hello all,   On October 12th, 2024, we will be updating our system between 7:00 AM and 6:00 PM CST. This maintenance will only affect the...

1 year ago

Azure Lab Services - lab plan outage - September 12, 2024

Hello, Azure Lab Services is currently experiencing an outage affecting customers using Lab Plans for their service. Customers using Lab Accou...

1 year ago

Azure Lab Services - Upcoming maintenance update on 08/24

Hi, We will be doing an update to the service on Saturday, August 24 starting at 12:30 pm PDT and ending at 11:59 pm PDT. The service is not g...

2 years ago

[Mitigated] Azure Lab Services - Maintenance update outage

Hi, We are experiencing a service outage due to ongoing maintenance since around July 21st, 4 pm PDT. The service is currently not available i...

2 years ago

Azure Lab Services - Maintenance update outage

Hi, We are experiencing a service outage due to ongoing maintenance since around July 21st, 4 pm PDT. The service is currently not available i...

2 years ago

[Mitigated] Azure Lab Services - Lab Plan Outage

Azure Lab Service is experiencing an outage that is affecting Lab Plans, but not Lab Accounts. This outage intermittently impacts all operatio...

2 years ago

Azure Lab Services Tutorial Video

This is a complete tutorial about Azure Lab Services' features. It walks through the steps of setting up a Lab Account, creating a Lab, and ac...

2 years ago

What's new in the Azure Lab Services

This is a presentation highlighting the new features introduced in the latest preview for Azure Lab Services.

2 years ago

Updates for Azure Lab Services

The product team has been busy working on fundamental improvements for the service to boost performance, reliability, and scalability. It has ...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.