SOLVED

Azure Policy - Enable Autoshutdown on Azure VM

%3CLINGO-SUB%20id%3D%22lingo-sub-3300129%22%20slang%3D%22de-DE%22%3EAzure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3300129%22%20slang%3D%22de-DE%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eit%20is%20possible%20to%20activate%20the%20Azure%20VM%20Autoshutdown%20Function%20with%20an%20Azure%20Policy%3F%3C%2FP%3E%3CP%3EI%20found%20always%20articles%20with%20an%20DevTest%20Lab.%20But%20i%20would%20like%20to%20use%20an%20AZure%20Policy%20at%20the%20Production%20Subscription%20to%20can%20found%20VMs%20without%20an%20Azure%20AutoShutdown%20Configuration.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20Regards%2CPhil%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3300129%22%20slang%3D%22de-DE%22%3E%3CLINGO-LABEL%3EAzure%20Policy%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301034%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301034%22%20slang%3D%22en-US%22%3EYes%2C%20you%20can.%20This%20blog%20post%20from%20Tao%20Yang%2C%20%3CA%20href%3D%22https%3A%2F%2Fblog.tyang.org%2F2019%2F06%2F02%2Fnew-azure-policy-definition-deploy-vm-shutdown-schedule%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblog.tyang.org%2F2019%2F06%2F02%2Fnew-azure-policy-definition-deploy-vm-shutdown-schedule%2F%3C%2FA%3E%20-%20help%20explains%20it.%20He%20has%20also%20written%20the%20Azure%20Policy%20JSON%20for%20you%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftyconsulting%2Fazurepolicy%2Fblob%2Fmaster%2Fpolicy-definitions%2Fdeploy-vm-shutdown-schedule%2Fazurepolicy.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftyconsulting%2Fazurepolicy%2Fblob%2Fmaster%2Fpolicy-definitions%2Fdeploy-vm-shutdown-schedule%2Fazurepolicy.json%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301095%22%20slang%3D%22de-DE%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301095%22%20slang%3D%22de-DE%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F108279%22%20target%3D%22_blank%22%3E%40Luke%20Murray%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%20Thanks%20for%20this%20Answer.%3CBR%20%2F%3EI%20found%20this%20website%20to.%20But%20im%20a%20little%20bit%20confused%20about%20the%20Fields%20in%20the%20JSON%20File.%3CBR%20%2F%3EThey%20always%20use%20the%20%22DevtestLab%22%20Fields.%3CBR%20%2F%3E%3CBR%20%2F%3ECan%20i%20use%20this%20also%20for%20the%20normal%20Azure%20Tenant%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301106%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301106%22%20slang%3D%22en-US%22%3EI%20haven't%20personally%20tried%20it%2C%20but%20it%20should%20work.%20You%20can%20always%20deploy%20it%20to%20a%20Resource%20Group%20as%20a%20test.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3301173%22%20slang%3D%22de-DE%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3301173%22%20slang%3D%22de-DE%22%3EIt%20doesn't%20work.%3CBR%20%2F%3EThe%20VM%20without%20an%20Autoshutdown%20Configuration%20is%20listen%20at%20compliant.%3CBR%20%2F%3E%3CBR%20%2F%3EDo%20you%20have%20any%20more%20Idea%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3317268%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3317268%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F766780%22%20target%3D%22_blank%22%3E%40Phil123%3C%2FA%3EI'm%20just%20testing%20this.%20Did%20you%20set%20a%20Remediation%20Task%20as%20part%20of%20the%20deployment%20so%20that%20it%20can%20deploy%20the%20%3CSPAN%3EComputeVmShutdownTask%3C%2FSPAN%3E%2C%20if%20it%20doesn't%20exist%20and%20make%20them%20compliant%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22LukeMurray_0-1651701858721.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F369318iC5913A5E427AE88A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22LukeMurray_0-1651701858721.png%22%20alt%3D%22LukeMurray_0-1651701858721.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22LukeMurray_1-1651701881358.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F369319iF8BB50F3E50C3AAA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22LukeMurray_1-1651701881358.png%22%20alt%3D%22LukeMurray_1-1651701881358.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3319902%22%20slang%3D%22de-DE%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3319902%22%20slang%3D%22de-DE%22%3EDid%20it%20work%20as%20you%3F%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20done%20so%20many%20tests.%20I%20must%20test%20it%20again.%3CBR%20%2F%3EWhen%20you%20say%20that%20its%20work%20than%20have%20i%20forgot%20the%20remediation%20task%20i%20think.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3319927%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3319927%22%20slang%3D%22en-US%22%3EHi%2C%20Phil.%3CBR%20%2F%3E%3CBR%20%2F%3EYes%2C%20it%20did!%3CBR%20%2F%3E%3CBR%20%2F%3EDelete%20the%20assignment%2C%20re-run%20it%20again%2C%20and%20create%20your%20Remediation%20Task%20with%20your%20System%20Assigned%20identity.%20Although%20not%20required%2C%20if%20you%20have%20an%20AutoShutdown%20already%20configured%2C%20you%20can%20just%20set%20it%20to%20'None'%20to%20let%20the%20policy%20configure%20the%20correct%20time%20etc%20in%20one%20place.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3319945%22%20slang%3D%22de-DE%22%3ERe%3A%20Azure%20Policy%20-%20Enable%20Autoshutdown%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3319945%22%20slang%3D%22de-DE%22%3EReally%20cool.%3CBR%20%2F%3EThanks%20for%20your%20help.%20It%20was%20many%20helpfully.%3CBR%20%2F%3E%3CBR%20%2F%3EP.s.%20I%20have%20another%20question%20about%20Policys%20and%20Extensions.%3CBR%20%2F%3EI%20will%20open%20a%20new%20case%20for%20this.%20Maybe%20you%20can%20help%20me%20at%20this%20Point%20to.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Contributor

Hello,

 

it is possible to activate the Azure VM Autoshutdown Function with an Azure Policy?

I found always articles with an DevTest Lab. But i would like to use an AZure Policy at the Production Subscription to can found VMs without an Azure AutoShutdown Configuration.

 

Thanks.

 

Best Regards,
Phil

8 Replies
@Luke Murray

Thanks for this Answer.
I found this Website to. But im a little bit confused about the Fields in the JSON File.
They always use the "DevtestLab" Fields.

Can i use this also for the normal Azure Tenant?

I haven't personally tried it, but it should work. You can always deploy it to a Resource Group as a test.
It doesnt work.
The VM without an Autoshutdown Configuration ist listen at compliant.

Do you have any more Idea?

@Phil123I'm just testing this. Did you set a Remediation Task as part of the deployment so that it can deploy the ComputeVmShutdownTask, if it doesn't exist and make them compliant?

 

LukeMurray_0-1651701858721.png

LukeMurray_1-1651701881358.png

 

 

 

Did it work as you?

I have done so many tests. I must test it again.
When you say that its work than have i forgot the remediation task i think.
best response confirmed by Phil123 (Contributor)
Solution
Hi, Phil.

Yes, it did!

Delete the assignment, re-run it again, and create your Remediation Task with your System Assigned identity. Although not required, if you have an AutoShutdown already configured, you can just set it to 'None' to let the policy configure the correct time etc in one place.
Really cool.
Thanks for your help. It was many helpfully.

P.s. I have another question about Policys and Extensions.
I will open a new case for this. Maybe you can help me at this Point to.

Thanks.