This PowerShell script starts, restarts, or stops Azure VMs listed in an Excel spreadsheet.
To install the required modules to run this script, follow the instructions below.
-
Open PowerShell as Administrator
-
Run the command to install the Azure PowerShell module -
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
-
Run the command to install the ImportExcel module -
Install-Module -Name ImportExcel -Scope CurrentUser
This script requires an Azure account to connect to, with privileges that allow administration of all virtual machines in the Excel file. Currently it can start, restart, or stop virtual machines within the same subscription that you are currently working in.
You will be prompted to enter which operation to perform on the virtual machines in lowercase - start, restart, or stop.
This script requires the user to input the following:
- A valid file path for an Excel file - .xlsx file extension
- A column which lists Azure Virtual Machine names
- The number of rows in the column - starting at row 1 - that list Azure Virtual Machine names
e.g. User input for a file with VMs listed in column A, and have values in the first two rows in column A:
- C:\Users\Mike\Downloads\vmfile.xlsx
- A
- 2