forked from PacktPublishing/Azure-PowerShell-on-the-Cloud-v-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.2 - Reading simple and complex object properties.ps1
53 lines (29 loc) · 1.24 KB
/
2.2 - Reading simple and complex object properties.ps1
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
#Reading simple and complex object properties
Set-Location C:\
Clear-Host
#Reviewing - working with simple and complex properties in PowerShell
Get-AzureRMVM -Status
# Display only one property value
Get-AzureRMVM -Status | Select-Object -Property PowerState
# Select multiple object properties
Get-AzureRMVM -Status | Select-Object Name, PowerState
#Works great for simple properties, but what about complex?
Get-AzureRMVM -Status | Select-Object Name, VMSize, PowerState
Get-AzureRMVM -Status | Select-Object Size -First 1
Get-AzureRMVM -Status | Get-Member
Get-AzureRMVM | Select-Object -ExpandProperty HardwareProfile -First 1
Get-AzureRMVM | Select-Object -Property * -First 1
$VM = Get-AzureRMVM -Status | Select-Object -First 1
$VM
#Mix of simple and complex object properties
$VM | Select-Object -Property *
#Expanding a complex object property
$VM | Select-Object -ExpandProperty HardwareProfile
#Or... use the '.' for an object reference. Intellisense also helps (CTRL + Enter)
$VM.HardwareProfile.VmSize
#
$VM | Select-Object -Property *
Clear-Host
$VM.StorageProfile | ConvertTo-Json -Depth 1
$VM.StorageProfile | ConvertTo-Json -Depth 2
$VM.StorageProfile.OsDisk.ManagedDisk.Id