Étape 5: Enfin signer votre script powershell
Votre script powershell peut être n’importe où, même sur un partage réseau.
- Lancer une fenêtre DOS et naviguez jusqu’au dossier où se trouve votre script powershell.
- Type de powershell
- Puis tapez cette commande pour voir si le certificat utilisateur n’est visible
PS D:\> dir cert:CurrentUser\My -CodeSigningCert Directory: Microsoft.PowerShell.Security\Certificate::CurrentUser\MyThumbprint Subject ---------- ------- 0416C2888A4BD94547FB24D5891A7A48930C489F CN=localhostPS D:\>
- Maintenant signer votre script powershell, dans mon cas « test.ps1 » avec echo « Hello world »
$cert=(dir cert:currentuser\my\ -CodeSigningCert)Set-AuthenticodeSignature test.ps1 $cert Directory: D:\PowershellSignerCertificate Status Path----------------- ------ ----33875C...D1F7A81A6415E72695421 Valid test.ps1
Si le statut n’est pas valide, tapez ceci pour voir quel est le problème (sortie ici tronquée).
Get-AuthenticodeSignature test.ps1 | fl *StatusMessage : Signature verified.
- Exécutez le script powershell en tapant dans le DOS-box sur la ligne de PS :
.\test1.ps
La première fois, vous obtiendrez un avertissement, réponse A pour toujours exécuter.