Skip to content

Instantly share code, notes, and snippets.

@Karobwe
Last active September 10, 2023 06:30
Show Gist options
  • Save Karobwe/db84dec48458490ab3f135e02fd4a108 to your computer and use it in GitHub Desktop.
Save Karobwe/db84dec48458490ab3f135e02fd4a108 to your computer and use it in GitHub Desktop.
Useful commands/tips for Powershell

Useful commands/tips for Powershell

Winget

winget search key-word

# Search can be used to find the ID
winget install <Package ID>

Terminal

# Create a symlink
# New-Item -Path  <SymlinkDestination> -ItemType SymbolicLink -Value <OriginalFile>
# E.g:
New-Item -Path  "C:\Users\Karobwe\AppData\Local\Karobwe\libs\Microsoft.OpenJDK.17" -ItemType SymbolicLink -Value "C:\Program Files\Microsoft\jdk-17.0.8.101-hotspot\"

# List environment variables:
gci env:

# Environment variables cant be used as they are, for example "cd %UserProfile% will fail
# because Powershell will look for a file named "%UserProfile%"
cd $Env:UserProfile

# Equivalent for Linux's "touch":
New-Item -Path  powershell-stuff-for-dummies.md
echo "Big question need simple response" >> powershell-stuff-fordummies.md

Windows related stuffs

Custom user home dir name on Windows

By default in Windows 10 and 11, the user folder is named with the first 5 characters of your name or Email address... Microsoft strongly advise that you do not change the name on the user folder, because that is referenced in many places in the registry and changing that name can have unforeseen consequences later.

So how to deal with it? By creating local account then link it to the Microsoft account if you want. This can be done using GUI or cli.

One easy and safe method for new computer or if you don't mind to reset your laptop:

  • Reset Windows by removing all existing data (and profiles)
  • Turn off Wifi or other Internet connection
  • Don't configure local account, use default one (Administrator for english local)
  • You'll be loged in as Administrator or equivalent according to the language you choosed
  • Open terminal and use net utility to create local account, make sure to give it administrator right
  • Disable Administrator account
# Get informatio  about all registred user profiles, including disabled one
Wmic useraccount get name

# Create new user called "Jessica" with password "JessPassword45" (note: you can ommit the password)
net user Jessica JessPassword45 /ADD

# Enable/disable user profile:
net user Guest /active:no

You can delete user profile using net utility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment