22external help file : Microsoft.PowerShell.Security.dll-Help.xml
33Locale : en-US
44Module Name : Microsoft.PowerShell.Security
5- ms.date : 12/12/2022
5+ ms.date : 03/07/2025
66online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.security/set-authenticodesignature?view=powershell-7.4&WT.mc_id=ps-gethelp
77schema : 2.0.0
88title : Set-AuthenticodeSignature
@@ -11,8 +11,7 @@ title: Set-AuthenticodeSignature
1111# Set-AuthenticodeSignature
1212
1313## SYNOPSIS
14- Adds an [ Authenticode] ( /windows-hardware/drivers/install/authenticode ) signature to a PowerShell
15- script or other file.
14+ Adds an Authenticode signature to a PowerShell script or other file.
1615
1716## SYNTAX
1817
@@ -36,8 +35,8 @@ Set-AuthenticodeSignature [-Certificate] <X509Certificate2> [-IncludeChain <Stri
3635
3736```
3837Set-AuthenticodeSignature [-Certificate] <X509Certificate2> [-IncludeChain <String>]
39- [-TimestampServer <String>] [-HashAlgorithm <String>] [-Force] -SourcePathOrExtension <String[]>
40- -Content <Byte[]> [-WhatIf] [-Confirm] [<CommonParameters>]
38+ [-TimestampServer <String>] [-HashAlgorithm <String>] [-Force] -SourcePathOrExtension
39+ <String[]> -Content <Byte[]> [-WhatIf] [-Confirm] [<CommonParameters>]
4140```
4241
4342## DESCRIPTION
@@ -59,7 +58,7 @@ These commands retrieve a code-signing certificate from the PowerShell certifica
5958it to sign a PowerShell script.
6059
6160``` powershell
62- $cert= Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
61+ $cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
6362Set-AuthenticodeSignature -FilePath PsTestInternet2.ps1 -Certificate $cert
6463```
6564
@@ -76,7 +75,7 @@ parameter to specify that the certificate is stored in the `$cert` variable.
7675> [ !NOTE]
7776> Using the ** CodeSigningCert** parameter with ` Get-ChildItem ` only returns certificates that have
7877> code-signing authority and contain a private key. If there is no private key, the certificates
79- > cannot be used for signing.
78+ > can't be used for signing.
8079
8180### Example 2 - Sign a script using a certificate from a PFX file
8281
@@ -88,7 +87,7 @@ $cert = Get-PfxCertificate -FilePath C:\Test\Mysign.pfx
8887Set-AuthenticodeSignature -FilePath ServerProps.ps1 -Certificate $cert
8988```
9089
91- The first command uses the ` Get-PfxCertificate ` cmdlet to load the C:\Test\MySign.pfx certificate
90+ The first command uses the ` Get-PfxCertificate ` cmdlet to load the ` C:\Test\MySign.pfx ` certificate
9291into the ` $cert ` variable.
9392
9493The second command uses ` Set-AuthenticodeSignature ` to sign the script. The ** FilePath** parameter
@@ -99,15 +98,22 @@ If the certificate file is password protected, PowerShell prompts you for the pa
9998
10099### Example 3 - Add a signature that includes the root authority
101100
102- This command adds a digital signature that includes the root authority in the trust chain, and it is
101+ This command adds a digital signature that includes the root authority in the trust chain, and it's
103102signed by a third-party timestamp server.
104103
105104``` powershell
106- Set-AuthenticodeSignature -FilePath c:\scripts\Remodel.ps1 -Certificate $cert -IncludeChain All -TimestampServer "https://timestamp.fabrikam.com/scripts/timstamper.dll"
105+ $signingParameters = @{
106+ FilePath = 'C:\scripts\Remodel.ps1'
107+ Certificate = $cert
108+ HashAlgorithm = 'SHA256'
109+ IncludeChain = 'All'
110+ TimestampServer = 'http://timestamp.fabrikam.com/scripts/timstamper.dll'
111+ }
112+ Set-AuthenticodeSignature @signingParameters
107113```
108114
109115The command uses the ** FilePath** parameter to specify the script being signed and the
110- ** Certificate** parameter to specify the certificate that is saved in the ` $cert ` variable. It uses
116+ ** Certificate** parameter to specify the certificate that's saved in the ` $cert ` variable. It uses
111117the ** IncludeChain** parameter to include all of the signatures in the trust chain, including the
112118root authority. It also uses the ** TimeStampServer** parameter to add a timestamp to the signature.
113119This prevents the script from failing when the certificate expires.
@@ -120,8 +126,8 @@ Specifies the certificate that will be used to sign the script or file. Enter a
120126an object representing the certificate or an expression that gets the certificate.
121127
122128To find a certificate, use ` Get-PfxCertificate ` or use the ` Get-ChildItem ` cmdlet in the Certificate
123- ` Cert: ` drive. If the certificate is not valid or does not have ` code-signing ` authority, the
124- command fails.
129+ ` Cert: ` drive. If the certificate isn't valid or doesn't have ` code-signing ` authority, the command
130+ fails.
125131
126132``` yaml
127133Type : System.Security.Cryptography.X509Certificates.X509Certificate2
@@ -137,8 +143,8 @@ Accept wildcard characters: False
137143
138144### -Content
139145
140- This parameter appears in the syntax listing because it is defined in the base class that
141- ` Set-AuthenticodeSignature` is derived from. However, support for this parameter is not implemented
146+ This parameter appears in the syntax listing because it's defined in the base class that
147+ ` Set-AuthenticodeSignature` is derived from. However, support for this parameter isn't implemented
142148in `Set-AuthenticodeSignature`.
143149
144150` ` ` yaml
@@ -155,7 +161,7 @@ Accept wildcard characters: False
155161
156162# ## -FilePath
157163
158- Specifies the path to a file that is being signed.
164+ Specifies the path to a file that's being signed.
159165
160166` ` ` yaml
161167Type: System.String[]
@@ -172,7 +178,7 @@ Accept wildcard characters: False
172178# ## -Force
173179
174180Allows the cmdlet to append a signature to a read-only file. Even using the **Force** parameter, the
175- cmdlet cannot override security restrictions.
181+ cmdlet can't override security restrictions.
176182
177183` ` ` yaml
178184Type: System.Management.Automation.SwitchParameter
@@ -195,7 +201,8 @@ earlier versions, the default is SHA1. Files that are signed with a different ha
195201might not be recognized on other systems. Which algorithms are supported depends on the version of
196202the operating system.
197203
198- For a list of possible values, see [HashAlgorithmName Struct](/dotnet/api/system.security.cryptography.hashalgorithmname?view=netframework-4.7.2#properties).
204+ For a list of possible values, see
205+ [HashAlgorithmName](xref:System.Security.Cryptography.HashAlgorithmName#properties) struct.
199206
200207` ` ` yaml
201208Type: System.String
@@ -216,9 +223,10 @@ Determines which certificates in the certificate trust chain are included in the
216223
217224Valid values are :
218225
219- - Signer : Includes only the signer's certificate.
220- - NotRoot : Includes all of the certificates in the certificate chain, except for the root authority.
221- - All : Includes all the certificates in the certificate chain.
226+ - `Signer` : Includes only the signer's certificate.
227+ - `NotRoot` : Includes all of the certificates in the certificate chain, except for the root
228+ authority.
229+ - `All` : Includes all the certificates in the certificate chain.
222230
223231` ` ` yaml
224232Type: System.String
@@ -234,15 +242,15 @@ Accept wildcard characters: False
234242
235243# ## -LiteralPath
236244
237- Specifies the path to a file that is being signed. Unlike **FilePath**, the value of the
238- **LiteralPath** parameter is used exactly as it is typed. No characters are interpreted as
245+ Specifies the path to a file that's being signed. Unlike **FilePath**, the value of the
246+ **LiteralPath** parameter is used exactly as it's typed. No characters are interpreted as
239247wildcards. If the path includes escape characters, enclose it in single quotation marks. Single
240248quotation marks tell PowerShell not to interpret any characters as escape sequences.
241249
242250` ` ` yaml
243251Type: System.String[]
244252Parameter Sets: ByLiteralPath
245- Aliases: PSPath
253+ Aliases: PSPath, LP
246254
247255Required: True
248256Position: Named
@@ -253,8 +261,8 @@ Accept wildcard characters: False
253261
254262# ## -SourcePathOrExtension
255263
256- This parameter appears in the syntax listing because it is defined in the base class that
257- ` Set-AuthenticodeSignature` is derived from. However, support for this parameter is not implemented
264+ This parameter appears in the syntax listing because it's defined in the base class that
265+ ` Set-AuthenticodeSignature` is derived from. However, support for this parameter isn't implemented
258266in `Set-AuthenticodeSignature`.
259267
260268` ` ` yaml
@@ -272,12 +280,18 @@ Accept wildcard characters: False
272280# ## -TimestampServer
273281
274282Uses the specified time stamp server to add a time stamp to the signature. Type the URL of the time
275- stamp server as a string. The URL must start with `https://` or ` http://`.
283+ stamp server as a string. The URL must start with `http://`.
276284
277285The time stamp represents the exact time that the certificate was added to the file. A time stamp
278286prevents the script from failing if the certificate expires because users and programs can verify
279287that the certificate was valid at the time of signing.
280288
289+ > [!NOTE]
290+ > PowerShell 7.3 added support for `https://` URLs with this parameter. However, the underlying API
291+ > doesn't support HTTPS. If you use HTTPS, the command returns an error, but the file is signed
292+ > without a time stamp. For more information, see
293+ > [Issue # 25130](https://github.com/PowerShell/PowerShell/issues/25130).
294+
281295` ` ` yaml
282296Type: System.String
283297Parameter Sets: (All)
@@ -308,7 +322,7 @@ Accept wildcard characters: False
308322
309323# ## -WhatIf
310324
311- Shows what would happen if the cmdlet runs. The cmdlet is not run.
325+ Shows what would happen if the cmdlet runs. The cmdlet isn't run.
312326
313327` ` ` yaml
314328Type: System.Management.Automation.SwitchParameter
@@ -347,6 +361,8 @@ This cmdlet is only available on Windows platforms.
347361
348362# # RELATED LINKS
349363
364+ [Authenticode](/windows-hardware/drivers/install/authenticode)
365+
350366[Get-AuthenticodeSignature](Get-AuthenticodeSignature.md)
351367
352368[Get-ExecutionPolicy](Get-ExecutionPolicy.md)
0 commit comments