Log inRegister
You are here: Boossy » Software » SwMicrosoft » MsWindowsGeneral » WinTerminal

Windows Terminal

Windows Terminal combineert een aantal command line tools:
  • Command Prompt
  • PowerShell
  • Azure Cloud Shell
  • WSL (Windows Subsystem for Linux)
Ook SSH-sessies vanuit Terminal zijn mogelijk, als je tenminste de Windows Additional Feature OpenSSH Client hebt geïnstalleerd.

Bovendien kun je met tabs werken.

Als je het wil toevoegen aan je contextmenu, zie dan WinContextMenu.

PowerShell 7

Hoe achterhaal je het versienummer van PowerShell? Geef volgende opdracht in PowerShell:
Get-Host | Select-Object Version

De installatiebestanden vind je hier: https://github.com/PowerShell/PowerShell.

Volgens https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows gebruik je best winget om het op een client te installeren.

Als je dat doet, krijg je tijdens de installatie niet de mogelijkheid om de contextmenu's toe te voegen. Wil je dat wel, dan download je beter de .msi.

Ga via winget op zoek naar PowerShell:

winget search Microsoft.PowerShell

Dat resulteert in:

Name       Id                                   Version Source
--------------------------------------------------------------
PowerShell Microsoft.PowerShell                 7.3.4.0 winget
PowerShell Preview Microsoft.PowerShell.Preview 7.4.1.0 winget

Installeer dan als volgt, gebruikmakend van de juiste Id:

winget install --id Microsoft.Powershell --source winget
 

Make PowerShell 7 the default terminal application

In Windows Terminal:
  • click the down arrow () to the right of the tab(s) and choose Settings
  • in the Startup section,
  • click the dropdown next to Default profile
  • and choose PowerShell
source: Defaulting Windows Terminal to PowerShell 7.x Core – Cody Hosterman

System shell

PsExec is designed especially to execute commands on remote machines.

Using the PsExec command line utility from PsTools (PsTools - Windows Sysinternals | Microsoft Docs), you can initiate a system shell. Open an elevated command prompt and issue the following statement to do that:

psexec.exe -s -i cmd

The above command starts the shell for the System account (-s) interactively (-i), and works fine for domain connected pc's.

If you want to launch a psexec session on your local machine (not connected to a domain), issue the following command:

PSEXEC.EXE \\<ip address> -u <username> -p <password> -s -i cmd

Strangely enough, it doesn't work with the machine name, but requires the ip address.

Why do you need it?

This way you have access to e.g. C:\Program Files\WindowsApps.

Add system shell to Windows Terminal

See: https://oofhours.com/2020/12/08/using-psexec-with-windows-terminal/

In Windows 11, you have a GUI, so in Windows Terminal:
  • click the down arrow () to the right of the tab(s)
  • choose Settings
  • on the left side, below Profiles, click on Add a new profile
  • choose New empty profile
    • Name: System Shell
    • Command line, depending on whether you prefer a cmd or PowerShell:
      - psexec.exe -s -i cmd
      or
      - PSExec -s -i "C:\Program Files\PowerShell\7\pwsh.exe"

cmd and PowerShell here (as admin) from File Explorer's address bar

File Explorer's address bar recognizes all .exe and .bat files (and other extensions within the PATHEXT ) that are in path environment variable.

Command Prompt here

  • simply type cmd in File Explorer's address and a Command Prompt window is opened in the current directory

Command Prompt here as administrator

In a directory that is in the path environment variable, e.g. %LocalAppData%\Microsoft\WindowsApps, create a .bat file, e.g. cmdadm.bat with the following content:
set here=%cd%
wscript.exe "C:\Users\sbo\AppData\Local\Microsoft\WindowsApps\Cache/helper.vbs" "C:\Users\sbo\AppData\Local\Microsoft\WindowsApps\wt.exe" "%here%" "Command Prompt"

Now you can simply type cmdadm in the File Explorer address bar and you'll get a Command Prompt as administrator in the current directory.

PowerShell 7.x here

You can type powershell in the address bar, but that will open PowerShell 5.1 by default, so that's why we need a separate approach for PowerShell 7.x.

In a directory that is in the path environment variable, e.g. %LocalAppData%\Microsoft\WindowsApps, create a .bat file, e.g. ps7.bat with the following content:

@echo off
pwsh -wd .
REM wt -d .

Now you can simply type ps7 in the File Explorer address bar and you'll get a Command Prompt as administrator in the current directory.

PowerShell 7.x here as administrator

This is of course comparable to cmd here as admin. So, in a directory that is in the path environment variable, e.g. %LocalAppData%\Microsoft\WindowsApps, create a .bat file, e.g. ps7adm.bat with the following content:

set here=%cd%
wscript.exe "C:\Users\sbo\AppData\Local\Microsoft\WindowsApps\Cache/helper.vbs" "C:\Users\sbo\AppData\Local\Microsoft\WindowsApps\wt.exe" "%here%"

Now you can simply type ps7adm in the File Explorer address bar and you'll get a PowerShell prompt as administrator in the current directory.
  • as you can see, I haven't added a Windows Terminal profile here, that's because PowerShell is the default profile in my Windows Terminal - if that's not the case, add "PowerShell" to the command above (including the quotes).

update history

24/05/2023: added double quotes around %here% for pathnames with spaces

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This page was cached on 25 Mar 2024 - 09:35.