title: UnauthorizedAccess on post build of Visual Studio
body: <p>I am trying to work on a Windows laptop and setup a <code>post_build.ps1</code> after the regular build of Visual Studio in VB.NET</p>
  
  <p>When I run the script on powershell command, it doesn't have any error. But when I do it through Build in Visual Studio, I have this:</p>
  
  <p><code>powershell ./_POST_BUILD.ps1 exited with code 1</code></p>
  
  <p>If I enable the diagnostic output, I can see through the output this:</p>
  
  <pre><code>1&gt;  AuthorizationManager check failed. (TaskId:39)
  1&gt;      + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException (TaskId:39)
  1&gt;      + FullyQualifiedErrorId : UnauthorizedAccess (TaskId:39)
  </code></pre>
  
  <p>What I tried:</p>
  
  <ol>
  <li>Set the policies to unrestricted with <code>Set-ExecutionPolicy Unrestricted -scope LocalMachine</code> and <code>Set-ExecutionPolicy Unrestricted -scope CurrentUser</code></li>
  <li>Change the post build event in Visual Studio to <code>Powershell.exe -ExecutionPolicy Unrestricted -file "$(SolutionDir)bin\debug\_POST_BUILD.ps1"</code></li>
  <li>Unblock file with right click -> properties -> unblock</li>
  <li>Run Visual Studio as administrator always</li>
  </ol>