-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-AllAzNics.ps1
107 lines (73 loc) · 3.4 KB
/
Get-AllAzNics.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<#
.Synopsis
List All NICs in a Subscription along with few other details like SubnetNSG,VNET,Location,UDR,ResourceGroup,Subscription,etc.
.Description
List All NICs in a Subscription along with few other details like SubnetNSG,VNET,Location,UDR,ResourceGroup,Subscription,etc.
.Parameter
None.
.Example
#List All NICs and few other details for a Subscription.
Get-AllAzNics
#>
#------------------------------------------------------------------------------
#
#
# THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR
# RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
#------------------------------------------------------------------------------
Function Get-AllAzNics (){
Param ()
$vmname = @()
$nsgobj = @()
$rg = @()
$getsubpernic = @()
$getnic = Get-AzureRmNetworkInterface
$date = (get-date).ToUniversalTime()
If((Get-Module Split-AzResourceID -ListAvailable) -eq $null){
Write-Host "Split-AzResourceID module is required to run this module. Installing Split-AzResourceID module"
Install-Module -Name Split-AzResourceID -MinimumVersion 2.1 -Scope CurrentUser
}
$vmname = $getnic | ForEach-Object {$_.VirtualMachine.Id -replace ".*/"}
$rgvnet = $getnic | ForEach-Object {$_.IpConfigurations.subnet.id -replace ".*/resourcegroups/" -replace "/providers/.*"}
$rg = $getnic | ForEach-Object {$_.ResourceGroupName}
For ($i=0; $i -lt $getnic.Count; $i++){
$getsubpernic += Get-AzVirtualNetworkSubnetConfig -ResourceId $getnic[$i].IpConfigurations[0].subnet.id
}
For ($i=0; $i -lt $getnic.Count; $i++){
$hash = [ordered]@{
NICName = $getnic[$i].Name
ResourceGroupName = $getnIC[$I].ResourceGroupName
Subscription = $(($getnic[$i].Id | Split-AzResourceID).subscription)
Location = $getnic[$i].Location
VM = $vmname[$i]
PrivateIPs = $getnic[$i].IpConfigurations.privateipaddress
Subnet = $getnic[$i].IpConfigurations.subnet.id
VNET = $(($getnic[$i].IpConfigurations.subnet.id | Split-AzResourceID).resourcename)
NicDNS = $getnic[$i].DnsSettings.DnsServers
VMid = $getnic[$i].VirtualMachine.Id
ApplicationGateway = $getnic[$i].IpConfigurations.ApplicationGatewayBackendAddressPools.id
LoadBalancer = $getnic[$i].IpConfigurations.LoadBalancerBackendAddressPools.id
#VNETDNS = ''
NicNSG = $getnic[$i].NetworkSecurityGroup.Id
EnableIPForwarding = $getnic[$i].EnableAcceleratedNetworking
SubnetNSG = $getsubpernic[$i].NetworkSecurityGroup.id
EnableAcceleratedNetworking = $getnic[$i].EnableAcceleratedNetworking
SubnetUDR = $getsubpernic[$i].routetable.id
ProvisioningState = $getnic[$i].ProvisioningState
PrivateEndPointFQDNs = $getnic[$i].IpConfigurations.PrivateLinkConnectionProperties.Fqdns
PrivateEndPointGroupID = $getnic[$i].IpConfigurations.PrivateLinkConnectionProperties.GroupID
ServiceEndpoints = $getsubpernic[$i].ServiceEndpoints
MacAddress = $getnic[$i].MacAddress
Date = $date
}
$nsgobj += New-Object PSObject -Property $hash
}
# Output
$nsgobj
####
}
#Export-ModuleMember -Function Get-AllAzNics