Skip to content

Commit

Permalink
Merge pull request #5 from ccbas/feat/add_support_for_uai
Browse files Browse the repository at this point in the history
  • Loading branch information
diecknet authored Mar 20, 2024
2 parents a1c301f + 39af868 commit c3e48ac
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions SimpleAzureVMStartStop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,44 @@
.OUTPUTS
String to determine result of the script
.PARAMETER userAssignedIdentityClientId
Specify the Managed Identity Client ID if applicable.
.PARAMETER VMName
Specify the name of the Virtual Machine, or use the asterisk symbol "*" to affect all VMs in the resource group.
.PARAMETER ResourceGroupName
Specifies the name of the resource group containing the VM(s).
.PARAMETER AzureSubscriptionID
Optionally specify Azure Subscription ID.
.PARAMETER Action
Specify desired Action, allowed values "Start" or "Stop".
#>

[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
# Specify the name of the Virtual Machine, or use the asterisk symbol "*" to affect all VMs in the resource group
[Parameter(Mandatory = $false, HelpMessage = "Specify the Managed Identity Client ID if applicable.")]
[string]
$userAssignedIdentityClientId,

[Parameter(Mandatory = $true, HelpMessage = "Specify the VM name or '*' for all VMs in the resource group.")]
[string]
$VMName,
[Parameter(Mandatory = $true)]

[Parameter(Mandatory = $true, HelpMessage = "Specify the name of the resource group containing the VM(s).")]
[string]
$ResourceGroupName,
[Parameter(Mandatory = $false)]
# Optionally specify Azure Subscription ID

[Parameter(Mandatory = $false, HelpMessage = "Optionally specify the Azure Subscription ID.")]
[string]
$AzureSubscriptionID,
[Parameter(Mandatory = $true)]

[Parameter(Mandatory = $true, HelpMessage = "Specify 'Start' or 'Stop' to control the VM(s).")]
[ValidateSet("Start", "Stop")]
# Specify desired Action, allowed values "Start" or "Stop"
[string]
$Action
)

Expand All @@ -81,7 +105,14 @@ $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
}
else {
Write-Output "Trying to connect to Azure with a system assigned Identity..."
$null = Connect-AzAccount -Identity
}
}
catch {
$ErrorMessage = "Error connecting to Azure: " + $_.Exception.message
Expand Down

0 comments on commit c3e48ac

Please sign in to comment.