title: Signtool allows me to sign code but Set-AuthenticodeSignature says the "certificate is not suitable for code signing"
body: <p>I have a self-signed code signing certificate, made with the directions from <a href="https://stackoverflow.com/a/201277/80274">this answer</a>, that works fine when used with <code>signtool.exe</code>, however if I try to sign using <code>Set-AuthenticodeSignature</code>, it fails.</p>
  <p>Why can I sign using <code>signtool</code>, but not using <code>Set-AuthenticodeSignature</code>?</p>
  <ul>
  <li><code>signtool</code>:
  <pre class="lang-powershell prettyprint-override"><code>Signtool sign /v /n &quot;VetWeb&quot; SetupRDPPermissions.ps1
  
    The following certificate was selected:
      Issued to: VetWeb
      Issued by: VetWeb CA
      Expires:   Sat Dec 31 18:59:59 2039
      SHA1 hash: 84136EBF8D2603C2CD6668C955F920C6C6482EE4
  
    Done Adding Additional Store
    Successfully signed: SetupRDPPermissions.ps1
  
    Number of files successfully Signed: 1
    Number of warnings: 0
  </code></pre>
   <br>
  </li>
  <li><code>Set-AuthenticodeSignature</code>:
  <pre class="lang-powershell prettyprint-override"><code>$cert = @(Get-Childitem cert:\CurrentUser\My | Where-Object -FilterScript {$_.Subject -eq 'CN=VetWeb'})[0]
  
  Set-AuthenticodeSignature SetupRDPPermissions.ps1 $cert
  
    Set-AuthenticodeSignature : Cannot sign code. The specified certificate is not suitable for code signing.
      At line:1 char:26
      + Set-AuthenticodeSignature &lt;&lt;&lt;&lt;  SetupRDPPermissions.ps1 $cert
        + CategoryInfo          : InvalidArgument: (:) [Set-AuthenticodeSignature], PSArgumentException
        + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SetAuthenticodeSignatureCommand
  </code></pre>
  <ul>
  <li><code>Get-Childitem cert:\CurrentUser\My -CodeSigningCert</code> returns no results <br><br></li>
  </ul>
  </li>
  <li>
  <pre class="lang-powershell prettyprint-override"><code> $cert | Format-List *
  
     PSPath             : Microsoft.PowerShell.Security\Certificate::CurrentUser\My\84136EBF8D2603C2CD6668C955F920C6C6482EE4
     PSParentPath       : Microsoft.PowerShell.Security\Certificate::CurrentUser\My
     PSChildName        : 84136EBF8D2603C2CD6668C955F920C6C6482EE4
     PSDrive            : cert
     PSProvider         : Microsoft.PowerShell.Security\Certificate
     PSIsContainer      : False
     Archived           : False
     Extensions         : {System.Security.Cryptography.Oid}
     FriendlyName       :
     IssuerName         : System.Security.Cryptography.X509Certificates.X500DistinguishedName
     NotAfter           : 12/31/2039 5:59:59 PM
     NotBefore          : 6/1/2012 1:49:31 PM
     HasPrivateKey      : True
     PrivateKey         : System.Security.Cryptography.RSACryptoServiceProvider
     PublicKey          : System.Security.Cryptography.X509Certificates.PublicKey
     RawData            : {48, 130, 1, 235...}
     SerialNumber       : CF330347F35AC0B4427AFFA82DB51238
     SubjectName        : System.Security.Cryptography.X509Certificates.X500DistinguishedName
     SignatureAlgorithm : System.Security.Cryptography.Oid
     Thumbprint         : 84136EBF8D2603C2CD6668C955F920C6C6482EE4
     Version            : 3
     Handle             : 479608336
     Issuer             : CN=VetWeb CA
     Subject            : CN=VetWeb
  </code></pre>
  </li>
  </ul>