-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.ps1
23 lines (19 loc) · 831 Bytes
/
start.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Authenticate with your Automation Account
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID `
-ApplicationID $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
($rmvms=Get-AzurermVM) > 0
# Start all running VMs in ResourceGroup
foreach ($vm in $rmvms)
{
$vmStatus = Get-AzureRmVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name -Status
# Start running VMs
if($vmStatus.Statuses | where Code -match "PowerState/deallocated")
{
Write-Output "Starting VM [$($vm.Name)]"
$vm | Start-AzureRmVM
}
else {
Write-Output "VM [$($vm.Name)] is already running!"
}
}