1
+ <#
2
+ . SYNOPSIS
3
+ Validates signed files. Use this code for manual validation of a folder of nupkg files.
4
+ . DESCRIPTION
5
+ Recursively validates folder for signed files.
6
+ . NOTES
7
+ Use this script to check files for valid signatures before release.
8
+ . EXAMPLE
9
+ .\Validate-SignedNupkg.ps1 -NupkgsPath "C:\MyNupkgs" -ExtractionPath "C:\MyNupkgs\Extracted"
10
+ #>
11
+
12
+ param
13
+ (
14
+ [Parameter (Mandatory = $true )]
15
+ # $NupkgsPath is the path to the folder of .nupkg files.
16
+ [string ] $NupkgsPath ,
17
+ [Parameter (Mandatory = $false )]
18
+ # $ExtractionPath is the path to extract each nupkg folders separately to. Extracts to $NupkgsPath by default.
19
+ [string ] $ExtractionPath = [System.IO.Path ]::Combine($PSScriptRoot , " extracted" )
20
+ )
21
+
22
+ # ##########
23
+ # EXTRACT
24
+ # ##########
25
+ $nupkgs = Get-ChildItem - Path $nupkgPath - Filter * .nupkg
26
+ $nupkgs | Out-String
27
+
28
+ New-Item - Path $extractionPath - ItemType Directory - Force
29
+
30
+ $nupkgs | ForEach-Object {Expand-Archive - Path $_.FullName - DestinationPath $ ([System.IO.Path ]::Combine($extractionPath , $_.BaseName )) - Force}
31
+ Write-Host - Message " Extracted nupkg modules to ${extractionPath} ."
32
+
33
+ # ##########
34
+ # VALIDATE
35
+ # ##########
36
+
37
+ # Add string of file name to $exclude hashtable to exclude specific files.
38
+ $exclude = @ ()
39
+ $fileInfos = Get-ChildItem - Path $extractionPath - File - Recurse `
40
+ | Where-Object { $_.Name -notin $exclude } `
41
+ | Where-Object { $_.Extension -in @ (' .dll' , ' .exe' , ' .msi' , ' .cab' , ' .ps1' , ' .psm1' , ' .psd1' , ' .pssc' , ' .ps1xml' ) }
42
+
43
+ $filePaths = $fileInfos | ForEach-Object {$_.FullName }
44
+ Write-Host " Scanning files:`n "
45
+ $filePaths | Out-String
46
+
47
+ $authenticodeStatuses = $filePaths | Get-AuthenticodeSignature
48
+ Write-Host " Statuses of files in the folder ${extractionPath} :`n "
49
+ $authenticodeStatuses | Select-Object - Property Status, Path | Out-String - width 4096
50
+
51
+ $unsignedFiles = $authenticodeStatuses | Where-Object {$_.Status -eq [System.Management.Automation.SignatureStatus ]::NotSigned}
52
+ $unsignedFilesFormatted = $unsignedFiles | Select-Object - Property Status, Path | Out-String
53
+
54
+ if ($unsignedFiles )
55
+ {
56
+ Write-Host " ERROR: These files in ${extractionPath} are unsigned:"
57
+ $unsignedFilesFormatted | Out-String - width 4096
58
+ throw " ERROR: The module contains unsigned files."
59
+ }
0 commit comments