Skip to content

Commit 65f1ce2

Browse files
authored
Merge pull request #260788 from EdB-MSFT/install-vminsights-2
updated
2 parents 56d877e + a1c207c commit 65f1ce2

File tree

1 file changed

+62
-19
lines changed

1 file changed

+62
-19
lines changed

articles/azure-monitor/vm/vminsights-enable-powershell.md

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.topic: conceptual
55
ms.custom: devx-track-azurepowershell
66
author: guywi-ms
77
ms.author: guywild
8-
ms.date: 11/28/2023
8+
ms.date: 12/13/2023
99
---
1010

1111
# Enable VM insights by using PowerShell
@@ -14,7 +14,7 @@ This article describes how to enable VM insights on Azure virtual machines by us
1414
- Azure Virtual Machines
1515
- Azure Virtual Machine Scale Sets
1616

17-
This script installs VM extensions for Log Analytics/Azure Monitoring Agent (AMA) and Dependency Agent if needed for VM Insights. If AMA is onboarded, a Data Collection Rule (DCR) and a User Assigned Managed Identity (UAMI) is also associated with the virtual machines and virtual machine scale sets.
17+
This script installs VM extensions for Log Analytics/Azure Monitoring Agent (AMA) and, if necessary, the Dependency Agent to enable VM Insights. If AMA is onboarded, a Data Collection Rule (DCR) and a User Assigned Managed Identity (UAMI) is also associated with the virtual machines and virtual machine scale sets.
1818

1919
[!INCLUDE [Log Analytics agent deprecation](../../../includes/log-analytics-agent-deprecation.md)]
2020

@@ -31,51 +31,60 @@ You need to:
3131
To enable VM insights for multiple VMs or virtual machine scale set, use the PowerShell script [Install-VMInsights.ps1](https://www.powershellgallery.com/packages/Install-VMInsights). The script is available from the Azure PowerShell Gallery. This script iterates through the virtual machines or virtual machine scale sets according to the parameters that you specify. The script can be used to enable VM insights for:
3232

3333
- Every virtual machine and virtual machine scale set in your subscription.
34-
- The scoped resource group that's specified by `-ResourceGroup`.
35-
- A single VM or virtual machine scale set that's specified by `-Name`.
34+
- The scoped resource groups specified by `-ResourceGroup`.
35+
- A VM or virtual machine scale set specified by `-Name`.
36+
You can specify multiple resource groups, VMs, or scale sets by using wildcards.
3637

3738

38-
Verify that you're using Az PowerShell module version 1.0.0 or later with `Enable-AzureRM` compatibility aliases enabled. Run `Get-Module -ListAvailable Az` to find the version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
39+
Verify that you're using Az PowerShell module version 1.0.0 or later with `Enable-AzureRM` compatibility aliases enabled. Run `Get-Module -ListAvailable Az` to find the version. To upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, run `Connect-AzAccount` to create a connection with Azure.
3940

4041
For a list of the script's argument details and example usage, run `Get-Help`.
4142

4243
```powershell
4344
Get-Help Install-VMInsights.ps1 -Detailed
4445
```
4546

46-
Use the script to enable VM insights using Azure Monitoring Agent and Dependency Agent, or Log Analytics Agent.
47+
Use the script to enable VM insights using Azure Monitoring Agent and Dependency Agent, or Log Analytics Agent.
4748

4849

4950

5051
### [Azure Monitor Agent](#tab/AMA)
5152

52-
When you enable VM insights using Azure Monitor Agent, the script associates a Data Collection Rule (DCR) and a User Assigned Managed Identity (UAMI) to the VM/VMSS, and passes the UAMI settings to the Azure Monitor Agent extension.
53+
When you enable VM insights using Azure Monitor Agent, the script associates a Data Collection Rule (DCR) and a User Assigned Managed Identity (UAMI) to the VM/Virtual Machine Scale Set. The UAMI settings are passed to the Azure Monitor Agent extension.
5354

5455
```powershell
5556
Install-VMInsights.ps1 -SubscriptionId <SubscriptionId> `
5657
[-ResourceGroup <ResourceGroup>] `
5758
[-ProcessAndDependencies ] `
58-
[-Name <MV or VMSS name>] `
59+
[-Name <VM or Virtual Machine Scale Set name>] `
5960
-DcrResourceId <DataCollectionRuleResourceId> `
6061
-UserAssignedManagedIdentityName <UserAssignedIdentityName> `
6162
-UserAssignedManagedIdentityResourceGroup <UserAssignedIdentityResourceGroup>
6263
6364
```
6465

6566
Required Arguments:
66-
+ `-SubscriptionId <String>` Azure subscription ID.
67-
+ `-DcrResourceId <String> ` Data Collection Rule (DCR) Azure resource ID identifier.
68-
+ `-UserAssignedManagedIdentityResourceGroup <String> ` Name of User Assigned Managed Identity (UAMI) resource group.
69-
+ `-UserAssignedManagedIdentityName <String> ` Name of User Assigned Managed Identity (UAMI).
67+
+ `-SubscriptionId <String>` Azure subscription ID.
68+
+ `-DcrResourceId <String> ` Data Collection Rule (DCR) Azure resource ID identifier. You can specify DCRs from different subscriptions to the VMs or virtual machine scale sets being enabled with Vm-Insights.
69+
+ `-UserAssignedManagedIdentityResourceGroup <String> ` Name of User Assigned Managed Identity (UAMI) resource group.
70+
+ `-UserAssignedManagedIdentityName <String> ` Name of User Assigned Managed Identity (UAMI).
71+
7072

7173
Optional Arguments:
72-
+ `-ProcessAndDependencies` Set this flag to onboard the Dependency Agent with Azure Monitoring Agent (AMA) settings. If not specified, only Azure Monitoring Agent (AMA) will be onboarded.
73-
+ ` - Name <String>` Name of the VM or VMSS to be onboarded. If not specified, all VMs and VMSS in the subscription or resource group will be onboarded.
74-
+ `- ResourceGroup <String>` Name of the resource group containing the VM or VMSS to be onboarded. If not specified, all VMs and VMSS in the subscription will be onboarded.
74+
+ `-ProcessAndDependencies` Set this flag to onboard the Dependency Agent with Azure Monitoring Agent (AMA) settings. If not specified, only the Azure Monitoring Agent (AMA) is onboarded.
75+
+ `-Name <String>` Name of the VM or Virtual Machine Scale Set to be onboarded. If not specified, all VMs and Virtual Machine Scale Set in the subscription or resource group are onboarded. Use wildcards to specify multiple VMs or Virtual Machine Scale Sets.
76+
+ `-ResourceGroup <String>` Name of the resource group containing the VM or Virtual Machine Scale Set to be onboarded. If not specified, all VMs and Virtual Machine Scale Set in the subscription are onboarded. Use wildcards to specify multiple resource groups.
77+
+ `-PolicyAssignmentName <String>` Only include VMs associated with this policy. When the PolicyAssignmentName parameter is specified, the VMs part of the parameter SubscriptionId are considered.
78+
+ `-TriggerVmssManualVMUpdate [<SwitchParameter>]` Trigger the update of VM instances in a scale set whose upgrade policy is set to Manual.
79+
+ `-WhatIf [<SwitchParameter>]` Get info about expected effect of the commands in the script.
80+
+ `-Confirm [<SwitchParameter>]` Confirm each action in the script.
81+
+ `-Approve [<SwitchParameter>]` Provide the approval for the installation to start with no confirmation prompt for the listed VM's/Virtual Machine Scale Sets.
82+
83+
The script supports wildcards for `-Name` and `-ResourceGroup`. For example, `-Name vm*` enables VM insights for all VMs and Virtual Machine Scale Sets that start with "vm". For more information, see [Wildcards in Windows PowerShell](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_wildcards).
7584

7685
Example:
7786
```azurepowershell
78-
Install-VMInsights.ps1 -SubscriptionId 12345678-abcd-abcd-1234-12345678 `
87+
Install-VMInsights.ps1 -SubscriptionId 12345678-abcd-abcd-1234-12345678 `
7988
-ResourceGroup rg-AMAPowershell `
8089
-ProcessAndDependencies `
8190
-Name vmAMAPowershellWindows `
@@ -89,10 +98,10 @@ The output has the following format:
8998
```powershell
9099
Name Account SubscriptionName Environment TenantId
91100
---- ------- ---------------- ----------- --------
92-
AzMon001 12345678-abcd-123… MSI@9876 AzMon001 AzureCloud abcd1234-9876-abcd-1234-1234abcd5648
101+
AzMon001 12345678-abcd-123… MSI@9876 AzMon001 AzureCloud abcd1234-9876-abcd-1234-1234abcd5648
93102
94103
Getting list of VMs or VM Scale Sets matching specified criteria.
95-
VMs and VMSS matching selection criteria :
104+
VMs and Virtual Machine Scale Sets matching selection criteria :
96105
97106
ResourceGroup : rg-AMAPowershell
98107
vmAMAPowershellWindows
@@ -125,6 +134,40 @@ VMSS Instance Upgrade Failures : 0
125134

126135
### [Log Analytics Agent](#tab/LogAnalyticsAgent)
127136

137+
138+
Required Arguments:
139+
+ `-WorkspaceId <String>` Log Analytics WorkspaceID (GUID).
140+
+ `-WorkspaceKey <String>` Log Analytics Workspace primary or secondary key.
141+
142+
Optional Arguments:
143+
+ `-ReInstall [<SwitchParameter>]` Trigger removal of existing Log analytics extension and reinstallation to migrate log analytics workspaces with Legacy Agent (Linux) - OMSAgent.
144+
+ `-Name <String>` Name of the VM or Virtual Machine Scale Set to be onboarded. If not specified, all VMs and Virtual Machine Scale Sets in the subscription or resource group are onboarded. Use wildcards to specify multiple VMs or Virtual Machine Scale Sets.
145+
+ `- ResourceGroup <String>` Name of the resource group containing the VM or Virtual Machine Scale Set to be onboarded. If not specified, all VMs and Virtual Machine Scale Sets in the subscription are onboarded. Use wildcards to specify multiple resource groups.
146+
+ `-PolicyAssignmentName <String>` Only include VMs associated with this policy. When the PolicyAssignmentName parameter is specified, the VMs part of the parameter SubscriptionId are considered.
147+
+ `-TriggerVmssManualVMUpdate [<SwitchParameter>]` Trigger the update of VM instances in a scale set whose upgrade policy is set to Manual.
148+
+ `-WhatIf [<SwitchParameter>]` Get info about expected effect of the commands in the script.
149+
+ `-Confirm [<SwitchParameter>]` Confirm each action in the script.
150+
+ `-Approve [<SwitchParameter>]` Provide the approval for the installation to start with no confirmation prompt for the listed VM's/Virtual Machine Scale Sets.
151+
152+
The script supports wildcards for `-Name` and `-ResourceGroup`. For example, `-Name vm*` enables VM insights for all VMs and Virtual Machine Scale Sets that start with "vm". For more information, see [Wildcards in Windows PowerShell](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_wildcards).
153+
154+
155+
Example:
156+
157+
```powershell
158+
Install-VMInsights.ps1 -WorkspaceId \<WorkspaceId\> `
159+
-WorkspaceKey \<WorkspaceKey\> `
160+
-SubscriptionId \<SubscriptionId\> `
161+
-ResourceGroup \<ResourceGroup\>
162+
163+
Install-VMInsights.ps1 -WorkspaceId \<WorkspaceId\> `
164+
-WorkspaceKey \<WorkspaceKey\> `
165+
-SubscriptionId \<SubscriptionId\> `
166+
-ResourceGroup \<ResourceGroup\> `
167+
-ReInstall
168+
```
169+
170+
128171
Use the following command to enable VM insights using Log Analytics Agent and Dependency Agent.
129172

130173

@@ -184,7 +227,7 @@ Failed: (0)
184227

185228
---
186229

187-
Check your VM/VMSS in Azure portal to see if the extensions are installed or use the following command:
230+
Check your VM/Virtual Machine Scale Set in Azure portal to see if the extensions are installed or use the following command:
188231

189232
```powershell
190233

0 commit comments

Comments
 (0)