CONTENTS
What is PowerShell?
How to get started with PowerShell
PowerShell installation
For Windows: PowerShell is already installed on your computer. You don't need to do anything extra! If you want the latest version with additional features, you can download PowerShell 7 (also known as PowerShell Core) from the official Microsoft page.
For Linux/macOS: You can easily install it through your system management tools, just like you install any other program.
How to open PowerShell
On Windows: Press Windows key + S, type “PowerShell” in the search box, and press Enter. A blue window with white text will appear – that’s PowerShell!
On Linux/macOS: Open the terminal and type pwsh, then press Enter.
The most useful PowerShell commands
1. Get-Help - The help command
This is the most important command for beginners and the first one to remember. It gives you detailed information and examples for any other command you want to learn. It's like having a personal tutor always available!
Example:
To see examples of using a command, add -Examples:
2. Get-Command - Find all available commands
It displays all the available commands that you can use on your system. It is useful when you want to discover what PowerShell can do.
To find commands related to something specific, use the asterisk (*) as a search symbol:
This will display all commands that have the word "service" in their name.
3. Get-Process - See running programs
This command shows you all the programs and applications currently running on your computer. You can see how much memory each program is using and other useful information.
To view information about a specific program, such as Windows Notepad:
4. Set-ExecutionPolicy - Security settings for file execution
PowerShell, for security reasons, does not allow the execution of command files by default. This protects you from accidentally executing dangerous files. This command allows you to change this setting when you need to.
The "RemoteSigned" setting means you can run your own files, but files you download from the internet must be digitally signed for security.
5. Get-Service - Manage system services
It displays all the services running on your system. Services are programs that run in the background and do various tasks, such as checking for updates or managing your network.
To view the status of a specific service, such as the Windows Update service:
6. Start-Service and Stop-Service - Service Control
These commands allow you to start or stop system services. This is useful when a service is causing problems or when you want to restart it.
To start a service:
To stop it:
Caution: Be careful when stopping services, especially if you are not sure what they do. Some services are essential for the computer to function properly.
7. Test-Connection - Network connection check
It works like the well-known "ping" command to check if you can connect to a website or another computer on the network. It's ideal for determining if you're having a problem with your internet.
To send only 4 test packets (instead of continuous checking):
8. Set-Location - Change working folder
It changes the folder you are currently in. It's like opening different folders on your computer, but from within PowerShell.
You can also use the shortcut command:
9. Get-ChildItem - Show folder contents
Displays all files and subfolders that exist in the current folder or a folder you specify.
To view the contents of a specific folder:
The abbreviation is simply ls ή dir (like in Windows before).
10. Copy-Item - Copy files and folders
Copies files or folders from one location to another. It is very useful for backing up or organizing your files.
To copy an entire folder along with all its contents:
11. Remove-Item - Delete files and folders
Deletes files or folders from your computer.
Caution: When you delete something with PowerShell, it doesn't go to the Recycle Bin - it's permanently deleted! So be very careful with this command.
12. New-Item - Create new files and folders
Creates new files or folders wherever you want.
To create a new folder:
To create a new empty file:
Creating command files (Scripts)
PowerShell allows you to store multiple commands in a file and run them all together with a single command. These files are called scripts and have the extension . .ps1It's like writing a "recipe" with instructions that you can use over and over again.
Example of a simple Script:
Create a file named example.ps1 using Notepad or any other text editor, and paste the following code:
To run the script, first navigate to the folder where you saved it using the Set-Location command, and then type:
The .\ at first it tells PowerShell to execute the file from the current folder.
Useful tips for beginners
1. Always use Get-Help: When you can't remember how a command works, Get-Help is your best friend. Don't hesitate to use it as often as needed.
2. Learn the shortcuts: PowerShell supports shortcuts for many commands, making your work faster. For example, you can type ls ή dir instead Get-ChildItemOr cd instead Set-Location.
3. Practice with simple scripts: Start with simple scripts that do basic tasks and gradually add more complex functionality as you gain experience. Don't be afraid to experiment!
4. Use Tab to autocomplete: Type the first few letters of a command and press Tab to auto-complete. If you press Tab multiple times, you will see all the available options. This saves time and avoids typing errors.
5. Keep backups: Before running any commands that delete or change files, make sure you have backups. It's better to be safe than sorry!
6. Read the commands carefully before executing them: Especially when copying commands from the internet, read them carefully to understand what they do. Don't randomly execute commands without knowing what the result will be.
7. Use the up/down arrows: You can use the up and down arrows on your keyboard to view previous commands you have executed. This saves you from having to retype the same commands.
Loading comments...