powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Set-AuthenticodeSignature



NAME
Set-AuthenticodeSignature

SYNOPSIS
Adds an Authenticode signature to a Windows PowerShell script or other file.

SYNTAX
Set-AuthenticodeSignature [-FilePath] [-Certificate] [-Force] [-HashAlgorithm >] [-IncludeChain ] [-TimestampServer ] [-Confirm] [-WhatIf] []


DESCRIPTION
The Set-AuthenticodeSignature cmdlet adds an Authenticode signature to any file that supports Subject Interface Pac
kage (SIP).

In a Windows PowerShell script file, the signature takes the form of a block of text that indicates the end of the
instructions that are executed in the script. If there is a signature in the file when this cmdlet runs, that signa
ture is removed.


PARAMETERS
-Certificate
Specifies the certificate that will be used to sign the script or file. Enter a variable that stores an object
representing the certificate or an expression that gets the certificate.

To find a certificate, use Get-PfxCertificate or use the Get-ChildItem cmdlet in the Certificate (Cert:) drive.
If the certificate is not valid or does not have code-signing authority, the command fails.

Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false

-FilePath
Specifies the path to a file that is being signed.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-Force []
Allows the cmdlet to append a signature to a read-only file. Even using the Force parameter, the cmdlet cannot
override security restrictions.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-HashAlgorithm
Specifies the hashing algorithm that Windows uses to compute the digital signature for the file. The default is
SHA1, which is the Windows default hashing algorithm.

Files that are signed with a different hashing algorithm might not be recognized on other systems.

Required? false
Position? named
Default value SHA1
Accept pipeline input? false
Accept wildcard characters? false

-IncludeChain
Determines which certificates in the certificate trust chain are included in the digital signature. "NotRoot" i
s the default.

Valid values are:

-- Signer: Includes only the signer's certificate.

-- NotRoot: Includes all of the certificates in the certificate chain, except for the root authority.

--All: Includes all the certificates in the certificate chain.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-TimestampServer
Uses the specified time stamp server to add a time stamp to the signature. Type the URL of the time stamp serve
r as a string.

The time stamp represents the exact time that the certificate was added to the file. A time stamp prevents the
script from failing if the certificate expires because users and programs can verify that the certificate was v
alid at the time of signing.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm []
Prompts you for confirmation before executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf []
Describes what would happen if you executed the command without actually executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.String
You can pipe a string that contains the file path to Set-AuthenticodeSignature.


OUTPUTS
System.Management.Automation.Signature



NOTES





-------------------------- EXAMPLE 1 --------------------------

C:\PS>$cert=Get-ChildItem -Path cert:\CurrentUser\my -CodeSigningCert

C:\PS>Set-AuthenticodeSignature -FilePath PsTestInternet2.ps1 -certificate $cert


Description
-----------
These commands retrieve a code-signing certificate from the Windows PowerShell certificate provider and use it to s
ign a Windows PowerShell script.

The first command uses the Get-ChildItem cmdlet and the Windows PowerShell certificate provider to get the certific
ates in the Cert:\CurrentUser\My subdirectory of the certificate store. (The Cert: drive is the drive exposed by th
e certificate provider.) The CodeSigningCert parameter, which is supported only by the certificate provider, limits
the certificates retrieved to those with code-signing authority. The command stores the result in the $cert variab
le.

The second command uses the Set-AuthenticodeSignature cmdlet to sign the PSTestInternet2.ps1 script. It uses the Fi
lePath parameter to specify the name of the script and the Certificate parameter to specify that the certificate is
stored in the $cert variable.





-------------------------- EXAMPLE 2 --------------------------

C:\PS>$cert = Get-PfxCertificate C:\Test\Mysign.pfx

C:\PS>Set-AuthenticodeSignature -Filepath ServerProps.ps1 -Cert $cert


Description
-----------
These commands use the Get-PfxCertificate cmdlet to find a code signing certificate. Then, they use it to sign a Wi
ndows PowerShell script.

The first command uses the Get-PfxCertificate cmdlet to find the C:\Test\MySign.pfx certificate and store it in the
$cert variable.

The second command uses Set-AuthenticodeSignature to sign the script. The FilePath parameter of Set-AuthenticodeSig
nature specifies the path to the script file being signed and the Cert parameter passes the $cert variable containi
ng the certificate to Set-AuthenticodeSignature.

If the certificate file is password protected, Windows PowerShell prompts you for the password.





-------------------------- EXAMPLE 3 --------------------------

C:\PS>Set-AuthenticodeSignature -filepath c:\scripts\Remodel.ps1 -certificate $cert -IncludeChain All -TimeStampSer
ver "http://timestamp.fabrikam.com/scripts/timstamper.dll"


Description
-----------
This command adds a digital signature that includes the root authority in the trust chain, and it is signed by a th
ird-party timestamp server.

The command uses the FilePath parameter to specify the script being signed and the Certificate parameter to specify
the certificate that is saved in the $cert variable. It uses the IncludeChain parameter to include all of the sign
atures in the trust chain (including the root authority). It also uses the TimeStampServer parameter to add a times
tamp to the signature. This prevents the script from failing when the certificate expires.






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113391
about_Signing
about_Execution_Policies
Get-AuthenticodeSignature
Get-PfxCertificate
Get-ExecutionPolicy
Set-ExecutionPolicy