Advance

Learn important PowerShell commands

Learn important PowerShell commands
0
(0)

Learn important PowerShell commands. Windows PowerShell is an advanced command line environment in Microsoft operating systems, which was fully introduced in the previous articles. Now, from the series of PowerShell training, in this article, we will teach the important PowerShell commands.

Working with PowerShell is very simple. Anyone who has worked with Windows or Linux can easily work with it and take advantage of it.

In this article, we try to acquaint you with the simple and basic tips of working with PowerShell and some important PowerShell commands. Stay with us.

Important PowerShell commands

PowerShell attracted the attention of many IT executives after its introduction. Windows PowerShell eliminates the need for professionals to lack a complete command-line environment in Windows.

Commands in PowerShell have two versions of alias commands and command-lets, in which most Allies commands are very similar to Linux commands.

For example, the ps command, which is used in Linux to get a list of active processes, is also used in PowerShell.

Before you start working with PowerShell, there are a few important points that we will mention.

Recommended Article: How To Install The Apache Web Server On Ubuntu 20.04

Tips for working with PowerShell Commands

All complete PowerShell commands have a pseudonym.

When working with PowerShell, uppercase and lowercase letters are no different.

Copying several lines is possible by selecting the mouse and pressing the Enter key, and to paste, you only need to right-click the mouse.

When working with PowerShell, you only need to type part of the command and press the Tab key to continue writing it automatically.

PowerShell can be run and managed on all parts of Windows.

Other Microsoft software and tools that are not on Windows by default have external modules to add to PowerShell.

PowerShell has a feature called PowerShell Direct to remotely control and manage another Windows system.

PowerShell has the ability to execute script commands.

In the following tutorial, you will learn more about the important PowerShell commands.

 

Learn PowerShell Basic Commands

Get Help commands in PowerShell

Like any PowerShell command line environment, it has a command to get-help. Learning these types of commands will definitely help you a lot in continuing to work with PowerShell.

For example, if you want to get information from the stop-process command, the command you need must be entered as follows.

Get-help stop-process

 

You can also use the Man command to get help in PowerShell. This command, which is similar to the Man command in Linux, will give you complete information about a command.

This command is entered as follows:

Man stop-process

 

The difference between the Get-help command and the Man command is that the page stops automatically when the output of the Man command is displayed.

This means that if the output content is more than the page size, it will automatically prevent the continuation of the content so that the user can easily read the text and view the rest with the Enter or Space key.

If you have trouble reading the help commands, you can use the -example parameter to get an example of the command.

In the box below is an example of using -example:

PS C:\Windows\system32> Get-Help Copy-Item -Examples    NAME  Copy-Item    SYNOPSIS  Copies an item from one location to another.    Example 1: Copy a file to the specified directory    PS C:\>Copy-Item "C:\Wabash\Logfiles\mar1604.log.txt" -Destination "C:\Presentation"    This command copies the mar1604.log.txt file to the C:\Presentation directory. The command does not delete the  original file.

 

If the Get-Help command does not show you complete information about the commands, update the PowerShell help file by entering the following command:

Update-help

 

Note: If Update-help encounters an error, open your PowerShell as Run as Administrator.

List of files and directories

The next command in this tutorial is the Get-Childitem command. This command is used to get a list of files and folders.

Using this command is very simple and you just need to enter it without parameters in PowerShell.

PS C:\> Get-childitem  Directory: C:\    Mode LastWriteTime Length Name  ---- ------------- ------ ----  d----- 8/8/2017 8:36 PM Intel  d----- 3/19/2017 12:33 AM PerfLogs  d-r--- 8/27/2017 9:10 PM Program Files  d-r--- 8/9/2017 12:47 AM Program Files (x86)  d-r--- 8/8/2017 7:44 PM Users  d----- 8/9/2017 1:13 AM Windows

 

There is another command called ls that you will enter to get the same output as the Get-Childitem command.

The ls or Get-Childitem command has a commonly used parameter called -attribute. Using this parameter you can see the complete list of hidden files.

Ls -attibutes hidden

or

Get-childitem -attributes h

or

ls -Attrib h

 

Navigate between folders in PowerShell

The command to change the address in PowerShell is Set-Location. You can also use the Cd command to move between directories.

Set-Location command structure
Set-location D:\multimedia

or

Cd c:\windows

 

One of the advantages of PowerShell and the Set-Location command is that you can go to the Windows registry directories, with which you can edit the registry keys.

To go to the Windows registry, you must use the -path parameter and the abbreviation of the registry directory.

 

Set-location -path “HKCU”

 

After entering the above command, you will go to the HKEY Current User directory.

 

Clear the PowerShell page

In PowerShell you can use the cls or clear command to clear the page.

Cls and Clear command structure in PowerShell
Cls

or

Clear

 

View the contents of text files in PowerShell

Use the Get-Content command or its alias Cat to display the contents of text files in PowerShell.

The method of using this command is very simple. Just enter the command with the full text file name.

Cat and Get-Content command structure
Cat eldernode.txt

or

Get-content eldernode.txt

 

Copy files in PowerShell

To get a copy in PowerShell, just use one of the Cp, Copy or Copy-Item commands. These 3 commands work the same and are no different.

Copy-Item command structure in PowerShell
Cp D:\multimedia\learn.mkv -destionation E:\video\

or

Copy-item D:\multimedia\learn.mkv -destination E:\video\

 

Note: In all commands, such as a copy that has two source and destination addresses, you only need to show them with a space.

Recommended Article: initial set up centos 8

Rename files in PowerShell

Renaming a file or folder in PowerShell is possible with either Ren or Rename-Item. To rename a file or folder, just type the command and then enter the name of the original file and then a new name with a space.

Rename-item “learn.mkv” train.mkv

or

Ren “learn.mkv” train.mkv

 

Delete files in PowerShell

Deleting a file or folder in PowerShell is no different, and both can be done using either the Remove-item or Del commands.

Remove-Item command structure in PowerShell
Remove-item D:\multimedia\learn.mkv

or

Del D:\multimedia

 

Move the file in PowerShell

The Move-Item or Mv command can be used to move the file in PowerShell. This command is the same as the structure of the Copy-Item command.

 

Move command structure in PowerShell
Move-item D:\eldernode.txt -destination E:\

or

Mv D:\eldernode.txt E:\

 

List of active processes in PowerShell

Getting the list of Processes or the same active processes in PowerShell is very simple and can be done with the Ps command or Get-Process.

Get-Process command structure in PowerShell
Ps

or

Get-process

 

One of the most important and interesting features of the Get-Process command is receiving the processes of a particular program. For example, by entering the following command, you will see explorer processes.

Get-Process explorer

 

Close PowerShell enabled processes

The two commands kill and Stop-Process have the ability to close active processes. To use these commands, just enter the command and enter the name or ID of the desired process.

 

Kill and Stop-process command structure
Stop-process 298

or

Kill -name notepad

 

Note: If you encounter a problem or error while using these commands, use the -force parameter.

Stop-Process -Name notepad -Force

 

Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problem in it as soon as possible. Make time for other users and experts to answer your questions.

Goodluck.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day