-
Notifications
You must be signed in to change notification settings - Fork 0
/
Initialize-PSDependFile.ps1
100 lines (89 loc) · 2.08 KB
/
Initialize-PSDependFile.ps1
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
91
92
93
94
95
96
97
98
99
100
<#
.Synopsis
Krótki opis
.DESCRIPTION
Trochę dłuższy opis
.EXAMPLE
(Get-Module dbatools -ListAvailable ).RepositorySourceLocation | Search-PSRepository
.LINK
Author: Mateusz Nadobnik
Link: mnadobnik.pl
Date:
Version: 1.0.0.0
eywords:
Notes:
Changelog:
#>
function Search-PSRepository
{
param(
[Parameter(Mandatory, ValueFromPipeline)]
[System.Uri]$RepositorySourceLocation
)
begin
{
$Repositories = Get-PSRepository
}
process
{
foreach ($Repository in $Repositories)
{
if (($Repository.SourceLocation) -eq $RepositorySourceLocation.OriginalString )
{
#$RepositorySourceLocation
$Repository.Name
}
}
}
}
<#
.EXAMPLE
$FilePath = 'W:\Mateusz\test.module.psd1'
$Exclude = '*VMWare*'
Initialize-PSDependFile -Path $FilePath -Exclude $Exclude
#>
function Initialize-PSDependFile
{
param (
[Parameter(Mandatory)]
[string]$Path,
[Parameter(Mandatory = $false)]
[string[]]$Exclude,
[Parameter(Mandatory = $false)]
[string[]]$Include #do poprawienia
)
begin
{
}
process
{
$Modules = Get-Module -ListAvailable | Where-Object { $_.RepositorySourceLocation -and $_.Name -notlike $Exclude } | Group-Object -Property Name
Foreach ($Module in $Modules)
{
# get the latest module
$LatestModule = ($Modules | Where-Object Name -eq $Module.Name).Group[0]
$PSRepository = $LatestModule.RepositorySourceLocation | Search-PSRepository
$ModuleJson += @"
`t'$($LatestModule.Name)_$($LatestModule.Version)' = @{
`tName = '$($LatestModule.Name)'
`tParameters = @{
`tRepository = '$PSRepository'
`tSkipPublisherCheck = `$true
`t}
`tVersion = '$($LatestModule.Version)'
`t}`n
"@
}
}
end
{
$FullJson = @"
@{
$ModuleJson
}
"@
$FullJson | Out-File -FilePath $Path
# Clear $FullJson
$FullJson = ''
}
}