6
6
# ---------------------------------------------------------[Initialisations]--------------------------------------------------------
7
7
8
8
# region Initialisations
9
+
9
10
$ProgressPreference = " SilentlyContinue"
10
11
$ErrorActionPreference = " SilentlyContinue"
11
12
# Set the script execution policy for this process
@@ -78,24 +79,33 @@ Function Get-ScriptName
78
79
}
79
80
}
80
81
}
82
+
83
+ Function Initialize-Module
81
84
{
85
+ <#
86
+ . SYNOPSIS
87
+ Initialize-Module install and import modules from PowerShell Galllery.
88
+ . OUTPUTS
89
+ System.String
90
+ #>
82
91
[CmdletBinding ()]
83
92
Param
84
93
(
85
94
[Parameter (Mandatory = $true )]
86
95
[string ]$Module
87
96
)
88
- Write-Host - Object " Importing $Module module..." - ForegroundColor Green
97
+ Write-Host - Object " Importing $Module module..." - ForegroundColor Green
89
98
90
99
# If module is imported say that and do nothing
91
- If (Get-Module | Where-Object {$_.Name -eq $Module })
100
+ If (Get-Module | Where-Object { $_.Name -eq $Module })
92
101
{
93
- Write-Host - Object " Module $Module is already imported." - ForegroundColor Green
102
+ Write-Host - Object " Module $Module is already imported." - ForegroundColor Green
94
103
}
95
104
Else
96
105
{
97
106
# If module is not imported, but available on disk then import
98
- If (Get-Module - ListAvailable | Where-Object {$_.Name -eq $Module })
107
+ If ( [boolean ](Get-Module - ListAvailable | Where-Object { $_.Name -eq $Module }) )
108
+
99
109
{
100
110
$InstalledModuleVersion = (Get-InstalledModule - Name $Module ).Version
101
111
$ModuleVersion = (Find-Module - Name $Module ).Version
@@ -136,7 +146,7 @@ Function Get-ScriptName
136
146
}
137
147
138
148
# If module is not imported, not available on disk, but is in online gallery then install and import
139
- If (Find-Module - Name $Module | Where-Object {$_.Name -eq $Module })
149
+ If (Find-Module - Name $Module | Where-Object { $_.Name -eq $Module })
140
150
{
141
151
# Install and import module
142
152
Install-Module - Name $Module - AllowClobber - Force - Scope AllUsers
@@ -161,6 +171,7 @@ Foreach ($Module in $Modules)
161
171
{
162
172
Initialize-Module - Module $Module
163
173
}
174
+
164
175
# endregion
165
176
166
177
# -----------------------------------------------------------[Functions]------------------------------------------------------------
0 commit comments