PowerShell Tutorial – GUIDE introduction with basics
2022-4-19 03:9:2 Author: kalitut.com(查看原文) 阅读量:26 收藏

This is the ultimate PowerShell tutorial . Here you will learn everything about console programs and commands from PowerShell, CMD and Bash.

PowerShell Tutorial - GUIDE introduction with basics

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:

  1. The user enters a command
  2. The user starts the command with ENTER
  3. The computer executes the command and outputs text
  4. 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 lineGUI
Less system resources for displayLess "googled" for command line commands and errors
Options with HELP flag can be found quicklyGraphic improvements like fonts, drop-down_menus
Simplified automation and repeatsGetting used to GUIs is short compared to the command line
developing proceduresEasy 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:

  1. Windows servers from 2008
  2. Active Directory (management of multiple Windows computers)
  3. Domain Name System (resolution of IP numbers in domain addresses)
  4. Hyper-V (virtual machine virtualization environment)
  5. ISS Web Service (Microsoft Web Server)
  6. 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.

shortcutmeaning / effect
Ctrl + CStops the running foreground process (hard)
Ctrl + ZStopping the foreground process
Ctrl + LEmpty inputs and outputs
Arrow up / downScroll through all previous entries
tabThe shortcuts auto-completes a command, filename, path for you

Types of Consoles / Shell / CMD

  1. Operating system consoles: cmd.exe, DEC Digital Command Language
  2. Application Consoles: Console-based applications
    1. Parameters: Information about the execution of the program, which changes the course of execution
    2. 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 WindowsBash Linu
Display help for a commandhelp programnameprogram name –h [alternatively –help]
change to another directory/foldercd foldername[/foldername/…]cd foldername[/foldername/…]
View files and foldersdir [/folder name/...]ls [/foldername/…]
move filemove oldfolder\filename.end newfolder\ filename.endmv oldfolder/filename.end newfolder/ filename.end
delete filedel filename.endrm filename.end
create foldermkdir folder namemkdir folder name
Edit / create filenotepad [filename old/new]vi [filename old/new]
Display the installation location of a programwhere programNamewhere programName
Download filecurl [https://url] –output [file.ending]curl [https://url] –output [file.ending]
run programprogramNameprogramName or ./programName
Run files / folders with administrator rightsrunas /noprofile /user:Administrator cmdsudo [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 Windowsbash linux
commandhelp-h or -help
syntaxhelp program nameprogram name –h [alternatively –help]
examplehelpJavac -help
tipsOnly for Windows own programsFor any Linux console program
PowerShell Tutorial

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 Windowsbash linux
commandCDCD
syntaxcd foldername[/foldername/…]cd foldername[/foldername/…]
exampleCDAMDCDAMD
tipsYou can complete the folder name with TabYou can complete the folder name with Tab
cmd - PowerShell

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 Windowsbash linux
commandto youls
syntaxdir [/folder name/...]ls [/foldername/…]
exampleyou userls user
tipsWith dir /AH you can display hidden filesWith 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 Windowsbash linux
commandmovemv
syntaxmove oldfolder\filename.end newfolder\ filename.endmv oldfolder/filename.end newfolder/ filename.end
examplemove c:\users\steff\text.txt C:\users\steff\Downloadsmv c:/users/steff/Downloads/text.txt c:/users/steff/text.txt
tips

Delete file

 PowerShell Windowsbash linux
commanddelrm
syntaxdel filename.endrm filename.end
exampledeltext.txtrmtext.txt
tips

Create folders

In Windows you can use CTRL+SHIFT+N in the graphical interface to quickly create new folders.

 PowerShell Windowsbash linux
commandmkdirmkdir
syntaxmkdir folder namemkdir folder name
examplemkdir gardenmkdir 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 Windowsbash linux
commandnotebookvi
syntaxnotepad [filename old/new]vi [filename old/new]
examplenotepadtext.txtvi text.txt
tipsOpens a graphical interfacevi 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 Windowsbash linux
commandwherewhere
syntaxwhere programNamewhere programName
examplewhere javawhere java
tipsLook 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 consoleTo 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 Windowsbash linux
commandcurlcurl
syntaxcurl [https://url] –output [file.ending]curl [https://url] –output [file.ending]
examplecurl https://kalitut.com – output kalitut.htmlcurl 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 Windowsbash linux
commandnothingNothing or ./
syntaxprogramNameprogramName or in the home directory ./programName
exampleJavajava or ./java
tipsUse the help flag (see above) to learn more about the program's commandsUse 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 Windowsbash linux
commandrunas /noprofile /user:Administrator cmdsudo or
syntaxrunas /noprofile /user:Administrator cmdsudo [any command except cd]
examplerunas /noprofile /user:Administrator cmdsudo apt-get install java
tipsYou 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.

文章来源: https://kalitut.com/powershell-tutorial-guide/
如有侵权请联系:admin#unsafe.sh