I am working on a PowerShell runbook to look at all vms in the azure subscription, find out if guest level monitoring is not enabled and enable it
Following is the command I am using to enable the diags.
Set-AzureRmVMDiagnosticsExtension -ResourceGroupName xxxxxx -VMName xxxxxx -DiagnosticsConfigurationPath $diagnosticsconfig_path -StorageAccountName xxxxxx
I am thinking of storing the diag xml file in a storage blog, how do I point to it with $diagnosticsconfig_path ?
If I use
Get-AzureStorageBlobContent -blob "xxx.json" -Container xxx -Context $storageAccount.Context
or
Get-AzureStorageFileContent -ShareName 'xxx' -Context $storageAccount.Context -path xxx.json
The runbook can download the file but how do I refer to this file as the diagpath in Set-AzureRmVMDiagnosticsExtension
Try the command below, you are no need to download the file, we can point the path directly to the blob url.
$SAResourceGroupName="<Storage Account ResourceGroupName>"
$StorageAccountName="<StorageAccountName>"
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $SAResourceGroupName -AccountName $StorageAccountName).Value[1]
$Context=New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tmpStart = Get-Date
$tmpEnd = $tmpStart.AddHours(2.0)
$SASToken = New-AzureStorageBlobSASToken -Blob "diagnostics_publicconfig.xml" -Container "111" -Context $Context -Permission r -StartTime $tmpStart -ExpiryTime $tmpEnd -FullURI
Set-AzureRmVMDiagnosticsExtension -ResourceGroupName joywebapp -VMName joyVM -DiagnosticsConfigurationPath "$SASToken" -StorageAccountName joystoragev2
In the runbook: