Skip to content

Commit

Permalink
Merge pull request #6 from diecknet/update-infos
Browse files Browse the repository at this point in the history
  • Loading branch information
diecknet authored Mar 20, 2024
2 parents c3e48ac + a33f690 commit cc29621
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Andreas Dieckmann
Copyright (c) 2024 Andreas Dieckmann and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
A simple PowerShell script to start/stop Azure Virtual Machines. For use with Azure Automation and a Managed Identity.
The Managed Identity needs the permissions according to [`CustomRoleDefinition.json`](CustomRoleDefinition.json).

Tested with PowerShell 5.1 as a runtime.

## Features

- Starts/Stops one specific VM or all VMs in a Resource Group
- Uses the modern ("Az") Azure PowerShell module (instead of the old AzureRm module)
- Uses Managed Identity instead of RunAs Accounts
- Supports System-Assigned and User-Assigned Managed Identities (thanks @SanderBlom)
- Simple
- Free
18 changes: 10 additions & 8 deletions SimpleAzureVMStartStop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.DESCRIPTION
This script is intended to start or stop Azure Virtual Machines in a simple way in Azure Automation.
The script uses Azure Automation Managed Identity and the modern ("Az") Azure PowerShell Module.
Both system-assigned and user-assigned Managed Identites are supported.
Requirements:
Give the Azure Automation Managed Identity necessary rights to Start/Stop VMs in the Resource Group.
Expand All @@ -13,14 +14,15 @@
- Microsoft.Compute/virtualMachines/read
.NOTES
Version: 1.2.2
Version: 1.3.0
Author: Andreas Dieckmann
Creation Date: 2023-09-21
Last update: 2024-03-20
GitHub: https://github.com/diecknet/Simple-Azure-VM-Start-Stop
Blog: https://diecknet.de
License: MIT License
Copyright (c) 2022 Andreas Dieckmann
Copyright (c) 2024 Andreas Dieckmann and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -51,7 +53,7 @@
.OUTPUTS
String to determine result of the script
.PARAMETER userAssignedIdentityClientId
.PARAMETER UserAssignedIdentityClientId
Specify the Managed Identity Client ID if applicable.
.PARAMETER VMName
Expand All @@ -72,7 +74,7 @@ Specify desired Action, allowed values "Start" or "Stop".
param(
[Parameter(Mandatory = $false, HelpMessage = "Specify the Managed Identity Client ID if applicable.")]
[string]
$userAssignedIdentityClientId,
$UserAssignedIdentityClientId,

[Parameter(Mandatory = $true, HelpMessage = "Specify the VM name or '*' for all VMs in the resource group.")]
[string]
Expand Down Expand Up @@ -105,13 +107,13 @@ $errorCount = 0

# connect to Azure, suppress output
try {
if($userAssignedIdentityClientId) {
Write-Output "Trying to connect to Azure with a User assigned Identity, with the Client ID $userAssignedIdentityClientId..."
$null = Connect-AzAccount -Identity -AccountId $userAssignedIdentityClientId
if($UserAssignedIdentityClientId) {
Write-Output "Trying to connect to Azure with a User assigned Identity, with the Client ID $UserAssignedIdentityClientId..."
$null = Connect-AzAccount -Identity -AccountId $UserAssignedIdentityClientId
}
else {
Write-Output "Trying to connect to Azure with a system assigned Identity..."
$null = Connect-AzAccount -Identity
$null = Connect-AzAccount -Identity
}
}
catch {
Expand Down

0 comments on commit cc29621

Please sign in to comment.