title: Different Behavior between .ps1 vs exe
body: <p>I hope you're well.
  I am currently facing to some incomprehensible behavior which you can find the description of below.</p>
  <p>What this code do?</p>
  <ol>
  <li>Check in 2 registry location (32 and 64 bits) for Ins_ProductVersion</li>
  <li>If nothing found then message displayed is Product Version: Not
  found!</li>
  <li>If value is found then display product version from
  Ins_ProductVersion</li>
  </ol>
  <p><strong>== Behavior descripton ==</strong></p>
  <p>If I use the code below into Powershell ISE, it work as expected:</p>
  <p>Ouput provide:</p>
  <blockquote>
  <ul>
  <li>Product Version: 11.7.0.669</li>
  </ul>
  </blockquote>
  <pre><code>foreach ($path in 'HKLM:\SOFTWARE\KasperskyLab\protected\KES\environment\', 'HKLM:\SOFTWARE\WOW6432Node\KasperskyLab\protected\KES\environment\') {
  try {
  $hotfix = Get-ItemPropertyValue -Path $path  -Name 'Ins_ProductVersion' -ErrorAction SilentlyContinue
  # assuming you want to exit the loop at the first successfull 'hit'
  if ($hotfix) { break }
  }
  catch { 
      #Write-Warning $_.Exception.Message
      #Write-Host &quot;Unable to find $hotfix&quot;
  }} 
  
  if ($hotfix) {write-host &quot;- Product Version: $hotfix&quot;}
  else {write-host &quot;- Product Version: Not found!&quot;}
  </code></pre>
  <p>If I convert this code to exe with ps2exe, the output result is different.</p>
  <blockquote>
  <p>ps2exe samples.ps1 test.exe</p>
  </blockquote>
  <pre><code>.\test.exe
  .\test.exe : ERROR: Impossible de trouver une variable nomm‚e ®ÿhotfixÿ¯.
  Au caractère Ligne:1 : 1
  + .\test.exe
  + ~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (ERROR: Impossib...m‚e ®ÿhotfixÿ¯.:String) [], RemoteException
  + FullyQualifiedErrorId : NativeCommandError
  
  - Product Version: Not found!
  </code></pre>
  <p>I hope you can help me to understand where the problem is :)</p>
  <p>Thanks in advance.</p>
  <p>LEFBE</p>
  <p>==[ Solution ] ==
  I found out where the problem was. The code works as expected, but my antivirus has been configured to block unsigned applications that read registry keys. Based on this, the value $ hotfix could not be obtained</p>