Last active
December 6, 2019 15:35
-
-
Save ljtill/eab57e175fad3aa426a76360e08b265b to your computer and use it in GitHub Desktop.
Provides the ability to retrieve logs for de-allocated Virtual Machines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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