Key Windows PowerShell Commands That You Should Know in the First Place
PowerShell is a very valuable Windows administrator tool that combines the flexibility of a scripting language and the speed of a command line. Recently, Microsoft has set itself the task of ensuring that PowerShell becomes the most preferred management tool. Most new Microsoft products, if not all, require it. What’s more, you cannot accomplish many management tasks without exploring the command line. To become an excellent Windows administrator, you need to fully familiarize yourself with the basics of using PowerShell. Here are the top 10 commands that you should master in order to grow in your career as a Windows administrator. Let’s explore them in detail.
Get-Service is a popular PowerShell command that provides a long list of all the services, which are installed on your system. All you need to do if you are interested in a particular service is to append the -Name switch before adding the name of the service. This way, Windows will show you the state of this service.
Get-Help is the first PowerShell cmdlet you should learn if you are a Windows administrator. This command can be used to help you with any PowerShell command. You can simply type “Get-Help -Name Get-Process” if you don’t know how to use Get-Process. Get-Help can also be used with individual verbs and nouns. For example, if you want to find out which commands you will be able to use with the verb ‘Get’ for a certain program, just type “Get-Help -Name Get”.
Any process can sometimes freeze or stop. In such a case, the Get-Process command can be used to get the process ID or the name of the process, which has stopped responding. After determining which process it is, you can use this command to terminate it. You can stop the process based on its ID PID or name. For instance, if Notepad stops responding, you can close it with Stop-Process using the following commands: “Stop-Process -Name Notepad”, or “Stop-Process -ID 3952”. It’s worth noting that the process ID may change from session to session. That is why it is important to know how to find out this number.
4. Set-Execution Policy
Of course, you can create and also execute PowerShell scripts. However, Microsoft has now disabled scripting by default in order to prevent malicious from being able to execute in the PowerShell environment. The Set-Execution Policy command can be used to control the level of security within the PowerShell scripting surroundings. There are four levels of security that are available to you:
- All Signed – You can set the execution policy to All Signed to run scripts.
- Restricted – This is the default execution policy that blocks PowerShell so that the commands can only be entered interactively.
- Unrestricted – It removes every restriction from the execution policy.
- Remote Signed – When the execution policy has been set to Remote Signed, then any PowerShell scripts, which have been created locally, will be allowed to run. PowerShell scripts that have been remotely created can only run if are signed by a trusted publisher.
You can enter the Set-Execution Policy command and then follow the policy name to set the execution policy. For instance, to allow scripts to run without any restrictions, just type “Set-Execution Policy Unrestricted”.
Get-Process is a basic Windows PowerShell command that is used to display a list of all the processes, which are currently running on the computer.
6. Get-Execution Policy
Get-Execution Policy is among the most popular basic Windows PowerShell cmdlets that every Windows administrator is supposed to familiarize himself/herself with. If you are working on a server that you are not familiar with, you will have to know what execution policy is currently in use before attempting to run the script. If you don’t know how to find out, just use this command.
7. Convert To-HTML
While PowerShell can provide you with a lot of information concerning the system, sometimes you will need to do much more than just relying on the information displayed on your screen. It is very helpful to create a good report that you can send to another person. One of the best ways to accomplish this is to use the Convert To-HTML command. In order to use it, just pipe the output from any other command into it. You will need to use the -Property switch in order to control what output properties should be included in the HTML file. Besides, you will also have to give a filename.
In the same way, it is possible to create an HTML report based on PowerShell data. It is also possible to export your data into the CSV file from PowerShell. You can use Microsoft Excel to open such a file. The syntax is actually similar to one that is used to convert the command’s output to the HTML report. You will need to provide the output filename before exporting data. Or if you want to export a list of system services in your system to the CSV file, you can use “Select-Object” as the command name.
We are sure you have tried using the Export-CSV command. If this is true, you must have realized that there were several properties that were included in the CSV file. It’s usually useful to narrow down everything and include only those properties that interest you. This is actually where this PowerShell command comes in. It allows you to specify the properties that you want to include.
10. Get-Event Log
You can analyze the event log of your computer using PowerShell. There are quite a lot of parameters available, but you can simply try out the PowerShell command by just providing the -Log switch and then confirming the log file name.
Knowing these basic Windows PowerShell commands will help you perform many tasks. But, of course, you need to know more if you want to become a professional.
You must be logged in to post a comment.