PowerShell commands are a versatile scripting language developed by Microsoft for managing and automating tasks in the Windows operating system.
Whether you are a seasoned IT professional or a beginner, mastering some basic PowerShell commands can significantly enhance your productivity and make system administration more efficient.
In this article, we will explore ten fundamental PowerShell commands that every Windows user should know.
10 Basic PowerShell Commands (Cmdlets) in Windows
Do you still have access to the Windows Task Manager, which lists all of your running services, programs, and processes?
The Get-Process cmdlet is a straightforward yet crucial function that enables you to quickly access all of your computer’s processes without opening Task Manager.
The Get-Process PowerShell commands allow you to view all the currently running processes on your Windows machine. This is useful for monitoring system resources and identifying resource-hungry applications.
PowerShell commands also enables you to view every service that is currently active on your system, similar to the Get-Process cmdlet. You can view all services, such as a database server or an application that regulates your computer screen’s brightness, using the Get-Service cmdlet.
With Get-Service, you can retrieve a list of all services running on your system. Services are background processes that perform various system tasks. This command helps you check the status of services and manage them efficiently.
The Get-ChildItem command, often abbreviated as ls or dir, lists the contents of a directory (folder) on your computer. It provides information about files, folders, and other items within the specified directory.
You may occasionally need to switch directories, such as when executing a script or program from a particular place. Use the Set-Location cmdlet to assist you. The directory you give in a command becomes the current working directory thanks to the Set-Location cmdlet.
The Set-Location command allows you to change the current working directory in the PowerShell session. It is similar to the cd command in traditional command prompts.
In PowerShell commands, the New-Item cmdlet is used to create a new item, such as a file, folder (directory), registry key, or any other type of item that is supported by the underlying provider. It is a versatile command that allows users to automate the process of creating new resources within the Windows operating system.
New-Item [-Path] [-ItemType ] [-Name ] [-Value ] [-Force] [-Credential ]
-Path: Specifies the path where the new item will be created.
-ItemType: Specifies the type of item to create (e.g., File, Directory, RegistryKey, etc.).
-Name: Specifies the name of the new item.
-Value: Specifies the value to set for the new item (e.g., when creating a registry key with a specific value).
-Force: If specified, the cmdlet creates the item even if a file or folder with the same name already exists.
-Credential: Specifies a user account that has permission to create the item in a location where the current user may not have sufficient rights.
In PowerShell commands, the Copy-Item cmdlet is used to copy files and directories from one location to another. It allows users to duplicate data effortlessly and is a powerful tool for managing files and organizing data within the Windows operating system.
Copy-Item [-Path] [[-Destination] ] [-Container] [-Force] [-Recurse] [-Filter ] [-Include ] [-Exclude ] [-PassThru] [-Credential ]
-Path: Specifies the path of the item(s) to be copied.
-Destination: Specifies the destination path where the item(s) will be copied. If not provided, the current location will be used as the destination.
-Container: Indicates that the cmdlet should treat the source as a container (e.g., a directory) and copy its contents instead of the container itself.
-Force: If specified, the cmdlet overwrites existing files in the destination without prompting for confirmation.
-Recurse: If specified, the cmdlet copies items in subdirectories recursively.
-Filter: Specifies a filter for the items to be copied based on their names.
-Include: Specifies an array of patterns that dictate which items should be included during the copy operation.
-Exclude: Specifies an array of patterns that dictate which items should be excluded during the copy operation.
-PassThru: If specified, the cmdlet returns the objects that were copied rather than just displaying the operation details.
-Credential: Specifies a user account that has permission to copy items in locations where the current user may not have sufficient rights.
In PowerShell, the Export-Csv cmdlet is used to export data from PowerShell objects to a Comma-Separated Values (CSV) file format. CSV files are a widely used and simple way to represent tabular data, where each line of the file corresponds to a row in the table, and the values within each row are separated by commas.
Export-Csv [-Path] [-Delimiter ] [-NoTypeInformation] [-Encoding ]
-Path: Specifies the file path where the CSV data will be saved. If the file already exists, Export-Csv will overwrite it. If the file doesn’t exist, a new one will be created.
-Delimiter: Specifies the character used to separate the values in the CSV file. The default delimiter is a comma (,), but you can use other characters such as semicolon (;) or tab (t).
-NoTypeInformation: If specified, the cmdlet will exclude the type information from the output CSV file. By default, the CSV file includes the type information as the first row, which can be useful when importing the CSV data back into PowerShell.
-Encoding: Specifies the character encoding used for the output CSV file, such as ASCII, UTF8, UTF32, Unicode, etc.
You may find the instructions you need to run any command correctly and error-free with the Get-Help cmdlet. Consider it the manual for each PowerShell command.
To read comprehensive (-comprehensive) information about a command, such as the Get-ExecutionPolicy cmdlet, open PowerShell as an administrator and use the Get-Help command listed below.
Get-Help is a fundamental command that provides information about other PowerShell commands. It helps you understand how to use a specific command and its parameters.
All of the PowerShell commands that are accessible to you are essentially listed in a table manner by the Get-Command cmdlet. However, as you’ve seen in the preceding examples, the Get-Command is capable of much more, as you are aware.
Maybe you wish to selectively list the aliases or cmdlets. If so, you may filter the result by the command type you provide by adding the -CommandType parameter to the Get-Command cmdlet. A Cmdlet, Function, or Alias value can be specified for the -CommandType option.
Get-Command allows you to retrieve a list of all available PowerShell commands on your system. This can be helpful when you’re exploring new commands or trying to find a command that accomplishes a specific task.
It might be necessary to review your recent commands, for example, to confirm whether the most recent command you ran was accurate or whether you actually issued a command.
But does PowerShell have a history of commands? Yes! In your current PowerShell session, the Get-History cmdlet provides an object listing all of your most recent commands.
The Get-History command displays the command history for your current session. You can use this command to recall previously executed commands and rerun them as needed.
These ten basic PowerShell commands provide a solid foundation for managing and automating tasks in Windows. As you become more comfortable with PowerShell, you can explore more advanced commands and scripting techniques to streamline your workflow even further.
Always exercise caution when running PowerShell commands, especially those involving file manipulation or system changes, as they can have significant consequences on your computer. It’s advisable to test commands in a controlled environment before applying them to critical systems. Happy scripting!