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 pathSet-ModuleSourcesVariable.ps1
More file actions
67 lines (56 loc) · 3.38 KB
/
Set-ModuleSourcesVariable.ps1
File metadata and controls
67 lines (56 loc) · 3.38 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
function Set-ModuleSourcesVariable
{
[CmdletBinding()]
param(
[switch]
$Force,
$Proxy,
$ProxyCredential
)
if(-not $script:PSGetModuleSources -or $Force)
{
$isPersistRequired = $false
if(Microsoft.PowerShell.Management\Test-Path $script:PSGetModuleSourcesFilePath)
{
$script:PSGetModuleSources = DeSerialize-PSObject -Path $script:PSGetModuleSourcesFilePath
}
else
{
$script:PSGetModuleSources = [ordered]@{}
if(-not $script:PSGetModuleSources.Contains($Script:PSGalleryModuleSource))
{
$null = Set-PSGalleryRepository -Proxy $Proxy -ProxyCredential $ProxyCredential
}
}
# Already registered repositories may not have the ScriptSourceLocation property, try to populate it from the existing SourceLocation
# Also populate the PublishLocation and ScriptPublishLocation from the SourceLocation if PublishLocation is empty/null.
#
$script:PSGetModuleSources.Keys | Microsoft.PowerShell.Core\ForEach-Object {
$moduleSource = $script:PSGetModuleSources[$_]
if(-not (Get-Member -InputObject $moduleSource -Name $script:ScriptSourceLocation))
{
$scriptSourceLocation = Get-ScriptSourceLocation -Location $moduleSource.SourceLocation -Proxy $Proxy -ProxyCredential $ProxyCredential
Microsoft.PowerShell.Utility\Add-Member -InputObject $script:PSGetModuleSources[$_] `
-MemberType NoteProperty `
-Name $script:ScriptSourceLocation `
-Value $scriptSourceLocation
if(Get-Member -InputObject $moduleSource -Name $script:PublishLocation)
{
if(-not $moduleSource.PublishLocation)
{
$script:PSGetModuleSources[$_].PublishLocation = Get-PublishLocation -Location $moduleSource.SourceLocation
}
Microsoft.PowerShell.Utility\Add-Member -InputObject $script:PSGetModuleSources[$_] `
-MemberType NoteProperty `
-Name $script:ScriptPublishLocation `
-Value $moduleSource.PublishLocation
}
$isPersistRequired = $true
}
}
if($isPersistRequired)
{
Save-ModuleSources
}
}
}