In PowerShell (with the now-deprecated AzureRM module), you can do this:
Get-AzureRmVM <Stuff to filter the VMs you want go here> | Set-AzureRmVMBootDiagnostics -Enable -ResourceGroupName <storage-account-rg> -StorageAccountName <storage-account-name> | Update-AzureRmVM
This will get the VM objects, change the setting and apply the change.
Example, to update all VMs' diag storage account to bucket
in RG mygroup
:
Get-AzureRmVM | Set-AzureRmVMBootDiagnostics -Enable -ResourceGroupName mygroup -StorageAccountName bucket | Update-AzureRmVM
(You probably want to filter more...)
For the new Az module, the commands would change to: (same warnings as above will apply)
Get-AzVM <Stuff to filter the VMs you want go here> | Set-AzVMBootDiagnostic -Enable -ResourceGroupName <storage-account-rg> -StorageAccountName <storage-account-name> | Update-AzVM
Get-AzVM | Set-AzVMBootDiagnostic -Enable -ResourceGroupName mygroup -StorageAccountName bucket | Update-AzVM
(There is a deprecation warning for the plural version of the command - this uses the new name, but the warning still shows)