Windows prompts
PowerShell
PowerShell is a command-line shell and scripting language built on the .NET Framework. It is the successor to the Command Prompt.
Commands are called cmdlets and are written in the form Verb-Noun. For example, Get-ChildItem lists the contents of a directory.
There are a few aliases for common commands, such as ls for Get-ChildItem and rm for Remove-Item.
Write-Output: Prints a line in the shellNew-Item: Creates a new file within the same directoryGet-Content: Reads the contents of a fileSet-Content: Writes the contents of a fileRemove-Item: Deletes a fileGet-ChildItem: Lists the contents of a directory
| Command | Alias | Description |
|---|---|---|
Write-Output | echo | Prints a line in the shell |
New-Item | touch | Creates a new file within the same directory |
Get-Content | type | Reads the contents of a file |
Set-Content | echo | Writes the contents of a file |
Remove-Item | del | Deletes a file |
Get-ChildItem | dir | Lists the contents of a directory |
CMD
echo <line>: Prints a line in the shelltype <file>: Reads the contents of a file- file operations
copy <source> <target>: Copies a filemove <source> <target>: Moves a filedel <file>: Deletes a file
dir: Lists the contents of a directorycdcommands: required to change the current directorycd <dir>: Changes the current directorycd ..: Changes the current directory to the parent directorycd: Changes the current directory to the home directory
mkdir <dir>: Creates a new directory- system boot options
shutdown /s: Shuts down the systemshutdown /r: Restarts the systemshutdown /l: Logs off the current usershutdown /h: Hibernates the systemshutdown /a: Aborts the system shutdown
- computer processes
tasklist: Lists all running processestaskkill /pid <pid>: Kills a process by its PIDtaskkill /im <name>: Kills a process by its name
- network operations
ipconfig: Lists the network configurationping <host>: Pings a host
- software management
- Note: These commands may require administrator privileges
winget install <package>: Installs a packagewinget uninstall <package>: Uninstalls a packagewinget search <package>: Searches for a packagewinget show <package>: Shows information about a packagewinget source: Lists the package sourceswinget source add <source>: Adds a package sourcewinget source remove <source>: Removes a package source
- system information
systeminfo: Lists the system informationsysteminfo | findstr /B /C:"OS Name" /C:"OS Version": Lists the OS informationsysteminfo | findstr /B /C:"System Boot Time": Lists the system boot timesysteminfo | findstr /B /C:"System Manufacturer" /C:"System Model": Lists the system manufacturer and modelsysteminfo | findstr /B /C:"Total Physical Memory": Lists the total physical memorysysteminfo | findstr /B /C:"Available Physical Memory": Lists the available physical memorysysteminfo | findstr /B /C:"Virtual Memory: Max Size": Lists the maximum virtual memory
- computer troubleshooting
sfc /scannow: Scans the system for corrupted fileschkdsk: Scans the system for corrupted disksdism /online /cleanup-image /restorehealth: Scans the system for corrupted imagesdism /online /cleanup-image /startcomponentcleanup: Cleans up the systemdism /online /cleanup-image /startcomponentcleanup /resetbase: Cleans up the system and resets the basedism /online /cleanup-image /restorehealth /source:<source>: Scans the system for corrupted images using a sourcedism /online /cleanup-image /startcomponentcleanup /resetbase /source:<source>: Cleans up the system and resets the base using a source
Batch files
A batch file is a text file containing a series of commands to be executed by the command interpreter. It is similar to a shell script. Batch files have the .bat extension.
Running a hello world script
- Create a file named
hello.batwith the following contents: - Run the script by double-clicking on it
- The output should be:
1Hello, world!
- Create a file named
Fibonacci sequence
Logical operations in batch files
Components of a batch file
@echo off: Disables the echoing of commandsecho <line>: Prints a line in the shellpause: Pauses the script until a key is pressedgoto <label>: Jumps to a label