Signature Authenticode

De NCad Wiki
Version datée du 1 septembre 2025 à 15:43 par Cacheln (discussion | contributions) (Page créée avec « = Présentation = La '''signature Authenticode''' permet d'apposer une signature sur un fichier ou un script. Dans un contexte d'exécution de '''scripts PowerShell''', on peut restreindre l'exécution uniquement à du code signé. = Signer un script = == Signer un script PowerShell == * L'exemple suivant permet de signer le '''script PowerShell''' nommé '''MonScriptPowerShell.ps1''' : $cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert Set-... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à la navigation Aller à la recherche

Présentation

La signature Authenticode permet d'apposer une signature sur un fichier ou un script. Dans un contexte d'exécution de scripts PowerShell, on peut restreindre l'exécution uniquement à du code signé.

Signer un script

Signer un script PowerShell

  • L'exemple suivant permet de signer le script PowerShell nommé MonScriptPowerShell.ps1 :
$cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
Set-AuthenticodeSignature -FilePath MonScriptPowerShell.ps1 -Certificate $cert

Signer plusieurs scripts PowerShell

  • L'exemple suivant permet de signer l'ensemble des scripts PowerShell contenu dans le répertoire C:\MES_SCRIPTS :
$PathScriptToSign = "C:\MES_SCRIPTS\"
$CertCodeSigning = Get-ChildItem Cert:\CurrentUser\My\ -CodeSigningCert

$ListScripts = Get-ChildItem -Path $PathScriptToSign -Name -Include *.ps1

foreach ($line in $ListScripts)
{
   Set-AuthenticodeSignature "$PathScriptToSign$line" -Certificate $CertCodeSigning
}