Software Installation Using Azure Policy State Change Events

Published Jun 18 2021 12:15 AM 1,373 Views
Microsoft

 

Azure Policy can give us the ability to audit settings inside a virtual machine using Guest Configuration. However, at this time we can’t remediate those machines because the feature is not yet available. This means that although we can see that a virtual machine is non-compliant there is little you can do about fixing it from the policy blade itself.

 

One of the built-in Guest Configuration policies can audit whether specific software is installed in a Windows machine, this could be a full software program or a specific agent. But then how do install the software based on the non-compliant policy result?

 

Thanks to Azure Policy state change events we can now detect when a resource changes it’s compliance settings and we can subscribe to these events using an Event Grid Subscription. I’ve used Event Grid in a previous post, but this time I’m going to use an Azure Automation runbook and some PowerShell to install the missing software package (PowerShell 7).

 

Pre-Requisite Deployment

 

I’m going to need several different resources to make this all work – so I’ve scripted everything up as Bicep templates and PowerShell scripts to run the deployment. All the files are in the GitHub repository, you can download them, and the only modification will be the names of the resources in deploy.ps1.

 

s1.png

 

After updating those fields, you can run the script, it will complete the following steps.

  • Deploy a new storage account.
  • Deploy a container into the storage account called software where the MSI file is placed.
  • Deploy a new automation account which is assigned a managed identity. This feature is currently in preview and simplifies the previous approach to giving permissions to an automation service principal.
  • Deploy a couple of variables into the automation account which are used by the runbook.
  • Assign Contributor permission to the automation account managed identity.
  • Install all the Az modules required by the runbook (this does take a bit of time to complete).
  • Assign the policy below to the resource group. This will install the Guest Configuration agent which is a pre-requisite for the software installation policy.

s2.png

  • Create a system topic to listen to the policy state changes.

 

It takes a while to deploy the initial template – but be patient. There is some output logging so you can see what the rest of the script does.

  • Download the PowerShell 7 MSI and upload it to the storage account.
  • Publish the runbook to the automation account
  • Create a webhook for the runbook
  • Deploy and Event Grid Subscription and the software installation policy.

 

s3.png

 

The policies will be deployed to the resource group...

 

s4.png

 

The software installation file is ready in the storage account...

 

s5.png

 

And the Event Grid subscription is listening for policy events...

 

s6.png

 

I’ve adjusted the filters for the events which I’m interested in – it should only fire the webhook when the software installation policy returns a non-compliant result.

 

s7.png

 

Testing the Process

 

And now for some testing. I’ll create a standard Windows Server in the resource group by just going through the wizard – when complete my machine will not have PowerShell 7 installed (simply because it isn't there out of the box).

 

s8.png

 

Checking the Apps and Features on the server...

 

s9.png

 

Things are going to start moving in this virtual machine, but at some point, that software installation policy is going to return a non-compliant result. This can happen either before or after the Guest Configuration agents are installed, now it doesn’t really matter. The Guest Configuration extension will eventually install and check for the installed application. It generally takes around 30 minutes for policy evaluation to complete – you can trigger an evaluation using PowerShell at any time by running.

 

Start-AzPolicyComplianceScan -ResourceGroupName SoftwareInstallation

 

 

It is called out in the documentation that state change events are only fired after the evaluation is complete. From my testing this took around 10 or so minutes so you have to patient.

 

While you wait, I’ll explain the runbook that is going to be run. The steps involved in this one are…

  1. Strip down the subject from the Event Grid event – the schema can be found here.
  2. Create a script object using a here-string and write that out to a script file in the runbook worker.
  3. Call the Invoke-AzVMRunCommand cmdlet on the virtual machine and run the script that is now in the runbook worker.

When it is eventually called – the extension runs the script which downloads and installs PowerShell from the storage account.

 

Back to the process and my software installation policy has returned a non-compliant result for my virtual machine. As I said before you need to wait until the evaluation cycle is complete before an event will be fired.

 

s10.png

 

I’ve captured the policy event that was generated by the Azure platform and it is below – note how the fields correspond to our filters and the subject contains the affected resource id.

 

s15.png

 

Now when I check the automation account I can see the job has been run and there are no errors in the runbook output which is a good sign...

 

s12.png

 

Finally, when I log on to the server, I can see the application has installed…

 

s13.png

 

The Guest Configuration service runs on its own timer, in turn it sends reports back to a guest assignment object. Azure Policy then performs its evaluation based on these objects so there is an inherent delay in a resource becoming compliant. However now that the extensions and software is installed eventually this resource will report back as compliant to the guest configuration object and finally the policy.

 

s14.png

 

Well, there it is, a way to use Azure Policy and state change events to trigger automation and remediate guest configuration policies. You could use this to install multiple agents on your virtual machines without affecting existing DSC configurations or custom script extensions. As always some caveats with the testing: -

  • My testing cases are small and in no way should reflect your own testing.
  • This is hosted on GitHub – if there are issues or you make changes, please submit a PR for review.

 

Thanks for reading, I hope this helps you out!

 

 

Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

%3CLINGO-SUB%20id%3D%22lingo-sub-2420515%22%20slang%3D%22en-US%22%3ESoftware%20Installation%20Using%20Azure%20Policy%20State%20Change%20Events%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2420515%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAzure%20Policy%20can%20give%20us%20the%20ability%20to%20audit%20settings%20inside%20a%20virtual%20machine%20using%20Guest%20Configuration.%20However%2C%20at%20this%20time%20we%20can%E2%80%99t%20remediate%20those%20machines%20because%20the%20feature%20is%20not%20yet%20available.%20This%20means%20that%20although%20we%20can%20see%20that%20a%20virtual%20machine%20is%20non-compliant%20there%20is%20little%20you%20can%20do%20about%20fixing%20it%20from%20the%20policy%20blade%20itself.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20of%20the%20built-in%20Guest%20Configuration%20policies%20can%20audit%20whether%20specific%20software%20is%20installed%20in%20a%20Windows%20machine%2C%20this%20could%20be%20a%20full%20software%20program%20or%20a%20specific%20agent.%20But%20then%20how%20do%20install%20the%20software%20based%20on%20the%20non-compliant%20policy%20result%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fgovernance%2Fpolicy%2Fconcepts%2Fevent-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Policy%20state%20change%20events%3C%2FA%3E%20we%20can%20now%20detect%20when%20a%20resource%20changes%20it%E2%80%99s%20compliance%20settings%20and%20we%20can%20subscribe%20to%20these%20events%20using%20an%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fevent-grid%2Fevent-schema-policy%3Ftabs%3Devent-grid-event-schema%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EEvent%20Grid%20Subscription%3C%2FA%3E.%20I%E2%80%99ve%20used%20Event%20Grid%20in%20a%20previous%20post%2C%20but%20this%20time%20I%E2%80%99m%20going%20to%20use%20an%20Azure%20Automation%20runbook%20and%20some%20PowerShell%20to%20install%20the%20missing%20software%20package%20(PowerShell%207).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-263567072%22%20id%3D%22toc-hId-259841211%22%3EPre-Requisite%20Deployment%3C%2FH4%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%E2%80%99m%20going%20to%20need%20several%20different%20resources%20to%20make%20this%20all%20work%20%E2%80%93%20so%20I%E2%80%99ve%20scripted%20everything%20up%20as%20Bicep%20templates%20and%20PowerShell%20scripts%20to%20run%20the%20deployment.%20All%20the%20files%20are%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fanwather%2FPolicySoftwareInstallation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGitHub%20repository%3C%2FA%3E%2C%20you%20can%20download%20them%2C%20and%20the%20only%20modification%20will%20be%20the%20names%20of%20the%20resources%20in%20deploy.ps1.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s1.png%22%20style%3D%22width%3A%20722px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286695iC1798815E6C5A5FA%2Fimage-dimensions%2F722x96%3Fv%3Dv2%22%20width%3D%22722%22%20height%3D%2296%22%20role%3D%22button%22%20title%3D%22s1.png%22%20alt%3D%22s1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20updating%20those%20fields%2C%20you%20can%20run%20the%20script%2C%20it%20will%20complete%20the%20following%20steps.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EDeploy%20a%20new%20storage%20account.%3C%2FLI%3E%0A%3CLI%3EDeploy%20a%20container%20into%20the%20storage%20account%20called%20%3CEM%3Esoftware%3C%2FEM%3E%20where%20the%20MSI%20file%20is%20placed.%3C%2FLI%3E%0A%3CLI%3EDeploy%20a%20new%20automation%20account%20which%20is%20assigned%20a%20managed%20identity.%20This%20feature%20is%20currently%20in%20preview%20and%20simplifies%20the%20previous%20approach%20to%20giving%20permissions%20to%20an%20automation%20service%20principal.%3C%2FLI%3E%0A%3CLI%3EDeploy%20a%20couple%20of%20variables%20into%20the%20automation%20account%20which%20are%20used%20by%20the%20runbook.%3C%2FLI%3E%0A%3CLI%3EAssign%20Contributor%20permission%20to%20the%20automation%20account%20managed%20identity.%3C%2FLI%3E%0A%3CLI%3EInstall%20all%20the%20Az%20modules%20required%20by%20the%20runbook%20(this%20does%20take%20a%20bit%20of%20time%20to%20complete).%3C%2FLI%3E%0A%3CLI%3EAssign%20the%20policy%20below%20to%20the%20resource%20group.%20This%20will%20install%20the%20Guest%20Configuration%20agent%20which%20is%20a%20pre-requisite%20for%20the%20software%20installation%20policy.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s2.png%22%20style%3D%22width%3A%20490px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286696i14240B334BA00393%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22s2.png%22%20alt%3D%22s2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreate%20a%20system%20topic%20to%20listen%20to%20the%20policy%20state%20changes.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20takes%20a%20while%20to%20deploy%20the%20initial%20template%20%E2%80%93%20but%20be%20patient.%20There%20is%20some%20output%20logging%20so%20you%20can%20see%20what%20the%20rest%20of%20the%20script%20does.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EDownload%20the%20PowerShell%207%20MSI%20and%20upload%20it%20to%20the%20storage%20account.%3C%2FLI%3E%0A%3CLI%3EPublish%20the%20runbook%20to%20the%20automation%20account%3C%2FLI%3E%0A%3CLI%3ECreate%20a%20webhook%20for%20the%20runbook%3C%2FLI%3E%0A%3CLI%3EDeploy%20and%20Event%20Grid%20Subscription%20and%20the%20software%20installation%20policy.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s3.png%22%20style%3D%22width%3A%20453px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286697i5575CAFF2ACFF4A6%2Fimage-dimensions%2F453x188%3Fv%3Dv2%22%20width%3D%22453%22%20height%3D%22188%22%20role%3D%22button%22%20title%3D%22s3.png%22%20alt%3D%22s3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20policies%20will%20be%20deployed%20to%20the%20resource%20group...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s4.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286698i2DAE05C4B5C383BA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22s4.png%22%20alt%3D%22s4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20software%20installation%20file%20is%20ready%20in%20the%20storage%20account...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s5.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286701i785B32E2F1B2F888%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22s5.png%22%20alt%3D%22s5.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20the%20Event%20Grid%20subscription%20is%20listening%20for%20policy%20events...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s6.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286703iE2E198D7DB7A5AB5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22s6.png%22%20alt%3D%22s6.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%E2%80%99ve%20adjusted%20the%20filters%20for%20the%20events%20which%20I%E2%80%99m%20interested%20in%20%E2%80%93%20it%20should%20only%20fire%20the%20webhook%20when%20the%20software%20installation%20policy%20returns%20a%20non-compliant%20result.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s7.png%22%20style%3D%22width%3A%20489px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286704i030F94A5A55E7AEA%2Fimage-dimensions%2F489x181%3Fv%3Dv2%22%20width%3D%22489%22%20height%3D%22181%22%20role%3D%22button%22%20title%3D%22s7.png%22%20alt%3D%22s7.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1543887391%22%20id%3D%22toc-hId--1547613252%22%3ETesting%20the%20Process%3C%2FH4%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20now%20for%20some%20testing.%20I%E2%80%99ll%20create%20a%20standard%20Windows%20Server%20in%20the%20resource%20group%20by%20just%20going%20through%20the%20wizard%20%E2%80%93%20when%20complete%20my%20machine%20will%20not%20have%20PowerShell%207%20installed%20(simply%20because%20it%20isn't%20there%20out%20of%20the%20box).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s8.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286707i0158F070DC2B3EC7%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22s8.png%22%20alt%3D%22s8.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EChecking%20the%20Apps%20and%20Features%20on%20the%20server...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s9.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286708i0314A25CE6ADD8D5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22s9.png%22%20alt%3D%22s9.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThings%20are%20going%20to%20start%20moving%20in%20this%20virtual%20machine%2C%20but%20at%20some%20point%2C%20that%20software%20installation%20policy%20is%20going%20to%20return%20a%20non-compliant%20result.%20This%20can%20happen%20either%20before%20or%20after%20the%20Guest%20Configuration%20agents%20are%20installed%2C%20now%20it%20doesn%E2%80%99t%20really%20matter.%20The%20Guest%20Configuration%20extension%20will%20eventually%20install%20and%20check%20for%20the%20installed%20application.%20It%20generally%20takes%20around%2030%20minutes%20for%20policy%20evaluation%20to%20complete%20%E2%80%93%20you%20can%20trigger%20an%20evaluation%20using%20PowerShell%20at%20any%20time%20by%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EStart-AzPolicyComplianceScan%20-ResourceGroupName%20SoftwareInstallation%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20is%20called%20out%20in%20the%20documentation%20that%20state%20change%20events%20are%20only%20fired%20after%20the%20evaluation%20is%20complete.%20From%20my%20testing%20this%20took%20around%2010%20or%20so%20minutes%20so%20you%20have%20to%20patient.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhile%20you%20wait%2C%20I%E2%80%99ll%20explain%20the%20runbook%20that%20is%20going%20to%20be%20run.%20The%20steps%20involved%20in%20this%20one%20are%E2%80%A6%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EStrip%20down%20the%20subject%20from%20the%20Event%20Grid%20event%20%E2%80%93%20the%20schema%20can%20be%20found%20here.%3C%2FLI%3E%0A%3CLI%3ECreate%20a%20script%20object%20using%20a%20here-string%20and%20write%20that%20out%20to%20a%20script%20file%20in%20the%20runbook%20worker.%3C%2FLI%3E%0A%3CLI%3ECall%20the%20Invoke-AzVMRunCommand%20cmdlet%20on%20the%20virtual%20machine%20and%20run%20the%20script%20that%20is%20now%20in%20the%20runbook%20worker.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EWhen%20it%20is%20eventually%20called%20%E2%80%93%20the%20extension%20runs%20the%20script%20which%20downloads%20and%20installs%20PowerShell%20from%20the%20storage%20account.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBack%20to%20the%20process%20and%20my%20software%20installation%20policy%20has%20returned%20a%20non-compliant%20result%20for%20my%20virtual%20machine.%20As%20I%20said%20before%20you%20need%20to%20wait%20until%20the%20evaluation%20cycle%20is%20complete%20before%20an%20event%20will%20be%20fired.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s10.png%22%20style%3D%22width%3A%20446px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286710i6EB6CEB1D5E3D217%2Fimage-dimensions%2F446x87%3Fv%3Dv2%22%20width%3D%22446%22%20height%3D%2287%22%20role%3D%22button%22%20title%3D%22s10.png%22%20alt%3D%22s10.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%E2%80%99ve%20captured%20the%20policy%20event%20that%20was%20generated%20by%20the%20Azure%20platform%20and%20it%20is%20below%20%E2%80%93%20note%20how%20the%20fields%20correspond%20to%20our%20filters%20and%20the%20subject%20contains%20the%20affected%20resource%20id.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s15.png%22%20style%3D%22width%3A%20666px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286711iF1110326FF6D8BDA%2Fimage-dimensions%2F666x584%3Fv%3Dv2%22%20width%3D%22666%22%20height%3D%22584%22%20role%3D%22button%22%20title%3D%22s15.png%22%20alt%3D%22s15.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20when%20I%20check%20the%20automation%20account%20I%20can%20see%20the%20job%20has%20been%20run%20and%20there%20are%20no%20errors%20in%20the%20runbook%20output%20which%20is%20a%20good%20sign...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s12.png%22%20style%3D%22width%3A%20584px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286712i8D98A0F8CACCA07B%2Fimage-dimensions%2F584x257%3Fv%3Dv2%22%20width%3D%22584%22%20height%3D%22257%22%20role%3D%22button%22%20title%3D%22s12.png%22%20alt%3D%22s12.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFinally%2C%20when%20I%20log%20on%20to%20the%20server%2C%20I%20can%20see%20the%20application%20has%20installed%E2%80%A6%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s13.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286713i99265097F21E96C7%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22s13.png%22%20alt%3D%22s13.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Guest%20Configuration%20service%20runs%20on%20its%20own%20timer%2C%20in%20turn%20it%20sends%20reports%20back%20to%20a%20guest%20assignment%20object.%20Azure%20Policy%20then%20performs%20its%20evaluation%20based%20on%20these%20objects%20so%20there%20is%20an%20inherent%20delay%20in%20a%20resource%20becoming%20compliant.%20However%20now%20that%20the%20extensions%20and%20software%20is%20installed%20eventually%20this%20resource%20will%20report%20back%20as%20compliant%20to%20the%20guest%20configuration%20object%20and%20finally%20the%20policy.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s14.png%22%20style%3D%22width%3A%20613px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286715iC4477AA58CB89DDD%2Fimage-dimensions%2F613x170%3Fv%3Dv2%22%20width%3D%22613%22%20height%3D%22170%22%20role%3D%22button%22%20title%3D%22s14.png%22%20alt%3D%22s14.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWell%2C%20there%20it%20is%2C%20a%20way%20to%20use%20Azure%20Policy%20and%20state%20change%20events%20to%20trigger%20automation%20and%20remediate%20guest%20configuration%20policies.%20You%20could%20use%20this%20to%20install%20multiple%20agents%20on%20your%20virtual%20machines%20without%20affecting%20existing%20DSC%20configurations%20or%20custom%20script%20extensions.%20As%20always%20some%20caveats%20with%20the%20testing%3A%20-%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EMy%20testing%20cases%20are%20small%20and%20in%20no%20way%20should%20reflect%20your%20own%20testing.%3C%2FLI%3E%0A%3CLI%3EThis%20is%20hosted%20on%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fanwather%2FPolicySoftwareInstallation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGitHub%3C%2FA%3E%20%E2%80%93%20if%20there%20are%20issues%20or%20you%20make%20changes%2C%20please%20submit%20a%20PR%20for%20review.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20reading%2C%20I%20hope%20this%20helps%20you%20out!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3E%3CFONT%20size%3D%221%202%203%204%205%206%207%22%3EDisclaimer%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CFONT%20size%3D%221%202%203%204%205%206%207%22%3EThe%20sample%20scripts%20are%20not%20supported%20under%20any%20Microsoft%20standard%20support%20program%20or%20service.%20The%20sample%20scripts%20are%20provided%20AS%20IS%20without%20warranty%20of%20any%20kind.%20Microsoft%20further%20disclaims%20all%20implied%20warranties%20including%2C%20without%20limitation%2C%20any%20implied%20warranties%20of%20merchantability%20or%20of%20fitness%20for%20a%20particular%20purpose.%20The%20entire%20risk%20arising%20out%20of%20the%20use%20or%20performance%20of%20the%20sample%20scripts%20and%20documentation%20remains%20with%20you.%20In%20no%20event%20shall%20Microsoft%2C%20its%20authors%2C%20or%20anyone%20else%20involved%20in%20the%20creation%2C%20production%2C%20or%20delivery%20of%20the%20scripts%20be%20liable%20for%20any%20damages%20whatsoever%20(including%2C%20without%20limitation%2C%20damages%20for%20loss%20of%20business%20profits%2C%20business%20interruption%2C%20loss%20of%20business%20information%2C%20or%20other%20pecuniary%20loss)%20arising%20out%20of%20the%20use%20of%20or%20inability%20to%20use%20the%20sample%20scripts%20or%20documentation%2C%20even%20if%20Microsoft%20has%20been%20advised%20of%20the%20possibility%20of%20such%20damages.%3C%2FFONT%3E%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2420515%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22s14.png%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286716i911507934C747CC1%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22s14.png%22%20alt%3D%22s14.png%22%20%2F%3E%3C%2FSPAN%3EAzure%20Policy%20can%20give%20us%20the%20ability%20to%20audit%20settings%20inside%20a%20virtual%20machine%20using%20Guest%20Configuration.%20However%2C%20at%20this%20time%20we%20can%E2%80%99t%20remediate%20those%20machines%20because%20the%20feature%20is%20not%20yet%20available.%26nbsp%3BBut%20then%20how%20do%20install%20the%20software%20based%20on%20the%20non-compliant%20policy%20result%3F%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2420515%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAnthonyWatherston%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Jun 18 2021 09:23 AM
Updated by: