This is the ultimate PowerShell tutorial . Here you will learn everything about console programs and commands from PowerShell, CMD and Bash.
In this tutorial (almost) everything works without a graphical user interface .
Clarify terms: Console, Shell, CMD, PowerShell and more
- Console is a prompt or prompt that asks for text input and usually displays text output.
- Bash = Shell is a Unix project under GPL and is a console for Linux and UNIX systems . This was developed by Brian Fox.
- Windows CMD.exe is called the Windows command prompt of Windows NT (New Technology) Line and React-OS (Operating System).
- Windows PowerShell is based on Dot-Net since 2009 and is a cross-platform console with the MIT license.
A BAT file (batch) is a script with ready-made console commands for Windows. With a click on the file, the computer executes the commands. Control structures such as closes and variables are possible.
Behind CMD.exe is the command line interpreter COMMAND.COM, which checks the entries. Windows PowerShell works with the PowerShell engine as a command line interpreter
PowerShell operation in 5 steps
A console works according to the same scheme:
- The user enters a command
- The user starts the command with ENTER
- The computer executes the command and outputs text
- The computer provides a new input field.
PowerShell vs Graphical User Interface (GUI)
When do I use a command line? When the GUI ? What are the advantages and disadvantages of the input options?
command line | GUI |
---|---|
Less system resources for display | Less "googled" for command line commands and errors |
Options with HELP flag can be found quickly | Graphic improvements like fonts, drop-down_menus |
Simplified automation and repeats | Getting used to GUIs is short compared to the command line |
developing procedures | Easy to use (for non-IT people). |
Use a GUI when…
- You complete a standard task.
- a proven GUI is available.
- You don’t know the commands.
- don’t have a command line available.
Use the command line when..
- You want to do specific tasks.
- You need a debugging option.
- You need increased processing speed (overload through GUI).
- The GUI sche*** is.
PowerShell explained
PowerShell is a cross-platform framework for setting, administering and automating e.g. B. Microsoft systems. PowerShell includes a command line interpreter and a language for scripting commands.
PowerShell belongs to the .NET Framework . .NET is a collection of developer tools and class libraries based on the common language runtime . Since 2016, PowerShell has been cross-platform (not just limited to Windows) and open source.
Scripts with PowerShell
For automation you need a script that you can run on the PowerShell. Like any programming language, PowerShell has a few special features. Instead of a less than sign, you use -lt to show a comparison.
for($counter=0;$counter -lt 9;$counter++) { Write-Host „Wiederhole die Schlefe $counter“ }
Application area PowerShell
The cross-platform PowerShell is extremely versatile. Configure with PowerShell e.g. B:
- Windows servers from 2008
- Active Directory (management of multiple Windows computers)
- Domain Name System (resolution of IP numbers in domain addresses)
- Hyper-V (virtual machine virtualization environment)
- ISS Web Service (Microsoft Web Server)
- Configuration of network, hard disks, proxy etc.
Ultimate Productivity Tips for PowerShell
So that you can work quickly and efficiently with PowerShell, learn the following shortcuts by heart. With a right click on the PowerShell menu bar you can adjust some shortcuts according to your wishes under > Settings > Options.
shortcut | meaning / effect |
---|---|
Ctrl + C | Stops the running foreground process (hard) |
Ctrl + Z | Stopping the foreground process |
Ctrl + L | Empty inputs and outputs |
Arrow up / down | Scroll through all previous entries |
tab | The shortcuts auto-completes a command, filename, path for you |
Types of Consoles / Shell / CMD
- Operating system consoles: cmd.exe, DEC Digital Command Language
- Application Consoles: Console-based applications
- Parameters: Information about the execution of the program, which changes the course of execution
- Prompts: After execution, the program asks for various parameters
The 11 Commands – PowerShell Tutorial
If you know these 11 commands for Bash and CMD from this PowerShell tutorial, you can do 80% of the day-to -day operation inside the Console / CMD / Bash / Shell.
Read the table below and scroll to the relevant section:
I would like to use PowerShell…
PowerShell Windows | Bash Linu | |
---|---|---|
Display help for a command | help programname | program name –h [alternatively –help] |
change to another directory/folder | cd foldername[/foldername/…] | cd foldername[/foldername/…] |
View files and folders | dir [/folder name/...] | ls [/foldername/…] |
move file | move oldfolder\filename.end newfolder\ filename.end | mv oldfolder/filename.end newfolder/ filename.end |
delete file | del filename.end | rm filename.end |
create folder | mkdir folder name | mkdir folder name |
Edit / create file | notepad [filename old/new] | vi [filename old/new] |
Display the installation location of a program | where programName | where programName |
Download file | curl [https://url] –output [file.ending] | curl [https://url] –output [file.ending] |
run program | programName | programName or ./programName |
Run files / folders with administrator rights | runas /noprofile /user:Administrator cmd | sudo [any command except cd] |
Display help for the Power Shell Tutorial
Let’s assume one for the tutorial, you have a great SDK console program. You don’t know the commands and you can’t find any documentation on the internet. With the help flag you can have all the commands from the great SDK console program displayed without having to look for any descriptions. A command consists of the program name, parameters and flags / options. The output of the help flag should explain the commands of the great SDK console program .
PowerShell Windows | bash linux | |
---|---|---|
command | help | -h or -help |
syntax | help program name | program name –h [alternatively –help] |
example | help | Javac -help |
tips | Only for Windows own programs | For any Linux console program |
Change to another directory / folder
A path is in front of the input field in the console.
The console can only operate in the specified folder (see path). If you want to run a program in a different folder, then you have to change the directory (change directory).
PowerShell Windows | bash linux | |
---|---|---|
command | CD | CD |
syntax | cd foldername[/foldername/…] | cd foldername[/foldername/…] |
example | CDAMD | CDAMD |
tips | You can complete the folder name with Tab | You can complete the folder name with Tab |
View files and folders
The console says nothing more than the path of the folder you are in. The dir / ls command gives you all files, programs and subfolders as a list.
PowerShell Windows | bash linux | |
---|---|---|
command | to you | ls |
syntax | dir [/folder name/...] | ls [/foldername/…] |
example | you user | ls user |
tips | With dir /AH you can display hidden files | With ls -a you can display hidden files |
Move File
This is how you transfer a file from the A folder to the B folder.
PowerShell Windows | bash linux | |
---|---|---|
command | move | mv |
syntax | move oldfolder\filename.end newfolder\ filename.end | mv oldfolder/filename.end newfolder/ filename.end |
example | move c:\users\steff\text.txt C:\users\steff\Downloads | mv c:/users/steff/Downloads/text.txt c:/users/steff/text.txt |
tips |
Delete file
PowerShell Windows | bash linux | |
---|---|---|
command | del | rm |
syntax | del filename.end | rm filename.end |
example | deltext.txt | rmtext.txt |
tips |
Create folders
In Windows you can use CTRL+SHIFT+N in the graphical interface to quickly create new folders.
PowerShell Windows | bash linux | |
---|---|---|
command | mkdir | mkdir |
syntax | mkdir folder name | mkdir folder name |
example | mkdir garden | mkdir garden |
tips |
Edit / create file
Windows “only” offers the graphical editor notepad . Linux has a console-internal editor vi (pronounced like-ei) for vi sual editor or vim (m = i m proved)
PowerShell Windows | bash linux | |
---|---|---|
command | notebook | vi |
syntax | notepad [filename old/new] | vi [filename old/new] |
example | notepadtext.txt | vi text.txt |
tips | Opens a graphical interface | vi is a slightly old-fashioned (but fast) editor |
Display the installation location of a program
If you don’t know in which folder the Java, AndoridSDK, VSCode installation is located, where will help.
PowerShell Windows | bash linux | |
---|---|---|
command | where | where |
syntax | where programName | where programName |
example | where java | where java |
tips | Look for .exe files that YOU want to run from the console. Enter new folders in the environment variables to address more .exe programs with the console | To add variables permanently run sudo -H gedit /etc/environment and add a line VALUE=VALUE. save. Log in and out again. Restart the console. |
Download file
It’s faster without a browser.
PowerShell Windows | bash linux | |
---|---|---|
command | curl | curl |
syntax | curl [https://url] –output [file.ending] | curl [https://url] –output [file.ending] |
example | curl https://kalitut.com – output kalitut.html | curl https://kalitut.com – output kalitut.html |
tips |
Run program
You can only start a program if it is in the same directory as the console path. Alternatively, you saved the program’s folder in an environment variable. With the environment variable set, you can call the program from any folder.
PowerShell Windows | bash linux | |
---|---|---|
command | nothing | Nothing or ./ |
syntax | programName | programName or in the home directory ./programName |
example | Java | java or ./java |
tips | Use the help flag (see above) to learn more about the program's commands | Use the help flag (see above) to learn more about the program's commands. |
Administrator rights execute files / folders
You need these commands to switch to god mode.
PowerShell Windows | bash linux | |
---|---|---|
command | runas /noprofile /user:Administrator cmd | sudo or |
syntax | runas /noprofile /user:Administrator cmd | sudo [any command except cd] |
example | runas /noprofile /user:Administrator cmd | sudo apt-get install java |
tips | You can start the CMD with a right click in admin mode. | With sudo –s you can switch to SUPERUSER mode. It may be dangerous. In SUPERUSER mode you can erase the entire system with everything. |