Over the past 6-12 months I have started using a more Microsoft-y environment on Windows, both on my own laptop and work’s. It started with using the bundled Windows OpenSSH client, removing the need for me to launch a Windows Subsystem for Linux (WSL) environment just to ssh to another system. I also been trying out Microsoft Terminal(yes, it is open source), which was released on Tuesday, and it is a really slick tool - a vast improvement on the old command-line windows and/or PuTTY. Yesterday I switched my default session from (WSL) Debian to PowerShell and have started using it as my main shell environment on Windows.

PowerShell basics

The first thing to note is that all commands are formatted as ‘Verb-Noun’. For example, ‘Get-Help’ (which is a very useful to know).

Aliases

One of the first things I did was to create an alias for Sublime Text 3, currently my preferred text editor:

New-Item -Path Alias:subl -Value 'C:\Program Files\Sublime Text 3\subl.exe'

Services

Because I use ssh almost all day everyday, I wanted an ssh-agent running on my machine.

One thing to note it that the Microsoft agent stores keys that are added in a key-store, so once the keys are added you no longer need to keep the private key file from ssh-keygen around. Microsoft’s own documentation recommends deleting the private keys once added (it also does not set a pass-phrase in the examples, which is bad practice):

It is strongly recommended that you back up your private key to a secure location, then delete it from the local system, after adding it to ssh-agent. The private key cannot be retrieved from the agent.

There is also a blog post on sharing SSH keys between Windows and WSL(spoiler: it is not possible), in which the author quite eloquently describes the problem. This is not directly useful to me as I just use SaltStack to manage both.

In order to manipulate services, you need PowerShell running as an administrator. To do this you need to launch a new terminal via ‘Run as administrator’ or use this PowerShell command, which will launch a new PowerShell window with elevated privileges:

Start-Process powershell -verb runAs

Once elevated to administrator, the ssh-agent service (‘OpenSSH Authentication Agent’ in the service user interface) can be enabled and set to running with one command:

Set-Service -Name ssh-agent -StartupType Automatic -Status Running

The current status of the service can be seen with:

Get-Service -Name ssh-agent 

And the name, start-up type and status with this command:

Get-Service -Name ssh-agent | Select-Object -Property Name, StartType, Status

Other notes

Here’s some information on keyboard shortcuts - I really do not like that ‘Ctrl+Home’ and ‘Ctrl+End’ delete to the start/end of a line but ‘Ctrl+arrow’ moves forward/back a word. It seems easy to forget that ‘Ctrl+movement_key’ is destructive with some combinations but not other. Anyway, directly quoted from https://computingforgeeks.com/top-20-windows-powershell-keyboard-shortcuts-for-geeks/:

Top 20 Windows PowerShell Keyboard Shortcuts For Geeks

To move the cursor word by word, you have to hold down the control key while pressing the Arrow Keys. Here is a List of Most used PowerShell Keyboard Shortcuts.

  • HOME: The home button places the cursor at the beginning of the line when pressed.
  • END: Places the cursor at the End of the Line
  • DEL: Erases character to the to the right of the Cursor
  • BACKSPACE: Deletes character to the left of the cursor.
  • ESC: Deletes the entire current line.
  • CTRL+HOME: Deletes all the characters at the current position up to the beginning of the Line. While sparing characters to the right of the cursor position.
  • CTRL+END: Deletes everything from the current cursor position up to the end of the Line.
  • INSERT key: Used to switch between insert and type-over modes. Type-over mode is encountered when you enter new characters and they overwrite existing Ones.
  • Arrow UP: Display previously entered commands reducing work of retyping recently used commands.
  • Arrow Down Key: Scroll down your command history.
  • F7: Shows a Full List of previously entered Commands with the support of scrolling and selecting command you want to reuse.
  • F8: Moves through the whole History List back and forth.
  • F4: Select the character to delete up to
  • ALT+ F7: Clear the command history and reset command count
  • F9: Select a Command by its number in the command history buffer through a Menu that accepts numbers and returns Desired Command.

To see all the commands you have entered before that begins with a certain Letter, type:

Letter(F8)

For example; Typing b(F8) will print out the commands you previously entered that begins with “b”.

Tab Key: Helps you avoid typos or typing errors. It will automatically complete a command for you after pressing few first letters. Typing it twice will work you through suggestions.