Skip to content

Commit 5a7cdfe

Browse files
authored
Merge pull request #113785 from lgayhardt/appinsightspowershell0520
App Insights PowerShell update from Dale
2 parents d9ca7c7 + 455337b commit 5a7cdfe

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

articles/azure-monitor/app/powershell.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Automate Azure Application Insights with PowerShell | Microsoft Docs
33
description: Automate creating and managing resources, alerts, and availability tests in PowerShell using an Azure Resource Manager template.
44
ms.topic: conceptual
5-
ms.date: 10/17/2019
5+
ms.date: 05/02/2020
66

77
---
88

@@ -17,10 +17,10 @@ The key to creating these resources is JSON templates for [Azure Resource Manage
1717
## One-time setup
1818
If you haven't used PowerShell with your Azure subscription before:
1919

20-
Install the Azure Powershell module on the machine where you want to run the scripts:
20+
Install the Azure PowerShell module on the machine where you want to run the scripts:
2121

2222
1. Install [Microsoft Web Platform Installer (v5 or higher)](https://www.microsoft.com/web/downloads/platform.aspx).
23-
2. Use it to install Microsoft Azure Powershell.
23+
2. Use it to install Microsoft Azure PowerShell.
2424

2525
In addition to using Resource Manager templates, there is a rich set of [Application Insights PowerShell cmdlets](https://docs.microsoft.com/powershell/module/az.applicationinsights), which make it easy to configure Application Insights resources programatically. The capabilities enabled by the cmdlets include:
2626

@@ -83,20 +83,20 @@ Create a new .json file - let's call it `template1.json` in this example. Copy t
8383
"defaultValue": 90,
8484
"allowedValues": [
8585
30,
86-
60,
87-
90,
88-
120,
89-
180,
90-
270,
91-
365,
92-
550,
93-
730
86+
60,
87+
90,
88+
120,
89+
180,
90+
270,
91+
365,
92+
550,
93+
730
9494
],
9595
"metadata": {
9696
"description": "Data retention in days"
9797
}
9898
},
99-
"ImmediatePurgeDataOn30Days": {
99+
"ImmediatePurgeDataOn30Days": {
100100
"type": "bool",
101101
"defaultValue": false,
102102
"metadata": {
@@ -225,7 +225,21 @@ Additional properties are available via the cmdlets:
225225

226226
Refer to the [detailed documentation](https://docs.microsoft.com/powershell/module/az.applicationinsights) for the parameters for these cmdlets.
227227

228-
## Set the data retention
228+
## Set the data retention
229+
230+
Below are three methods to programmatically set the data retention on an Application Insights resource.
231+
232+
### Setting data retention using a PowerShell commands
233+
234+
Here's a simple set of PowerShell commands to set the data retention for your Application Insights resource:
235+
236+
```PS
237+
$Resource = Get-AzResource -ResourceType Microsoft.Insights/components -ResourceGroupName MyResourceGroupName -ResourceName MyResourceName
238+
$Resource.Properties.RetentionInDays = 365
239+
$Resource | Set-AzResource -Force
240+
```
241+
242+
### Setting data retention using REST
229243

230244
To get the current data retention for your Application Insights resource, you can use the OSS tool [ARMClient](https://github.com/projectkudu/ARMClient). (Learn more about ARMClient from articles by [David Ebbo](http://blog.davidebbo.com/2015/01/azure-resource-manager-client.html) and [Daniel Bowbyes](https://blog.bowbyes.co.nz/2016/11/02/using-armclient-to-directly-access-azure-arm-rest-apis-and-list-arm-policy-details/).) Here's an example using `ARMClient`, to get the current retention:
231245

@@ -248,6 +262,8 @@ New-AzResourceGroupDeployment -ResourceGroupName "<resource group>" `
248262
-appName myApp
249263
```
250264

265+
### Setting data retention using a PowerShell script
266+
251267
The following script can also be used to change retention. Copy this script to save as `Set-ApplicationInsightsRetention.ps1`.
252268

253269
```PS
@@ -303,9 +319,9 @@ This script can then be used as:
303319
```PS
304320
Set-ApplicationInsightsRetention `
305321
[-SubscriptionId] <String> `
306-
[-ResourceGroupName] <String> `
307-
[-Name] <String> `
308-
[-RetentionInDays <Int>]
322+
[-ResourceGroupName] <String> `
323+
[-Name] <String> `
324+
[-RetentionInDays <Int>]
309325
```
310326

311327
## Set the daily cap

0 commit comments

Comments
 (0)