Computer

Do you want to master PowerShell? Start with those basic commands

Advantages of using as administrator

At this point it is important to know that, as with the rest of the operating system applications, PowerShell can be executed in different ways. We can open it in conventional mode, through which we will have certain permissions blocked such as:

  • Changes in the execution policy.
  • Modification of system files.
  • Registry Modifications.

This is especially interesting because less experienced users may end up making changes to the system that may end up damaging it. In the event that you want to have full control, it will be necessary to run the application as an administrator.

How to open in Windows

Once we know a little more about PowerShell, it is important to learn how we can open it. Whether in Windows 10 or Windows 11, there are different ways to do it, but the most common is to type “Windows PowerShell” in the Start menu search box.

Run PowerShell as administrator

Later, it is important that we take into account the possibility of starting it as an administrator, since this will allow us to carry out all kinds of tasks, even the most complete ones. Therefore, once we see the Windows PowerShell executable icon, we must click on the option Run as administrator which we find on the right.

Basic and essential commands

Once we have learned more about PowerShell, we will show you a series of basic and essential commands that we must know to work with this command line console. As we master them we can go deeper into them.

Help to use any command

It is possible that when using PowerShell commands we find that we do not know how to use them. For this we can use the Get-Help command with which we will obtain different types of help. Whether it is generic help, about a specific command or knowing how any command works:

Get-Help Get-Help <comando> Get-Help <comando> -Full Get-Help <comando> -Example Get-Help *

PowerShell Get-Help

Sometimes, it can also be useful to use the Update-Help command, which will help us to download help libraries.

Find and open files

In the event that we need to search for a specific directory from this console, the Get-Item command that will be in charge of showing us its content in question. For this we will write:

Get-Item <ruta>

If what we want is to open a file from this console, we must use a command similar to the previous one, such as:

Get-Content <ruta al archivo con su extensión>

This command is most useful for getting lists of information in Windows PowerShell directly.

Find a command

It is likely that when we want to execute any command, we may not remember exactly its syntax, so PowerShell has the possibility of searching for them just by remembering a part of it.

In order to find commands of a similar type or that contain a particular phrase, it is possible to use the Get-Command cmdlet. However, it doesn’t list all the cmdlets in PowerShell, so it takes care of using some filters. It is possible to use the commands:

Get-Comand – Name <nombre> Get-Commad – CommandType <tipo>

PowerShell Get-Command

We will use the first command to obtain commands related to the name that we indicate, while the second is used to be able to carry out a specific function.

Create a new directory

With PowerShell we can also create a new directory using the mkdir command. It is important that when giving the name we avoid using spaces.

For example, we can create the directory DocumentSoftZone

mkdir DocumentoSoftZone

We can also avoid the use of spaces by inserting a hyphen or underscore, for example:

mkdir DocumentoSoftZone

Copy and delete files or directories

Another of the functions of the Windows console is the possibility of copying and deleting files or directories, for which we can use the Copy-Item or Remove-Item commands depending on what we need.

To copy a file or directory we use:

Copy-Item «ruta al archivo de origen con extensión» -Destination «ruta de destino»

In the event that what we want is to delete it, we must choose:

Remove-Item «ruta al archivo con extensión»

List of all files within a folder

If we want to see all the elements that are inside a folder we can do it through the command:

Get-ChildItem

We can add the Force parameter to also show the hidden elements of the system, for example, of the C: drive.

Get-ChildItem -Path C: -Force

Create files and folders

With PowerShell we also have the possibility to create new elements depending on the type of element. In case you have more than one type of element it will be necessary to specify the type of element.

This command creates a new folder:

New-Item -Path 'C:tempNueva carpeta' -ItemType Directory

This command creates a new empty file:

New-Item -Path 'C:tempNueva carpetafile.txt' -ItemType File

Know all the content of a file

If we need to know all the content of a text file in a specific path, we can use the Get-Content command, to be able to examine it without having to open it. Using Get-Content alone does not provide much utility, but can be mixed with more specific cmdlets for more precise results.

For example, we can see the content of the file softzone.htm

Get-Content "C:/softzone.txt"

We can also see 10 lines of text included in softzone.htm

Get-Content "C:/softzone.txt" – TotalCount 20

Change execution policy

Although PowerShell has support for creating and running scripts, it also has restrictions for each of them as part of security measures. It is possible to change the security level to any of four levels of restrictions. To do this, it is possible to use the Set-ExecutionPolicy command followed by any of the security levels that we will see below:

Set-ExecutionPolicy Unrestricted Set-ExecutionPolicy All Signed Set-ExecutionPolicy Remote Signed Set-ExecutionPolicy Restricted

In this list, security policies range from least restrictive to most restrictive.

View, start, stop, suspend or restart a service or process

Windows has certain services that are small used application processes that always run in the background, such as to always be on the alert to run or check for updates in the background.

List of running services

If we want to see in PowerShell a complete list of the services that are running, we must use the command Get Service. With the help of other commands we can perform certain actions such as:

Start-Service <nombre del servicio> Stop-Service <nombre del servicio> Suspend-Service <nombre del servicio> Resume-Service <nombre del servicio> Restart-Service <nombre del servicio>

The commands shown in descending order can perform actions such as starting a new process, stopping a running one, suspending, resuming or restarting it.

PowerShell Get-Service

List of open processes

In a similar way we can work with Windows processes. To see a list with all open processes we can use the Get-Process command. With it we can perform certain actions such as:

Start-Process <nombre del proceso> Stop-Process <nombre del proceso> Wait-Service <nombre del proceso>

In the list in descending order, we can start a new process, stop it or put it on hold.

Run UWP apps on Windows

One of the purposes of PowerShell is the ability to run UWP applications quickly, so we can use it to open certain applications or create our own scripts. For this we use the Star-Process command.

For example, if we want to open Windows Settings we use:

Start-Process «ms-settings:»

If what we want is to use a UWP application like Spotify, the command to write would be

Start-Process «spotify:»

In this way, without the need to use the Windows graphical interface, we can run applications both from the system and downloaded from the Microsoft Store.

Related Articles

Leave a Reply

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