10 useful basic PowerShell commands for Windows

Over the past few years, Microsoft has tried to turn PowerShell into one of the comprehensive management tools for Windows.

In recent years, Microsoft has been trying to turn PowerShell into one of the comprehensive management tools for Windows. Most Microsoft server systems recommend that everyone use PowerShell , be able to perform a lot of functions without having to intervene with the Command Prompt as before. For every Windows system administrator, they need to get used to and use PowerShell from the initial basic steps. Here, we will introduce you 10 indispensable commands when starting to get acquainted with PowerShell.

1. Get-Help:

First and foremost, everyone needs to learn about any command and syntax of Get-Help. For example, if you want to check on Get-Process , type the following command:

Get-Help -Name Get-Process

and Windows will display the full syntax. In addition, Get-Help is also used with individual nouns and verbs, for example with the dynamic command from Get:

Get-Help -Name Get- *

2. Set-ExecutionPolicy:

Although you can create and execute different PowerShell scripts, in default mode, Microsoft disables this feature to prevent different types of malicious code from entering the system that can activate itself and Boot in PowerShell environment. Users can apply the Set-ExecutionPolicy command to set up different security levels, specifically with 4 appropriate choices:

- Restricted : this is the system's default policy, all PowerShell statements are locked, the user can only enter the command but cannot execute it.

- All Signed : if you or an administrator sets the All Signed level, the code will be executed, but only with the specified components.

- Remote Signed : security policy at this level, any PowerShell code created inside the local system will be allowed to operate. The codes created via remote are only allowed to run when the attribute is fully assigned.

- Unrestricted : does not apply any form of prohibition in the system.

The general syntax of this command includes the name of the Set-ExecutionPolicy command that follows the policy. Examples are as follows:

Set-ExecutionPolicy Unrestricted

3. Get-ExecutionPolicy:

If you have to work on an unfamiliar server system, you need to know which security policy level policy is being applied before executing any code or command. To do this, use the Get-ExecutionPolicy command.

4. Get-Service:

This command will list all the services that are installed on the system. If you need to learn more about any one service, add -Name and the name of the service, Windows will display the full details and related status.

5. ConvertTo-HTML:

When you need to view or create a full report on the current status and information of the entire system, use the ConvertTo-HTML format conversion function. First, you need to specify the conversion file path after using ConvertTo-HTML , the -Property parameter is responsible for initializing properties in the HTML file, and finally naming the converted file. The general syntax of this command is as follows:

Get-Service | ConvertTo-HTML -Property Name, Status> C: services.htm

6. Export-CSV:

After creating an HTML report based on PowerShell data, you can also extract PowerShell data into a CSV file for use with Microsoft Excel. The general syntax is similar to the above command:

Get-Service | Export-CSV c: service.csv

7. Select-Object:

Using the above commands to learn about the system, you will discover that there are many properties included in the CSV file. This feature is really useful when allowing users to specify fixed attributes in links. For example, to create a CSV file that contains the name of the individual services in the system and the associated status, you can use the following general syntax:

Get-Service | Select-Object Name, Status | Export-CSV c: service.csv

8. Get-EventLog:

Users can fully use PowerShell to analyze events in the system via the log file. There are a few specific parameters for different services, but please experiment by adding -Log in front of the log file name. For example, to view the Application log, use the following command:

Get-EventLog -Log "Application"

However, this syntax is not really common in working situations, when the user can choose between the method to save the report into HTML or CSV format.

9. Get-Process:

Comes with the Get-Service command to display the current list of system services, the Get-Process syntax is used to list all active processes.

10. Stop-Process:

Sometimes, there are services in the system that are in a "suspended" state. For such cases, use the Get-Process command to determine the exact name or ID of the process, and turn off this process with the Stop-Process command. For example, to turn off the NotePad program, type the following command:

Stop-Process -Name notepad

Stop-Process -ID 2668

But be aware because the process ID will change according to the system.