Public/Test-RaidinessPrerequisite.ps1
|
function Test-RaidinessPrerequisite { <# .SYNOPSIS Checks what a run needs before it starts: PowerShell version and the PowerShell modules each selected Raidiness module signs in with. .DESCRIPTION Nothing is installed and nothing is changed — this only reports. One row per requirement, with an Install-Module hint for what is missing, so a run with -Modules All does not fail halfway through its third sign-in because a module was never installed. .PARAMETER Modules Which Raidiness modules you intend to run (default: All). .EXAMPLE Test-RaidinessPrerequisite -Modules ExchangeOnline, Teams #> [CmdletBinding()] [OutputType([pscustomobject])] param( [ValidateSet('All', 'MsGraph', 'ExchangeOnline', 'Teams', 'SharePoint', 'PowerPlatform')] [string[]] $Modules = @('All') ) $rows = [System.Collections.Generic.List[object]]::new() $rows.Add([pscustomobject]@{ PSTypeName = 'Raidiness.Prerequisite' Module = '(host)' Requirement = 'PowerShell 7.2 or later' Present = $PSVersionTable.PSVersion -ge [version]'7.2' Hint = 'https://aka.ms/powershell' }) foreach ($module in Get-RaidinessModuleCatalog -Modules $Modules) { foreach ($required in $module.RequiredModules) { $present = [bool](Get-Module -ListAvailable -Name $required | Select-Object -First 1) $rows.Add([pscustomobject]@{ PSTypeName = 'Raidiness.Prerequisite' Module = $module.Name Requirement = "PowerShell module $required" Present = $present Hint = $present ? '' : "Install-Module $required -Scope CurrentUser" }) } } $missing = @($rows | Where-Object { -not $_.Present }) if ($missing.Count -eq 0) { Write-Host "All prerequisites present for: $((Get-RaidinessModuleCatalog -Modules $Modules).Name -join ', ')." -ForegroundColor Green } else { Write-Host "$($missing.Count) prerequisite(s) missing — the affected modules will be skipped or fail to sign in:" -ForegroundColor Yellow foreach ($row in $missing) { Write-Host " - $($row.Module): $($row.Requirement) → $($row.Hint)" -ForegroundColor Yellow } } return $rows.ToArray() } |