How to Install PowerShell 7+ During Windows 11 Unattended Setup?

0
11
Asked By TechWhiz42 On

I'm trying to install PowerShell 7 (PWSH) automatically while setting up Windows 11 without any user interaction. I attempted to use the winget command during the first logon, but I keep getting a 'not available in this session' error. Here's the command I tried:

```powershell
# Check if winget is available
if (Get-Command winget -ErrorAction SilentlyContinue) {
# Install or upgrade PowerShell
winget install --id Microsoft.PowerShell --source winget --accept-package-agreements --accept-source-agreements --silent
} else {
Write-Error "winget is not installed or not available in this session."
}
```

Is there a better way to do this?

4 Answers

Answered By InstallGuru47 On

Why not use the MSI package directly? It simplifies the process for unattended installations.

QuickFix89 -

Exactly! The MSI is designed for this purpose.

Answered By PowershellNoob On

If you're running the command as system, make sure you call the winget executable specifically since it's not available in system context by default. But like others suggested, using the MSI is a more straightforward approach.

Answered By ScriptMaster91 On

You can install anything unattended as long as you follow the right method. Winget is typically for user context installs, and while there are ways to work around that, it's not officially supported. Just use the conventional methods for an unattended setup.

Answered By DevOpsDude On

Check out this GitHub project for using winget on a system level: [Winget Install](https://github.com/Romanitho/Winget-Install). It handles everything you might normally struggle with, especially for deployments with Intune.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.