This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathTest-ValidManifestModule.ps1
More file actions
90 lines (77 loc) · 3.2 KB
/
Test-ValidManifestModule.ps1
File metadata and controls
90 lines (77 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function Test-ValidManifestModule
{
[CmdletBinding()]
[OutputType([bool])]
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$ModuleBasePath,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$ModuleName,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$InstallLocation,
[Parameter()]
[Switch]
$SkipPublisherCheck,
[Parameter()]
[Switch]
$AllowClobber,
[Parameter()]
[Switch]
$IsUpdateOperation
)
Write-Verbose -Message ($LocalizedData.ValidatingTheModule -f $ModuleName,$ModuleBasePath)
$manifestPath = Join-PathUtility -Path $ModuleBasePath -ChildPath "$ModuleName.psd1" -PathType File
$PSModuleInfo = $null
if(-not (Microsoft.PowerShell.Management\Test-Path $manifestPath -PathType Leaf))
{
$message = $LocalizedData.PathNotFound -f ($manifestPath)
ThrowError -ExceptionName 'System.InvalidOperationException' `
-ExceptionMessage $message `
-ErrorId 'PathNotFound' `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidOperation
}
$PSModuleInfo = Microsoft.PowerShell.Core\Test-ModuleManifest -Path $manifestPath -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if(-not $PSModuleInfo)
{
$message = $LocalizedData.InvalidPSModule -f ($moduleName)
ThrowError -ExceptionName 'System.InvalidOperationException' `
-ExceptionMessage $message `
-ErrorId 'InvalidManifestModule' `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidOperation
}
else
{
Write-Verbose -Message ($LocalizedData.ValidatedModuleManifestFile -f $ModuleBasePath)
}
if($script:IsWindows)
{
Write-Verbose -Message ($LocalizedData.ValidateModuleAuthenticodeSignature -f $ModuleName)
$ValidationResult = Validate-ModuleAuthenticodeSignature -CurrentModuleInfo $PSModuleInfo `
-InstallLocation $InstallLocation `
-IsUpdateOperation:$IsUpdateOperation `
-SkipPublisherCheck:$SkipPublisherCheck
if($ValidationResult)
{
# Checking for the possible command clobbering.
Write-Verbose -Message ($LocalizedData.ValidateModuleCommandAlreadyAvailable -f $ModuleName)
$ValidationResult = Validate-ModuleCommandAlreadyAvailable -CurrentModuleInfo $PSModuleInfo `
-InstallLocation $InstallLocation `
-AllowClobber:$AllowClobber `
-IsUpdateOperation:$IsUpdateOperation
}
if(-not $ValidationResult)
{
$PSModuleInfo = $null
}
}
return $PSModuleInfo
}