|
2 | 2 | # Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. |
3 | 3 | # ------------------------------------------------------------------------------ |
4 | 4 |
|
| 5 | +[CmdletBinding()] |
5 | 6 | [CmdletBinding()] |
6 | 7 | param( |
7 | 8 | # The name of the module to install dependencies for. The module name should match the folder name in the module folder. If not provided, the script will default to 'Entra'. |
8 | 9 | [ArgumentCompleter({ (Get-ChildItem -Path "$PSScriptRoot\..\module").Name })] |
9 | 10 | [string] |
10 | 11 | $ModuleName = 'Entra', |
| 12 | + # The name of the module to install dependencies for. The module name should match the folder name in the module folder. If not provided, the script will default to 'Entra'. |
| 13 | + [ArgumentCompleter({ (Get-ChildItem -Path "$PSScriptRoot\..\module").Name })] |
| 14 | + [string] |
| 15 | + $ModuleName = 'Entra', |
11 | 16 |
|
12 | 17 | # Path to the ModuleSettings.json file. If not provided, the script will look for the file in the module folder. |
13 | 18 | [ValidateScript({ Test-Path $_ })] |
@@ -74,56 +79,56 @@ foreach ($DestinationModuleName in $ModuleSettings.destinationModuleName) { |
74 | 79 | } catch { |
75 | 80 | Write-Warning "Failed to update module '$DestinationModuleName' to version ${RequiredVersion}. Error: $_" |
76 | 81 | } |
77 | | -======= |
78 | | -try { |
79 | | - # Review: are the common functions required for this script? There does not seem to be any dependencies on them [yet?]. |
80 | | - . "$PSScriptRoot/common-functions.ps1" |
81 | | -} catch { |
82 | | - Write-Error -Message "Failed to load common-functions.ps1. Error: $_" -RecommendedAction "This script should be run from the 'build' folder. Ensure 'common-functions.ps1' exists and is accessible." |
83 | | -} |
| 82 | + ======= |
| 83 | + try { |
| 84 | + # Review: are the common functions required for this script? There does not seem to be any dependencies on them [yet?]. |
| 85 | + . "$PSScriptRoot/common-functions.ps1" |
| 86 | + } catch { |
| 87 | + Write-Error -Message "Failed to load common-functions.ps1. Error: $_" -RecommendedAction "This script should be run from the 'build' folder. Ensure 'common-functions.ps1' exists and is accessible." |
| 88 | + } |
84 | 89 |
|
85 | | -# Get module settings from the relevant ModuleSettings.json file. |
86 | | -if ($ModuleSettingsPath) { |
87 | | - $SettingsPath = $ModuleSettingsPath |
88 | | -} else { |
89 | | - $SettingsPath = "$PSScriptRoot/../module/$ModuleName/config/ModuleSettings.json" |
90 | | -} |
91 | | -$ModuleSettings = Get-Content -Path $SettingsPath | ConvertFrom-Json |
92 | | -$RequiredVersion = $ModuleSettings.destinationModuleVersion |
| 90 | + # Get module settings from the relevant ModuleSettings.json file. |
| 91 | + if ($ModuleSettingsPath) { |
| 92 | + $SettingsPath = $ModuleSettingsPath |
| 93 | + } else { |
| 94 | + $SettingsPath = "$PSScriptRoot/../module/$ModuleName/config/ModuleSettings.json" |
| 95 | + } |
| 96 | + $ModuleSettings = Get-Content -Path $SettingsPath | ConvertFrom-Json |
| 97 | + $RequiredVersion = $ModuleSettings.destinationModuleVersion |
93 | 98 |
|
94 | | -# Do not check for installed modules if -Force is specified. |
95 | | -if ($Force) { |
96 | | - Write-Verbose 'Skipping the check for installed prerequisites. Forcing the installation of all required modules.' |
97 | | -} else { |
98 | | - Write-Verbose 'Checking installed modules for required dependencies.' |
99 | | - $InstalledModules = Get-Module -ListAvailable -Verbose:$false | Group-Object -Property Name |
100 | | -} |
| 99 | + # Do not check for installed modules if -Force is specified. |
| 100 | + if ($Force) { |
| 101 | + Write-Verbose 'Skipping the check for installed prerequisites. Forcing the installation of all required modules.' |
| 102 | + } else { |
| 103 | + Write-Verbose 'Checking installed modules for required dependencies.' |
| 104 | + $InstalledModules = Get-Module -ListAvailable -Verbose:$false | Group-Object -Property Name |
| 105 | + } |
101 | 106 |
|
102 | | -# Install the AzureAD module. |
103 | | -$SourceModule = $ModuleSettings.sourceModule |
104 | | -if (($InstalledModules.Name -contains $SourceModule) -and -not $Force) { |
105 | | - Write-Verbose "The $SourceModule module is already installed." |
106 | | -} else { |
107 | | - Write-Verbose("Installing Module: $sourceModule") |
108 | | - try { |
109 | | - Install-Module $sourceModule -Scope CurrentUser -Force -AllowClobber |
110 | | - } catch { |
111 | | - Write-Error "Failed to install the $sourceModule module. Error: $_" |
112 | | - } |
113 | | -} |
| 107 | + # Install the AzureAD module. |
| 108 | + $SourceModule = $ModuleSettings.sourceModule |
| 109 | + if (($InstalledModules.Name -contains $SourceModule) -and -not $Force) { |
| 110 | + Write-Verbose "The $SourceModule module is already installed." |
| 111 | + } else { |
| 112 | + Write-Verbose("Installing Module: $sourceModule") |
| 113 | + try { |
| 114 | + Install-Module $sourceModule -Scope CurrentUser -Force -AllowClobber |
| 115 | + } catch { |
| 116 | + Write-Error "Failed to install the $sourceModule module. Error: $_" |
| 117 | + } |
| 118 | + } |
114 | 119 |
|
115 | | -# Install the required module dependencies if missing the required version or if -Force. |
116 | | -foreach ($moduleName in $ModuleSettings.destinationModuleName) { |
117 | | - $InstalledModuleReference = $InstalledModules.Where({ $_.Name -eq $moduleName }) |
118 | | - if (-not $InstalledModuleReference -or $Force) { |
119 | | - Write-Verbose "Installing version $RequiredVersion of $moduleName" |
120 | | - try { |
121 | | - Install-Module $moduleName -Scope CurrentUser -RequiredVersion $RequiredVersion -Force -AllowClobber |
122 | | - } catch { |
123 | | - Write-Error "Failed to install module $moduleName ${RequiredVersion}. Error: $_" |
| 120 | + # Install the required module dependencies if missing the required version or if -Force. |
| 121 | + foreach ($moduleName in $ModuleSettings.destinationModuleName) { |
| 122 | + $InstalledModuleReference = $InstalledModules.Where({ $_.Name -eq $moduleName }) |
| 123 | + if (-not $InstalledModuleReference -or $Force) { |
| 124 | + Write-Verbose "Installing version $RequiredVersion of $moduleName" |
| 125 | + try { |
| 126 | + Install-Module $moduleName -Scope CurrentUser -RequiredVersion $RequiredVersion -Force -AllowClobber |
| 127 | + } catch { |
| 128 | + Write-Error "Failed to install module $moduleName ${RequiredVersion}. Error: $_" |
| 129 | + } |
| 130 | + } elseif ($InstalledModuleReference.Group.Version -contains $RequiredVersion) { |
| 131 | + Write-Verbose "Found version $RequiredVersion of $moduleName" |
| 132 | + >>>>>(Add version checks and error handling.) |
| 133 | + } |
124 | 134 | } |
125 | | - } elseif ($InstalledModuleReference.Group.Version -contains $RequiredVersion) { |
126 | | - Write-Verbose "Found version $RequiredVersion of $moduleName" |
127 | | ->>>>>>> 48ba4e296 (Add version checks and error handling.) |
128 | | - } |
129 | | -} |
|
0 commit comments