Skip to content

Commit cfe160c

Browse files
committed
Learn Editor: Update personal-data-delete-export.md
1 parent 357694a commit cfe160c

File tree

1 file changed

+61
-45
lines changed

1 file changed

+61
-45
lines changed

articles/devtest-labs/personal-data-delete-export.md

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,64 +40,80 @@ You can export personal and lab usage data by using the Azure PowerShell. The da
4040

4141
```powershell
4242
Param (
43-
[Parameter (Mandatory=$true, HelpMessage="The storage account name where to store usage data")]
44-
[string] $storageAccountName,
43+
[Parameter (Mandatory=$true, HelpMessage="The resource group name of the storage account")]
44+
[string] $resourceGroupName,
45+
46+
[Parameter (Mandatory=$true, HelpMessage="The subscription id of the storage account and DTL")]
47+
[string] $subscriptionId,
4548
46-
[Parameter (Mandatory=$true, HelpMessage="The storage account key")]
47-
[string] $storageKey,
49+
[Parameter (Mandatory=$true, HelpMessage="The storage account name")]
50+
[string] $storageAccountName,
4851
49-
[Parameter (Mandatory=$true, HelpMessage="The DevTest Lab name to get usage data from")]
50-
[string] $labName,
52+
[Parameter (Mandatory=$true, HelpMessage="Expire time of the SAS Token")]
53+
[string] $expiryTime,
5154
52-
[Parameter (Mandatory=$true, HelpMessage="The DevTest Lab subscription")]
53-
[string] $labSubscription
54-
)
55+
[Parameter (Mandatory=$true, HelpMessage="Date to pull data from")][string] $startTime,
5556
56-
#Login
57-
Login-AzureRmAccount
57+
[Parameter (Mandatory=$true, HelpMessage="Name of the lab to export")]
58+
[string] $labName,
5859
59-
# Set the subscription for the lab
60-
Get-AzureRmSubscription -SubscriptionId $labSubscription | Select-AzureRmSubscription
60+
[Parameter (Mandatory=$true, HelpMessage="The desired SKU")]
61+
[string] $desiredSKU,
6162
62-
# DTL will create this container in the storage when invoking the action, cannot be changed currently
63-
$containerName = "labresourceusage"
63+
[Parameter (Mandatory=$true, HelpMessage="Protocol for SAS token generation")]
64+
[string] $protocol,
6465
65-
# Get the storage context
66-
$Ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey
67-
$SasToken = New-AzureStorageAccountSASToken -Service Blob, File -ResourceType Container, Service, Object -Permission rwdlacup -Protocol HttpsOnly -Context $Ctx
66+
[Parameter (Mandatory=$true, HelpMessage="Permissions given for SAS token")]
67+
[string] $permissions
6868
69-
# Generate the storage blob uri
70-
$blobUri = $Ctx.BlobEndPoint + $SasToken
71-
72-
# blobStorageAbsoluteSasUri and usageStartDate are required
69+
# Log in
70+
Connect-AzAccount -UseDeviceAuthentication
71+
72+
# Set your subscription
73+
Set-AzContext -SubscriptionId $subscriptionId
74+
75+
76+
# Create a resource group and storage account
77+
New-AzStorageAccount -ResourceGroupName $resourceGroupName `
78+
-Name $storageAccountName `
79+
-Location $location `
80+
-SkuName $desiredSKU
81+
82+
# Get storage account context
83+
$storageAccountContext = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
84+
$storageAccountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName
85+
86+
$Ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKeys[0].Value
87+
88+
# Create blob container
89+
$containerName = "exportLabResources"
90+
New-AzStorageContainer -Name $containerName `
91+
-Context $Ctx `
92+
-Permission Off
93+
94+
# Get SAS token
95+
$sasToken = New-AzStorageContainerSASToken `
96+
-Context $Ctx `
97+
-Name $containerName `
98+
-StartTime (Get-Date) `
99+
-ExpiryTime $expiryTime `
100+
-Permission $permissions `
101+
-Protocol $protocol
102+
103+
# Make blob endpoint
104+
$blobEndpointWithSas = $storageAccountContext.Context.BlobEndPoint + $containerName+ "?" + $sasToken
105+
106+
# Invoke Export Job
73107
$actionParameters = @{
74-
'blobStorageAbsoluteSasUri' = $blobUri
108+
'blobStorageAbsoluteSasUri' = $blobEndpointWithSas
75109
}
76110
77-
$startdate = (Get-Date).AddDays(-7)
78-
79111
$actionParameters.Add('usageStartDate', $startdate.Date.ToString())
80-
81-
# Get the lab resource group
82-
$resourceGroupName = (Find-AzureRmResource -ResourceType 'Microsoft.DevTestLab/labs' | Where-Object { $_.Name -eq $labName}).ResourceGroupName
83-
84-
# Create the lab resource id
85-
$resourceId = "/subscriptions/" + $labSubscription + "/resourceGroups/" + $resourceGroupName + "/providers/Microsoft.DevTestLab/labs/" + $labName + "/"
86-
87-
# !!!!!!! this is the new resource action to get the usage data.
88-
$result = Invoke-AzureRmResourceAction -Action 'exportLabResourceUsage' -ResourceId $resourceId -Parameters $actionParameters -Force
89112
90-
# Finish up cleanly
91-
if ($result.Status -eq "Succeeded") {
92-
Write-Output "Telemetry successfully downloaded for " $labName
93-
return 0
94-
}
95-
else
96-
{
97-
Write-Output "Failed to download lab: " + $labName
98-
Write-Error $result.toString()
99-
return -1
100-
}
113+
$resourceId = "/subscriptions/" + $subscriptionId + "/resourceGroups/" + $resourceGroupName + "/providers/Microsoft.DevTestLab/labs/" + $labName + "/"
114+
115+
$result = Invoke-AzureRmResourceAction -Action 'ExportResourceUsage' -ResourceId $resourceId -Parameters $actionParameters -Force
116+
101117
```
102118

103119
The key components in the above sample are:

0 commit comments

Comments
 (0)