title: How do you keep track of changes in registry using powershell?
body: <p>I have a ruby script that basically checks for few keys in registry that are flags for our application. The script would check if the flag was 'on'(DWORD value 1) for longer than 14 days, it will turn it off(0) and send out an email. </p>
  
  <p>To track this, what the script does is during the first run, it creates a local DB and store the flag name, date time and so on of every flag that is on in the registry. During next run, it checks this DB to find if the flag has been on for more than 14 days.</p>
  
  <p>I wanted to know if there is a better way to handle this using powershell or should i create a local DB and follow the same flow?</p>
  
  <h2>Further info:</h2>
  
  <p>So i will have different accounts under '\HKEY_LOCAL_MACHINE\SOFTWARE\Company\Clients' and each client will have a debug folder which will have the flags as seen below</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Company\Clients
                                          \Client1\Debug
                                                      IsEmail
                                                      IsShip
                                          \Client2\Debug
                                                      IsEmail
                                                      IsPack
  </code></pre>
  
  <p>So i need to effectively iterate through each client, maybe create an XML/JSON or DB with the client name, flags defined and current date time. Then during a later run, i should be accessing this info, compare the registry entries and turn off flags that have been turned for longer than a days specified. I will use the timestamp saved early for this. </p>
  
  <h2>Update 1:</h2>
  
  <p>Few updates based on my updated understanding of how  powershell scripts work. I will have a master array or sort with a list of flags i need. For examples $MasterFlagList=['IsEmail','IsShip','IsNew']. Now during my first run of the application, i would like to create a json string like @tukan mentioned in this answer or xml file that will be something like:</p>
  
  <pre><code>&lt;xml&gt;
  &lt;Client1&gt;
      &lt;IsEmail&gt;
          &lt;value&gt;1&lt;/value&gt;
          &lt;time&gt;*current time*&lt;/time&gt;
      &lt;/IsEmail&gt;
      &lt;IsShip&gt;
          &lt;value&gt;1&lt;/value&gt;
          &lt;time&gt;*current time*&lt;/time&gt;
      &lt;/IsShip&gt;
      &lt;IsPack&gt;
          &lt;value&gt;0&lt;/value&gt;
          &lt;time&gt;*current time*&lt;/time&gt;
      &lt;/IsPack&gt;
  &lt;/Client1&gt;
  &lt;Client2&gt;
      &lt;IsEmail&gt;
          &lt;value&gt;0&lt;/value&gt;
          &lt;time&gt;*current time*&lt;/time&gt;
      &lt;/IsEmail&gt;
      &lt;IsShip&gt;
          &lt;value&gt;0&lt;/value&gt;
          &lt;time&gt;*current time*&lt;/time&gt;
      &lt;/IsShip&gt;
      &lt;IsPack&gt;
          &lt;value&gt;0&lt;/value&gt;
          &lt;time&gt;*current time*&lt;/time&gt;
      &lt;/IsPack&gt;
  &lt;/Client2&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>So basically what happens here is that the XML string will have all the flags from masterlist, but if there is an entry for those in registry, that value will be loaded(0 or 1) and for those not mentioned in registry, default value of 0 will be set.</p>
  
  <p>Next time i run, i will load this XML from directory into an object and for each client, i need to check if the XML already has a record, if so check the date time and see if the flag has been on for an amount of time, if so turn the flag off.</p>
  
  <p>A better solution to implement the idea is also welcome. I am new to powershell and that why i thought of this approach.</p>