-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGet-LabInfo.ps1
More file actions
53 lines (41 loc) · 1.31 KB
/
Copy pathGet-LabInfo.ps1
File metadata and controls
53 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
param
(
[Parameter(Mandatory=$true, HelpMessage="Name of lab to query")]
[string] $DevTestLabName,
[Parameter(Mandatory=$true, HelpMessage="RG of lab to query")]
[string] $ResourceGroupName,
[Parameter(valueFromRemainingArguments=$true)]
[String[]]
$rest = @()
)
$ErrorActionPreference = "Stop"
$existingLab = Get-AzureRmResource -Name $DevTestLabName -ResourceGroupName $ResourceGroupName
if (-not $existingLab) {
throw "'$DevTestLabName' Doesn't exist"
}
$vms = Get-AzureRmResource -ResourceType "Microsoft.DevTestLab/labs/virtualMachines" -ResourceGroupName $ResourceGroupName -ExpandProperties -Name "$DevTestLabName/"
if(-not $vms) {
throw "No VMs in $DevTestLabName"
}
$runningVms = @()
foreach ($vm in $vms) {
$computeVm = Get-AzureRmResource -ResourceId $vm.Properties.computeId
$computeGroup = $computeVm.ResourceGroupName
$name = $computeVm.Name
$compVM = Get-AzureRmVM -ResourceGroupName $computeGroup -name $name -Status
$isRunning = $false
$compVM.Statuses | ForEach-Object {
if ($_.Code -eq 'PowerState/running') {
$isRunning = $true
}
}
if($isRunning) {
$runningVms += $vm.Name
}
}
if($runningVms) {
$runString = $runningVms -join " "
} else {
$runString = 'None'
}
Write-Output "RUNNING VMS FOR LAB $DevTestLabName : $runString"