Internal Certificate Chain Error <p>I wrote my first PowerShell script that accesses a short-cut (.lnk),</p> <p>to obtain its target, and then access that target to copy all of the files in that target directory to another directory.</p> <p>It works fine on my lap-top. I have admin privileges on my lap-top so I could easily change my executionPolicy to remoteSigned.  The person who really is going to run the script only has &quot;AllSigned&quot; executionPolicy. And he does not have admin on his lap-top so he cannot change his exeuctionPolicy.</p> <p>So, I read some articles about certificates and signing files. This certificate facility is new to me. </p> <p>I found some scripts which allowed me to create a &quot;.cer&quot; certificate. And I exported it.</p> <p>I found a script that allows me to sign a file. I ran that script and it looks like it signed the file.</p> <p>== script ==============================================</p> <p># *** sos *************************************************************<br/># *  Return the target directory locatin of a &quot;.lnk&quot; type object      *<br/># *********************************************************************<br/>#<br/>function link_target( $link)<br/>{<br/>  $shell = New-Object -com wscript.shell<br/>  $lnk   = $shell.CreateShortcut($link)<br/>  $tgt   = $lnk.TargetPath<br/>  return $tgt<br/>}<br/>#<br/># *** eos *************************************************************<br/>del c:\ISSS\Reports\*.xls -exclude *_report.xls<br/>$s = link_target(&quot;C:\Source_locations\User_reports.lnk&quot;)<br/>dir C:\ISSS\Reports\*.xls<br/>copy $s\*.xls    C:\Reports</p> <p># SIG # Begin signature block<br/># MIIEMwYJKoZIhvcNAQcCoIIEJDCCBCACAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB<br/># gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR<br/># AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU1me2pCTaKosL7n9ON5WMAEYT<br/># +nSgggI9MIICOTCCAaagAwIBAgIQmdia+k7om71HpfJvI46IADAJBgUrDgMCHQUA<br/># MCwxKjAoBgNVBAMTIVBvd2VyU2hlbGwgTG9jYWwgQ2VydGlmaWNhdGUgUm9vdDAe<br/># Fw0wOTA2MTExOTQ2NDNaFw0zOTEyMzEyMzU5NTlaMBoxGDAWBgNVBAMTD1Bvd2Vy<br/># U2h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I2iOU+CUrDRv3v<br/># cQw3tIT6qVv6qy11obITjKz2BCnblBY=<br/># SIG # End signature block<br/><br/>=== script ===============================================<br/><br/>It works correctly on my lap-top, but we receive &quot;internal certificate chain error&quot; when<br/>we try to run it on his computer.<br/><br/>I did an export of my &quot;.cer&quot; file and we ran certmgr.msc on his computer and imported that certificate into his personal store. The certificate has the &quot;all&quot; properties.<br/><br/>Maybe my signing process did not use my certificate to sign it. I don't know.<br/>Is this possible? How do I tell the sign script which certificate to use?<br/><br/>Here is the script I use to sign my scripts:<br/><br/>=== script ==============================================<br/> ## sign-file.ps1<br/> ## Sign a file<br/> param([string] $file=$(throw &quot;Please specify a filename.&quot;))<br/> $cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0]<br/> Set-AuthenticodeSignature $file $cert</p> <p># SIG # Begin signature block<br/>....<br/>=== script =======================================</p>© 2009 Microsoft Corporation. All rights reserved.Wed, 07 Oct 2009 13:58:08 Z19880378-d413-4db6-a28f-af7694570d1ehttp://social.technet.microsoft.com/Forums/en/ITCG/thread/19880378-d413-4db6-a28f-af7694570d1e#19880378-d413-4db6-a28f-af7694570d1ehttp://social.technet.microsoft.com/Forums/en/ITCG/thread/19880378-d413-4db6-a28f-af7694570d1e#19880378-d413-4db6-a28f-af7694570d1eL.E.E.http://social.technet.microsoft.com/Profile/en-US/?user=L.E.E.Internal Certificate Chain Error <p>I wrote my first PowerShell script that accesses a short-cut (.lnk),</p> <p>to obtain its target, and then access that target to copy all of the files in that target directory to another directory.</p> <p>It works fine on my lap-top. I have admin privileges on my lap-top so I could easily change my executionPolicy to remoteSigned.  The person who really is going to run the script only has &quot;AllSigned&quot; executionPolicy. And he does not have admin on his lap-top so he cannot change his exeuctionPolicy.</p> <p>So, I read some articles about certificates and signing files. This certificate facility is new to me. </p> <p>I found some scripts which allowed me to create a &quot;.cer&quot; certificate. And I exported it.</p> <p>I found a script that allows me to sign a file. I ran that script and it looks like it signed the file.</p> <p>== script ==============================================</p> <p># *** sos *************************************************************<br/># *  Return the target directory locatin of a &quot;.lnk&quot; type object      *<br/># *********************************************************************<br/>#<br/>function link_target( $link)<br/>{<br/>  $shell = New-Object -com wscript.shell<br/>  $lnk   = $shell.CreateShortcut($link)<br/>  $tgt   = $lnk.TargetPath<br/>  return $tgt<br/>}<br/>#<br/># *** eos *************************************************************<br/>del c:\ISSS\Reports\*.xls -exclude *_report.xls<br/>$s = link_target(&quot;C:\Source_locations\User_reports.lnk&quot;)<br/>dir C:\ISSS\Reports\*.xls<br/>copy $s\*.xls    C:\Reports</p> <p># SIG # Begin signature block<br/># MIIEMwYJKoZIhvcNAQcCoIIEJDCCBCACAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB<br/># gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR<br/># AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU1me2pCTaKosL7n9ON5WMAEYT<br/># +nSgggI9MIICOTCCAaagAwIBAgIQmdia+k7om71HpfJvI46IADAJBgUrDgMCHQUA<br/># MCwxKjAoBgNVBAMTIVBvd2VyU2hlbGwgTG9jYWwgQ2VydGlmaWNhdGUgUm9vdDAe<br/># Fw0wOTA2MTExOTQ2NDNaFw0zOTEyMzEyMzU5NTlaMBoxGDAWBgNVBAMTD1Bvd2Vy<br/># U2hlbGwgVXNlcjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA04s/pKSzkAkU<br/># A1vP9TL9MhZ1+5JCXj6lYdlV9GUoHoX5lZBkXAY9NofXXeLwzcbQ9XqukvvQ73oN<br/># MxodIPJc84ngg6RQUDFm5lgjHgiTua/cczohCNyvfCV+kduP2fE8trnUqJokzxDI<br/># lN5zQHdfd7ptB+98rhTkabM3Dv6umz0CAwEAAaN2MHQwEwYDVR0lBAwwCgYIKwYB<br/># BQUHAwMwXQYDVR0BBFYwVIAQXvn0+W06mVY6T7MBJEkriKEuMCwxKjAoBgNVBAMT<br/># IVBvd2VyU2hlbGwgTG9jYWwgQ2VydGlmaWNhdGUgUm9vdIIQ6k4XJepngoFPl/yI<br/># L95tkzAJBgUrDgMCHQUAA4GBALGnM4LTHzi9IGH8NwMlliaICqyrFbtzJCa44t/9<br/># li2ijU9DReuA/stqiBmpFQX1/m4IQcc8Lbt9xcQg6kOakRXjiNFp2jWPPyXLmz7h<br/># XbSZvfTDq8Py69LNjYIwKRZIK9Gj37o+5D4l/sj6+c96+qw31DCbrvr6Bsm9mr3r<br/># OTX/MYIBYDCCAVwCAQEwQDAsMSowKAYDVQQDEyFQb3dlclNoZWxsIExvY2FsIENl<br/># cnRpZmljYXRlIFJvb3QCEJnYmvpO6Ju9R6XybyOOiAAwCQYFKw4DAhoFAKB4MBgG<br/># CisGAQQBgjcCAQwxCjAIoAKAAKECgAAwGQYJKoZIhvcNAQkDMQwGCisGAQQBgjcC<br/># AQQwHAYKKwYBBAGCNwIBCzEOMAwGCisGAQQBgjcCARUwIwYJKoZIhvcNAQkEMRYE<br/># FEYNyIl6IAawtsGKa0qU0J/+GxclMA0GCSqGSIb3DQEBAQUABIGAxrkRaHLev7G1<br/># QKU+0s/EH+xLr6BAR9UVl/pCxPiw5xuSc6pHBrwtFLXUN45pOCE0TP/ENEUdOYBM<br/># FgoOT5PrihJgGRaBFKhBK6bhhg/sRSduXvY/jz23WsCVDWXM2OI2iOU+CUrDRv3v<br/># cQw3tIT6qVv6qy11obITjKz2BCnblBY=<br/># SIG # End signature block<br/><br/>=== script ===============================================<br/><br/>It works correctly on my lap-top, but we receive &quot;internal certificate chain error&quot; when<br/>we try to run it on his computer.<br/><br/>I did an export of my &quot;.cer&quot; file and we ran certmgr.msc on his computer and imported that certificate into his personal store. The certificate has the &quot;all&quot; properties.<br/><br/>Maybe my signing process did not use my certificate to sign it. I don't know.<br/>Is this possible? How do I tell the sign script which certificate to use?<br/><br/>Here is the script I use to sign my scripts:<br/><br/>=== script ==============================================<br/> ## sign-file.ps1<br/> ## Sign a file<br/> param([string] $file=$(throw &quot;Please specify a filename.&quot;))<br/> $cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0]<br/> Set-AuthenticodeSignature $file $cert</p> <p># SIG # Begin signature block<br/>....<br/>=== script =======================================</p>Thu, 02 Jul 2009 22:12:31 Z2009-07-02T22:12:31Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/19880378-d413-4db6-a28f-af7694570d1e#9a0c9ca8-1ea4-4bcc-b460-5d06ec9e6a55http://social.technet.microsoft.com/Forums/en/ITCG/thread/19880378-d413-4db6-a28f-af7694570d1e#9a0c9ca8-1ea4-4bcc-b460-5d06ec9e6a55Grégory Schirohttp://social.technet.microsoft.com/Profile/en-US/?user=Gr%u00e9gory%20SchiroInternal Certificate Chain Error Hi,<br/> <br/> All certificate chain has to be trusted. You need a trusted root certification Authority which generate certificate to all users executing your script.<br/> <br/> Check that the certification autority root certificate is stored in the Trusted Root Store.<hr class="sig">Grégory Schiro - PowerShell MVP - <a href="http://scriptingof.blogspot.com">PowerShell &amp; MOF</a>Fri, 03 Jul 2009 07:48:31 Z2009-07-03T07:48:31Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/19880378-d413-4db6-a28f-af7694570d1e#67ad3cc9-92f3-45ba-927d-01614f317b11http://social.technet.microsoft.com/Forums/en/ITCG/thread/19880378-d413-4db6-a28f-af7694570d1e#67ad3cc9-92f3-45ba-927d-01614f317b11gooolyhttp://social.technet.microsoft.com/Profile/en-US/?user=gooolyInternal Certificate Chain Error Hm, but what about this (my) case?<br /> <br /> # my script folder:<br /> $dir&nbsp;&nbsp; = &quot;C:\Users\cas\Documents\sysTools\Windows PowerShell\prg&quot;<br /> $cert = @(Get-ChildItem cert:\CurrentUser\My -CodeSigning)[0]<br /> <br /> foreach ($scr in Dir -path $dir -filter *.ps1) {<br /> &nbsp;&nbsp;&nbsp; $scr = $dir+&quot;\&quot;+$scr<br /> &nbsp;&nbsp;&nbsp; echo $scr<br /> &nbsp;&nbsp;&nbsp; Set-AuthenticodeSignature $scr $cert<br /> }<br /> ###&nbsp; done&nbsp; ###<br /> this causes one script is valid, tow others have an <strong>unkonwn error</strong> ?<br /> <br /> SignerCertificate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Path&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> -----------------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp;&nbsp; <br /> C:\Users\cas\Documents\sysTools\Windows PowerShell\prg\send-TcpRequest.ps1<br /> B305..B53D20&nbsp; Valid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; send-TcpRequest.ps1&nbsp;&nbsp;&nbsp; <br /> <br /> and a : get-childitem cert:\. -recurse -codesigningcert<br /> <br /> prints to me:<br /> &nbsp;&nbsp;&nbsp; Verzeichnis: Microsoft.PowerShell.Security\Certificate::CurrentUser\My<br /> <br /> <br /> Thumbprint&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Subject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> ----------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> B305..B53D20&nbsp; CN=PowerShell User&nbsp;&nbsp;&nbsp; <br /> The sig has been created by <br /> <br /> So I think my local certificat was found, but why the ____ my scripts aren't sigend?<br />Wed, 07 Oct 2009 13:58:07 Z2009-10-07T13:58:07Z