Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work on new Modules #13

Open
lukemurraynz opened this issue Feb 26, 2018 · 2 comments
Open

Does not work on new Modules #13

lukemurraynz opened this issue Feb 26, 2018 · 2 comments

Comments

@lukemurraynz
Copy link

Upgraded my Modules to the latest versions and the script fails to see tagged objects and then Shutdown or Turn them on. Using the versions of the earlier Azure modules that exist when creating Automation accounts work as a workaround, for the moment.

@iansmittie
Copy link

If you are getting the below message even though the VMs are tagged:
     "Not tagged for shutdown directly or via membership in a tagged resource group. Skipping this VM."
I got this working by changing the following 4 lines from:

$taggedResourceGroups = @(Get-AzureRmResourceGroup | where {$.Tags.Count -gt 0 -and $.Tags.Name -contains "AutoShutdownSchedule"})
if($vm.ResourceType -eq "Microsoft.Compute/virtualMachines" -and $vm.Tags -and $vm.Tags.Name -contains "AutoShutdownSchedule")
$schedule = ($vm.Tags | where Name -eq "AutoShutdownSchedule")["Value"]
$schedule = ($parentGroup.Tags | where Name -eq "AutoShutdownSchedule")["Value"]

to:

$taggedResourceGroups = @(Get-AzureRmResourceGroup | where {$_.Tags.AutoShutdownSchedule})
if($vm.ResourceType -eq "Microsoft.Compute/virtualMachines" -and $vm.Tags.AutoShutdownSchedule)
$schedule = $vm.Tags.AutoShutdownSchedule
$schedule = $parentGroup.Tags.AutoShutdownSchedule

@zarozak
Copy link

zarozak commented Jan 29, 2020

I also had to update the code for the vm tag detection to:

    # Check for direct tag or group-inherited tag
    if($vm.ResourceType -like "Microsoft.*/virtualMachines" -and $vm.Tags.AutoShutdownSchedule -gt 0)
    {
        # VM has direct tag (possible for resource manager deployment model VMs). Prefer this tag schedule.
        $schedule = $vm.Tags.AutoShutdownSchedule
        Write-Output "[$($vm.Name)]: Found direct VM schedule tag with value: $schedule"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants