Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active December 6, 2019 15:35
Show Gist options
  • Save ljtill/eab57e175fad3aa426a76360e08b265b to your computer and use it in GitHub Desktop.
Save ljtill/eab57e175fad3aa426a76360e08b265b to your computer and use it in GitHub Desktop.
Provides the ability to retrieve logs for de-allocated Virtual Machines
$logs = @()
$subscriptions = Get-AzSubscription
$subscriptions | ForEach-Object {
Set-AzContext -SubscriptionObject $_ | Out-Null
$resourceGroups = Get-AzResourceGroup
$resourceGroups | ForEach-Object {
$logs += Get-AzLog `
-ResourceGroup $_.ResourceGroupName `
-StartTime (Get-Date).AddDays(-14) `
-WarningAction SilentlyContinue `
| Where-Object -FilterScript {$_.OperationName.Value -like "Microsoft.Compute/virtualMachines/deallocate/action"}
}
}
$virtualMachineNames = @()
$count = 0
$logs | ForEach-Object {
$virtualMachineNames += $logs[$count].Id.Split("/")[8]
$count = $count + 1
}
$virtualMachineNames | Select-Object -Unique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment