Hammer of the Gods
New Member
Having trouble getting some PowerShell scripts used for installing programs to execute during post-install. If I run them on the desktop manually after setup they work fine, but they appear to not work properly when I put the .ps1 files in post install.
Set execution policy for LocalMachine to unrestricted via a registry edit:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"Path"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
"ExecutionPolicy"="Unrestricted"
Post-install order:
WinGet_Chocolatey.ps1
Install_Programs.ps1
DirectX.ps1
WinGet_Chocolatey.ps1
Script to install WinGet and Chocolatey:
#Install WinGet
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
#Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Install_Programs.ps1
Script to install starting programs:
#Install VCRedist 2013 + 2015-2022
winget install --id=Microsoft.VCRedist.2013.x86 -e --accept-package-agreements --accept-source-agreements ; winget install --id=Microsoft.VCRedist.2013.x64 -e ; winget install --id=Microsoft.VCRedist.2015+.x86 -e ; winget install --id=Microsoft.VCRedist.2015+.x64 -e
#Install Shell
winget install nilesoft.shell
#Install Google Chrome
winget install --id Google.Chrome -e
#Install PowerToys
winget install Microsoft.PowerToys --source winget
#Install Notepad++
winget install --id Notepad++.Notepad++ -e
#Install 7-Zip
winget install --id 7zip.7zip -e
#Install VLC
winget install --id=VideoLAN.VLC -e
#Install EarTrumpet
winget install --id=File-New-Project.EarTrumpet -e
DirectX.ps1
Script to install DirectX (separated to troubleshoot the elevated rights separately):
#Elevate Script
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
#Instal DirectX
winget install --id=Microsoft.DirectX -e
Set execution policy for LocalMachine to unrestricted via a registry edit:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"Path"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
"ExecutionPolicy"="Unrestricted"
Post-install order:
WinGet_Chocolatey.ps1
Install_Programs.ps1
DirectX.ps1
WinGet_Chocolatey.ps1
Script to install WinGet and Chocolatey:
#Install WinGet
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
#Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Install_Programs.ps1
Script to install starting programs:
#Install VCRedist 2013 + 2015-2022
winget install --id=Microsoft.VCRedist.2013.x86 -e --accept-package-agreements --accept-source-agreements ; winget install --id=Microsoft.VCRedist.2013.x64 -e ; winget install --id=Microsoft.VCRedist.2015+.x86 -e ; winget install --id=Microsoft.VCRedist.2015+.x64 -e
#Install Shell
winget install nilesoft.shell
#Install Google Chrome
winget install --id Google.Chrome -e
#Install PowerToys
winget install Microsoft.PowerToys --source winget
#Install Notepad++
winget install --id Notepad++.Notepad++ -e
#Install 7-Zip
winget install --id 7zip.7zip -e
#Install VLC
winget install --id=VideoLAN.VLC -e
#Install EarTrumpet
winget install --id=File-New-Project.EarTrumpet -e
DirectX.ps1
Script to install DirectX (separated to troubleshoot the elevated rights separately):
#Elevate Script
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
#Instal DirectX
winget install --id=Microsoft.DirectX -e