-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathQuery_output.ps1
49 lines (33 loc) · 1.39 KB
/
Query_output.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
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
#Select simple properties
Get-AzVM -Name tw-winsrv -ResourceGroupName tw-rg01 | Select-Object *
#Once you know the names of the properties that you're interested in, you can use those property names
Get-AzVM -Name tw-winsrv -ResourceGroupName tw-rg01 | Select-Object Name,VmId,ProvisioningState
#Select nested properties
Get-AzVM -ResourceGroupName tw-rg01 | `
Select-Object Name,@{Name="OSType"; Expression={$_.StorageProfile.OSDisk.OSType}}
#Filter results
Get-AzVM -ResourceGroupName tw-rg01 | `
Where-Object {$_.StorageProfile.OSDisk.OSType -eq "Linux"}
#You can pipe the results
Get-AzVM -ResourceGroupName tw-rg01 | `
Where-Object {$_.StorageProfile.OsDisk.OsType -eq "Linux"} | `
Select-Object Name,VmID,ProvisioningState
#Table output format
Get-AzVM
Get-AzVM -ResourceGroupName tw-rg01 | Format-Table Name,ResourceGroupName,Location
#List output format
Get-AzVM | Format-List
Get-AzVM | Format-List ResourceGroupName,Name,Location
#Wide output format
Get-AzVM | Format-Wide
Get-AzVM | Format-Wide ResourceGroupName
#Custom output format
Get-AzVM | Format-Custom
Get-AzVM | Format-Custom Name,ResourceGroupName,Location