-
Notifications
You must be signed in to change notification settings - Fork 42
/
configure-powershell.ps1
executable file
·68 lines (57 loc) · 1.8 KB
/
configure-powershell.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
#!/usr/bin/env pwsh
#region functions
function Write-Log {
param( [string] $msg)
"$(Get-Date -Format FileDateTimeUniversal) : $msg" | Write-Host
}
function Exit-WithError {
param( [string]$msg )
Write-Log "There was an exception during the process, please review..."
Write-Log $msg
Exit 2
}
#endregion
#region main
# Install PowerShell prerequisites
$nugetPackage = Get-PackageProvider | Where-Object Name -eq 'NuGet'
if ($null -eq $nugetPackage) {
Write-Log "Installing NuGet PowerShell package provider..."
try {
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
}
catch {
Exit-WithError $_
}
}
$nugetPackage = Get-PackageProvider | Where-Object Name -eq 'NuGet'
Write-Log "NuGet Powershell Package Provider version $($nugetPackage.Version.Major).$($nugetPackage.Version.Minor).$($nugetPackage.Version.Build).$($nugetPackage.Version.Revision) is already installed..."
$repo = Get-PSRepository -Name PSGallery
if ( $repo.InstallationPolicy -eq 'Trusted' ) {
Write-Log "PSGallery installation policy is already set to 'Trusted'..."
}
else {
Write-Log "Setting PSGallery installation policy to 'Trusted'..."
try {
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
}
catch {
Exit-WithError $_
}
}
$azModule = Get-Module -ListAvailable -Name Az*
if ($null -eq $azModule ) {
Write-Log "Installing PowerShell Az module..."
try {
Install-Module -Name Az -AllowClobber -Scope AllUsers
}
catch {
Exit-WithError $_
}
}
else {
Write-Log "PowerShell Az module is already installed..."
}
$azAutomationModule = Get-Module -ListAvailable -Name Az.Automation
Write-Log "PowerShell Az.Automation version $($azAutomationModule.Version) is installed..."
Exit 0
#endregion