3 Replies Latest reply on Mar 1, 2015 8:30 PM by jamesl1

    Scanning for broken gpt.ini files

    gregf SupportEmployee
      In case you need to search an environment for machines with corrupted gpt.ini files:

      $machines = gc 'c:\temp\machines.txt' 
        
      $machines | %{ 
          $ini = gc "\\$_\c$\windows\system32\GroupPolicy\gpt.ini" 
        
          $squareCount = ($ini | Select-String '\[' -AllMatches).Matches.Count - ($ini | Select-String '\]' -AllMatches).Matches.Count 
          $curlyCount = ($ini | Select-String '\{' -AllMatches).Matches.Count - ($ini | Select-String '\}' -AllMatches).Matches.Count 
        
          if (($squareCount -ne 0) -or ($curlyCount -ne 0)) { 
            $_ + "`tbroken" 
          } 
          else { 
            $_ + "`tokay" 
          } 
      }
      


      Sample output:

      L-R9P9T2R     okay 
      D-2N51XX1     okay 
      L-R9D5BA5     okay 
      L-2VBYFS1     broken 
      PRD-VMSOE01   okay 
      D-312HC2S     okay 
      D-96TV92S     okay 
      D-F9H9D2S     okay 
      L-J1NGCS1     broken 
      L-52M11P1     okay 
      L-6PVY7W1     okay 
      
      



      Notes
      • Change c:\temp\machines.txt to the path of your newline-separated list of machines
      • Works on the basis that an imbalance in curly or square braces means the .ini file is corrupt
      • Requires PowerShell 4.0 on the machine you run the script from (might work with 3.0 - I just haven't tried it)
        • 1. Re: Scanning for broken gpt.ini files
          rictersmith Specialist
          We decided to improve upon this script some so we could get more accurate results. We also wanted to automate the deleting of the gpt.ini file.
          Out of 15,000 devices, this script took awhile to run, but we detected nearly 800 devices that had a corrupt gpt.ini which was the root cause for those devices not running the AppSense Logoff processes.

          Additionally we wanted an initial run that simply detected the problem devices. Once detected, we shortened the machine.txt list to just the broken devices and ran it with the deletion at night shortly before our automated reboot cycle. The problem with the initial code is that it bases the offline value on the file not being accessible, which would be true if you delete the gpt.ini file and the device had not rebooted yet. This script uses the powershell test-connection command to see if the device can be connected to, and then logs differently if the file is inaccessible or deleted.

          $machines = gc 'c:\temp\machines.txt' 
          $logfile = 'c:\temp\gptresults.csv'
          $logDeleteFile = 'c:\temp\gpt_Delete_results.csv'
          $deletegpt = $FALSE #set to $TRUE if you also want to remove the gpt.ini file. It will get recreated on a reboot.
            
          $machines | %{ 
          
              if(Test-Connection $_ -Quiet){
          
          
               if(Test-Path "\\$_\c$\windows\system32\GroupPolicy\gpt.ini"){
          
                $ini = gc "\\$_\c$\windows\system32\GroupPolicy\gpt.ini" 
             
                $squareCount = ($ini | Select-String '\[' -AllMatches).Matches.Count - ($ini | Select-String '\]' -AllMatches).Matches.Count 
                $curlyCount = ($ini | Select-String '\{' -AllMatches).Matches.Count - ($ini | Select-String '\}' -AllMatches).Matches.Count 
             
                if (($squareCount -ne 0) -or ($curlyCount -ne 0)) { 
          
                          if($deletegpt){
                              remove-item -path "\\$_\c$\windows\system32\GroupPolicy\gpt.ini"
                    
                              $_ + "`tbroken" + "`tFileDeleted"  | Out-File $logDeleteFile -append
                          }
                          else{
                        $_ + "`tbroken" + "`tFileNOTDeleted" | Out-File $logfile -append
                          }
          
                } 
                else { 
                  $_ + "`tokay" | Out-File $logfile -append
                } 
               }
               else {
                $_ + "`tinaccessibleORremoved" | Out-File $logfile -append
               }
              }
              else{
                  $_ + "`toffline" | Out-File $logfile -append
              }
          } 
          
          • 2. Re: Scanning for broken gpt.ini files
            MalcolmBruton Rookie
            But do you know why they are broken?  What process breaks it.  I have seen the same and we have our own script to detect as well.
            • 3. Re: Scanning for broken gpt.ini files
              jamesl1 Apprentice
              The following knowledge base article describes the cause https://www.myappsense.com/Knowledgebase/TN-150974.aspx

              Basically two components both writing to the gpt.ini without synchronization can cause errors in formatting in the file. This dependency is removed in version 8.5 of EM.