You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ($extension.Name -eq "AzureNetworkWatcherExtension")
109
-
{
110
-
if (NeedsUpdate($extension.TypeHandlerVersion))
111
-
{
112
-
$foundVMs = $true;
113
-
if (-not ($NoUpdate))
114
-
{
115
-
Write-Host "Found VM that needs to be updated: subscriptions/$($SubID)/resourceGroups/$($vm.ResourceGroupName)/providers/Microsoft.Compute/virtualMachines/$($vm.Name) -> Updating " -NoNewline
Write-Host "Found $(if ($isWindows) {"Windows"} else {"Linux"}) VM that needs to be updated: subscriptions/$($SubID)/resourceGroups/$($vm.ResourceGroupName)/providers/Microsoft.Compute/virtualMachines/$($vm.Name)"
125
-
}
126
-
}
127
-
}
128
-
}
129
-
}
130
-
131
-
if ($foundVMs)
132
-
{
133
-
Write-Host "Finished $(if ($NoUpdate) {"searching"} else {"updating"}) out of date AzureNetworkWatcherExtension on VMs"
59
+
60
+
[CmdletBinding()]
61
+
param(
62
+
[Parameter(Mandatory=$true)]
63
+
[string] $SubID,
64
+
[Parameter(Mandatory=$false)]
65
+
[Switch] $NoUpdate = $false,
66
+
[Parameter(Mandatory=$false)]
67
+
[string] $MinVersion = "1.4.2423.1"
68
+
)
69
+
function NeedsUpdate($version)
70
+
{
71
+
if ([Version]$version -lt [Version]$MinVersion)
72
+
{
73
+
$lessThan = $true
74
+
}else{
75
+
$lessThan = $false
76
+
}
77
+
return $lessThan
78
+
}
79
+
Write-Host "Scanning all VMs in the subscription: $($SubID)"
80
+
Set-AzContext -SubscriptionId $SubID
81
+
$vms = Get-AzVM
82
+
$foundVMs = $false
83
+
Write-Host "Starting VM search, this may take a while"
if ($extension.Name -eq "AzureNetworkWatcherExtension")
93
+
{
94
+
if (NeedsUpdate($extension.TypeHandlerVersion))
95
+
{
96
+
$foundVMs = $true
97
+
if (-not ($NoUpdate))
98
+
{
99
+
Write-Host "Found VM that needs to be updated: subscriptions/$($SubID)/resourceGroups/$($vm.ResourceGroupName)/providers/Microsoft.Compute/virtualMachines/$($vm.Name) -> Updating " -NoNewline
Write-Host "Found $(if ($isitWindows) {"Windows"} else {"Linux"}) VM that needs to be updated: subscriptions/$($SubID)/resourceGroups/$($vm.ResourceGroupName)/providers/Microsoft.Compute/virtualMachines/$($vm.Name)"
109
+
}
110
+
}
111
+
}
112
+
}
134
113
}
135
-
else
136
-
{
137
-
Write-Host "All AzureNetworkWatcherExtensions up to date"
114
+
115
+
if ($foundVMs)
116
+
{
117
+
Write-Host "Finished $(if ($NoUpdate) {"searching"} else {"updating"}) out of date AzureNetworkWatcherExtension on VMs"
118
+
}
119
+
else
120
+
{
121
+
Write-Host "All AzureNetworkWatcherExtensions up to date"
0 commit comments