Skip to content

Commit d714111

Browse files
committed
feat: support allusers scope
1 parent 5392dbb commit d714111

1 file changed

Lines changed: 33 additions & 14 deletions

File tree

src/ALZ/Private/Tools/Test-Tooling.ps1

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,22 @@ function Test-Tooling {
157157
}
158158
}
159159

160+
$currentScope = "CurrentUser"
161+
160162
if($skipAlzModuleVersionCheck.IsPresent) {
161163
Write-Verbose "Skipping ALZ module version check"
162164
} else {
163165
# Check if latest ALZ module is installed
164166
Write-Verbose "Checking ALZ module version"
165-
$alzModuleCurrentVersion = Get-InstalledPSResource -Name ALZ | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
167+
$alzModuleCurrentVersion = Get-InstalledPSResource -Name ALZ 2>$null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
168+
if($null -eq $alzModuleCurrentVersion) {
169+
Write-Verbose "ALZ module not found in CurrentUser scope, checking AllUsers scope"
170+
$alzModuleCurrentVersion = Get-InstalledPSResource -Name ALZ -Scope AllUsers 2>$null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
171+
if($null -ne $alzModuleCurrentVersion) {
172+
Write-Verbose "ALZ module found in AllUsers scope"
173+
$currentScope = "AllUsers"
174+
}
175+
}
166176

167177
if($null -eq $alzModuleCurrentVersion) {
168178
$checkResults += @{
@@ -191,31 +201,40 @@ function Test-Tooling {
191201
# Check if powershell-yaml module is installed (only when YAML files are being used)
192202
if ($checkYamlModule.IsPresent) {
193203
Write-Verbose "Checking powershell-yaml module installation"
194-
$yamlModule = Get-InstalledPSResource -Name powershell-yaml 2> $null
204+
$yamlModule = Get-InstalledPSResource -Name powershell-yaml 2> $null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
205+
if($null -eq $yamlModule) {
206+
Write-Verbose "powershell-yaml module not found in CurrentUser scope, checking AllUsers scope"
207+
$yamlModule = Get-InstalledPSResource -Name powershell-yaml -Scope AllUsers 2> $null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
208+
}
209+
195210
if ($yamlModule) {
196211
$checkResults += @{
197212
message = "powershell-yaml module is installed (version $($yamlModule.Version))."
198213
result = "Success"
199214
}
200215
} else {
201-
$installSuccessful = $false
202-
try {
203-
Install-PSResource powershell-yaml -TrustRepository
204-
$installSuccessful = $true
205-
} catch {
206-
Write-Verbose "Failed to install powershell-yaml module"
207-
}
208-
if($installSuccessful) {
216+
Write-Verbose "powershell-yaml module is not installed, attempting installation"
217+
$installResult = Install-PSResource powershell-yaml -TrustRepository -Scope $currentScope 2>&1
218+
if($installResult -like "*Access to the path*") {
219+
Write-Verbose "Failed to install powershell-yaml module due to permission issues at $currentScope scope."
209220
$checkResults += @{
210-
message = "powershell-yaml module was not installed, but has been successfully installed (version $((Get-InstalledPSResource -Name powershell-yaml).Version))."
211-
result = "Success"
221+
message = "powershell-yaml module is not installed. Please install it using an admin terminal with 'Install-PSResource powershell-yaml -Scope $currentScope'. Could not install due to permission issues."
222+
result = "Failure"
212223
}
213-
} else {
224+
$hasFailure = $true
225+
} elseif ($null -ne $installResult) {
226+
Write-Verbose "Failed to install powershell-yaml module: $installResult"
214227
$checkResults += @{
215-
message = "powershell-yaml module is not installed. Please install it using 'Install-PSResource powershell-yaml'."
228+
message = "powershell-yaml module is not installed. Please install it using 'Install-PSResource powershell-yaml -Scope $currentScope'. Attempted installation error: $installResult"
216229
result = "Failure"
217230
}
218231
$hasFailure = $true
232+
} else {
233+
$installedVersion = (Get-InstalledPSResource -Name powershell-yaml -Scope $currentScope).Version
234+
$checkResults += @{
235+
message = "powershell-yaml module was not installed, but has been successfully installed (version $installedVersion)."
236+
result = "Success"
237+
}
219238
}
220239
}
221240
}

0 commit comments

Comments
 (0)