diff --git a/Tools.ps1 b/Tools.ps1 index 0e57d36..632d1e4 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -1149,6 +1149,36 @@ Function Set-OutlookProfilePrompt () { Write-Output "Available Outlook profiles:`n${Profiles}" } +# Function to install and run script using Powershell 7 +# Provided by j.mcbride from https://community.syncromsp.com/t/powershell-7-2/7425/5 +Function Start-ScriptInPowershell7 () { + # Check for required PowerShell version (7+) + If (!($PSVersionTable.PSVersion.Major -ge 7)) { + Try { + + # Install PowerShell 7 if missing + If (!(Test-Path "$env:SystemDrive\Program Files\PowerShell\7")) { + Write-Output 'Installing PowerShell version 7...' + Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet" + } + + # Refresh PATH + $Env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User') + + # Restart script in PowerShell 7 + pwsh -File "`"$PSCommandPath`"" @PSBoundParameters + + } + Catch { Write-Error $_.Exception.Message } + Finally { Exit $LASTEXITCODE } + } + # Input the actual script below this line +} + +# Upgrade default TLS version to 1.2 +Try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } +Catch { Write-Error $_.Exception.Message } + # Initial setup of the MSP management directories and log file Setup-MSPDirectories Setup-LogFile