Basic PowerShell commands that every Windows 10 user should know
Bernard Aybout
PowerShell is a powerful scripting language and command-line shell that is built into Windows. It’s designed for system administration, automation, and configuration management. For Windows 10 users, especially those with an interest in managing their system more efficiently or automating tasks, knowing a few basic PowerShell commands can be very helpful. Here are some essential PowerShell commands that every Windows 10 user should be familiar with:
Get-Help: Before diving into other commands, it’s crucial to know how to get help. The Get-Help command can be used to find information about PowerShell commands and syntax. For example, Get-Help Get-Process would provide details on how the Get-Process command works.
Get-Command: To discover the commands available in PowerShell, you can use the Get-Command command. This is particularly useful for beginners to explore what commands are at their disposal.
Get-Process: This command allows you to view all the running processes on your system. It’s similar to the Task Manager in Windows but gives you a way to monitor these processes through the command line.
Start-Process and Stop-Process: These commands allow you to start and stop processes, respectively. For instance, Start-Process notepad would open Notepad, and Stop-Process -Name notepad would close it.
Set-ExecutionPolicy: By default, PowerShell restricts the execution of scripts for security reasons. To run scripts, you might need to change the execution policy using the Set-ExecutionPolicy command, for example, Set-ExecutionPolicy RemoteSigned.
Get-Service: This command displays all the services installed on the system, showing their status as Running, Stopped, or Paused. You can also start, stop, or pause services with the Start-Service, Stop-Service, and Suspend-Service commands.
Get-Item: Allows you to get the item at a specific location. This command is not restricted to files and folders but can also work with registry keys, environmental variables, etc.
Copy-Item, Remove-Item, Rename-Item: These commands allow you to manipulate files and directories—copying, removing, and renaming them, respectively.
Get-Content and Set-Content: To read and write content to a file, you can use Get-Content and Set-Content. For example, Get-Content log.txt would display the content of log.txt, and Set-Content log.txt -Value "New content" would overwrite log.txt with “New content”.
Select-String: This command is used for searching within files for specific patterns, similar to grep in Linux/UNIX.
Get-EventLog: Useful for viewing Windows event logs from the command line. For example, Get-EventLog -LogName Application would show entries from the Application log.
Update-Help: PowerShell’s help system is not fully downloaded by default. Running Update-Help downloads the latest help files for PowerShell commands, ensuring that Get-Help provides you with the most up-to-date information.
These commands only scratch the surface of what PowerShell can do, but they are a good starting point for anyone looking to become more proficient in managing and automating tasks in Windows 10. Remember, the Get-Help command is your best friend when learning PowerShell; use it often to explore and understand the capabilities of different commands.
For those ready to delve deeper into PowerShell’s capabilities, here are 10 more advanced commands that can significantly enhance your scripting and system management skills:
Invoke-Command: This command is used to run scripts or commands on remote computers. It’s extremely powerful for managing multiple machines at once. For example, Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-Service} runs Get-Service on Server01 and Server02.
ConvertTo-Json and ConvertFrom-Json: These commands are invaluable when working with JSON data. You can convert PowerShell objects to JSON format and vice versa, facilitating integration with web APIs and other data sources that use JSON.
Export-Csv and Import-Csv: These commands allow you to export objects to a CSV file and import objects from a CSV file, respectively. This is particularly useful for data manipulation and reporting tasks.
Select-Object: This command is used for selecting specific properties of objects or for creating new custom objects. It’s handy for filtering data or simplifying output.
Where-Object: Allows you to filter objects based on their properties. It’s the PowerShell equivalent of applying a “where” clause in SQL or a filter in Excel.
ForEach-Object: This command iterates over each item in a collection of objects, allowing you to perform operations on each object. It’s similar to a “for each” loop in programming languages.
New-Object: With this command, you can create instances of .NET objects. This can be useful for utilizing .NET libraries and capabilities within your PowerShell scripts.
Get-WmiObject/Get-CimInstance: These commands are used to access Windows Management Instrumentation (WMI) and Common Information Model (CIM) data. This data provides a wealth of information and control over hardware, operating systems, and installed applications. Get-CimInstance is the newer cmdlet that uses the WS-Management protocol, which is more secure and efficient than the DCOM protocol used by Get-WmiObject.
Test-Path: This command checks the existence of a file, folder, or registry key, returning True or False. It’s very useful for conditional statements in scripts to verify if a particular item exists before proceeding.
New-PSDrive: This command creates temporary and persistent mapped network drives. Beyond network drives, it can also be used to create drives that are mapped to other data stores, like the registry or a certificate store, providing a unified interface to access different types of data.
These advanced commands offer a glimpse into the power and flexibility of PowerShell for automating complex tasks, managing systems, and manipulating data. Remember, the versatility of PowerShell lies in its ability to integrate with a wide range of technologies and data types, making it an invaluable tool for administrators, developers, and IT professionals.
Basic PowerShell commands that every Windows 10 user should know: Windows PowerShell is powerful and can do almost everything that a person wants on his computer. But the only problem is that it is a command line tool and does not have GUI. However, it can be helpful when the GUI based interface fails or stops responding. The main thing unfortunately is the fact that a normal user lacks the knowledge of using PowerShell to its full potential. But today, we will be trying to discuss the top 10 PowerShell commands that can help a user do more on Windows 10.
Basic PowerShell commands that every Windows 10 user should know
Before we begin, we must highlighted that some of these cmdlets might toggle certain settings or configuration on your computer.
cmdlets are great tools which can be used to launch UWP Applications within seconds. But the main thing lies in the proper execution of a command. You can use:
Start-Process "ms-settings:"
This command launches the Windows Settings UWP Application. You can learn more about other URIs for other UWP Applications here on microsoft.com.
If you are ever stuck confused about what command you must be used to execute a specific task. Or what a specific cmdlet does, you do not need worry. You can just use the Get-Help cmdlet to do it. You can use it in the following ways:
Here, the first entry will guide you on how to use this cmdlet. The second entry will give you a simple summary of the particular cmdlet. The third entry will give detailed information about the respective cmdlet. The fourth entry will comprise of everything that the third cmdlet shows but will add an example of how to use that cmdlet. And finally, the fifth cmdlet will list every command that is available for your use.
Basic PowerShell commands that every Windows 10 user should know
3] Get Similar Commands
To find commands of a similar type or that contain a particular phrase in them, you can use the Get-Command cmdlet. However, it does not list out every cmdlet in PowerShell, so you make use of some particular filters. You can use the following commands:
The first cmdlet will help you in finding a cmdlet with a particular phrase in it whereas the second one will enable you to filter out cmdlets that perform a particular function.
Basic PowerShell commands that every Windows 10 user should know
5] Read the contents of a file
If you need to read the contents of a file, you can use the Get-Contentcommand as follows:
Get-Content <PATH of the file with its extension>
This particular example above is the Windows Hosts file. Notice we use $env:SystemRoot in place of C: (drive) and C:\WINDOWS (windows folder). The reason for this is because the drive/network letter and windows installation folder are all user dependant, therefor the system environment variable holds this information.
Basic PowerShell commands that every Windows 10 user should know
6] Read information about all the services on a computer
You can use the Get-Servicecmdlet to list all the services running or stopped on your computer. Alternatively, you can use the following related cmdlets to do their respective functions:
Basic PowerShell commands that every Windows 10 user should know
7] Read information about all the processes on a computer
Similar to the Get-Servicecmdlet, you can use the Get-Processcmdlet to list all the Processes running on your computer. Alternatively, you can use the following related cmdlets to do their respective functions:
Basic PowerShell commands that every Windows 10 user should know
8] Setting the Execution Policy
While there is support for creating and executing scripts on PowerShell, there are restrictions to each one of them as a part of some security measures. You can toggle the Security level to any of the 4 levels. You can use the Set-ExecutionPolicy cmdlet followed by any of the security levels given as follows:
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy All Signed
Set-ExecutionPolicy Remote Signed
Set-ExecutionPolicy Restricted
Here, the policies from top to bottom range from lowest to the highest level of security.
Basic PowerShell commands that every Windows 10 user should know
10] Delete a file or a directory
Similar to the Copy-Item cmdlet, A user can make use of the Copy-Item cmdlet to copy one file or directory to another destination. The syntax for this cmdlet is as follows:
Get-Help: Before diving into other commands, it’s crucial to know how to get help. The Get-Help command can be used to find information about PowerShell commands and syntax. For example, Get-Help Get-Process would provide details on how the Get-Process command works.
Get-Command: To discover the commands available in PowerShell, you can use the Get-Command command. This is particularly useful for beginners to explore what commands are at their disposal.
Get-Process: This command allows you to view all the running processes on your system. It’s similar to the Task Manager in Windows but gives you a way to monitor these processes through the command line.
Start-Process and Stop-Process: These commands allow you to start and stop processes, respectively. For instance, Start-Process notepad would open Notepad, and Stop-Process -Name notepad would close it.
Set-ExecutionPolicy: By default, PowerShell restricts the execution of scripts for security reasons. To run scripts, you might need to change the execution policy using the Set-ExecutionPolicy command, for example, Set-ExecutionPolicy RemoteSigned.
Get-Service: This command displays all the services installed on the system, showing their status as Running, Stopped, or Paused. You can also start, stop, or pause services with the Start-Service, Stop-Service, and Suspend-Service commands.
Get-Item: Allows you to get the item at a specific location. This command is not restricted to files and folders but can also work with registry keys, environmental variables, etc.
Copy-Item, Remove-Item, Rename-Item: These commands allow you to manipulate files and directories—copying, removing, and renaming them, respectively.
Get-Content and Set-Content: To read and write content to a file, you can use Get-Content and Set-Content. For example, Get-Content log.txt would display the content of log.txt, and Set-Content log.txt -Value "New content" would overwrite log.txt with “New content”.
Select-String: This command is used for searching within files for specific patterns, similar to grep in Linux/UNIX.
Get-EventLog: Useful for viewing Windows event logs from the command line. For example, Get-EventLog -LogName Application would show entries from the Application log.
Update-Help: PowerShell’s help system is not fully downloaded by default. Running Update-Help downloads the latest help files for PowerShell commands, ensuring that Get-Help provides you with the most up-to-date information.
Invoke-Command: This command is used to run scripts or commands on remote computers. It’s extremely powerful for managing multiple machines at once. For example, Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-Service} runs Get-Service on Server01 and Server02.
ConvertTo-Json and ConvertFrom-Json: These commands are invaluable when working with JSON data. You can convert PowerShell objects to JSON format and vice versa, facilitating integration with web APIs and other data sources that use JSON.
Export-Csv and Import-Csv: These commands allow you to export objects to a CSV file and import objects from a CSV file, respectively. This is particularly useful for data manipulation and reporting tasks.
Select-Object: This command is used for selecting specific properties of objects or for creating new custom objects. It’s handy for filtering data or simplifying output.
Where-Object: Allows you to filter objects based on their properties. It’s the PowerShell equivalent of applying a “where” clause in SQL or a filter in Excel.
ForEach-Object: This command iterates over each item in a collection of objects, allowing you to perform operations on each object. It’s similar to a “for each” loop in programming languages.
New-Object: With this command, you can create instances of .NET objects. This can be useful for utilizing .NET libraries and capabilities within your PowerShell scripts.
Get-WmiObject/Get-CimInstance: These commands are used to access Windows Management Instrumentation (WMI) and Common Information Model (CIM) data. This data provides a wealth of information and control over hardware, operating systems, and installed applications. Get-CimInstance is the newer cmdlet that uses the WS-Management protocol, which is more secure and efficient than the DCOM protocol used by Get-WmiObject.
Test-Path: This command checks the existence of a file, folder, or registry key, returning True or False. It’s very useful for conditional statements in scripts to verify if a particular item exists before proceeding.
New-PSDrive: This command creates temporary and persistent mapped network drives. Beyond network drives, it can also be used to create drives that are mapped to other data stores, like the registry or a certificate store, providing a unified interface to access different types of data.
Get-Help
Use: Retrieves documentation about PowerShell commands.
Example: Get-Help Get-Process
Get-Command
Use: Lists all commands available in PowerShell.
Example: Get-Command -Noun Process
Get-Process
Use: Gets the processes running on the computer.
Example: Get-Process -Name notepad
Start-Process
Use: Starts one or more processes on the local computer.
Example: Start-Process notepad.exe
Stop-Process
Use: Stops one or more running processes.
Example: Stop-Process -Name notepad
Set-ExecutionPolicy
Use: Changes the user preference for PowerShell script execution.
Get-Credential – Use: Prompts the user for a username and password and creates a credential object. – Example: $cred = Get-Credential
New-ScheduledTask – Use: Creates an object that represents a scheduled task. – Example: $action = New-ScheduledTaskAction -Execute 'Notepad.exe'; New-ScheduledTask -Action $action -Trigger (New-ScheduledTaskTrigger -AtLogon)
Register-ScheduledTask – Use: Registers a scheduled task definition on a local computer. – Example: Register-ScheduledTask -TaskName "MyTask" -InputObject $task
Export-PfxCertificate – Use: Exports a certificate to a PFX file. – Example: Export-PfxCertificate -Cert cert:\LocalMachine\My\ -FilePath "C:\cert.pfx" -Password (ConvertTo-SecureString -String "password" -Force -AsPlainText)
Import-PfxCertificate – Use: Imports a certificate from a PFX file to a certificate store. – Example: Import-PfxCertificate -FilePath "C:\cert.pfx" -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String "password" -Force -AsPlainText)
Get-Certificate – Use: Retrieves a certificate from a local or remote certificate store. – Example: Get-Certificate -DnsName "www.example.com" -CertStoreLocation "Cert:\LocalMachine\My"
New-SelfSignedCertificate – Use: Creates a new self-signed certificate for testing purposes. – Example: New-SelfSignedCertificate -DnsName "www.example.com" -CertStoreLocation "Cert:\LocalMachine\My"
Test-Certificate – Use: Tests a certificate and certificate chain for validity. – Example: Test-Certificate -CertPath "C:\cert.cer"
Compare-Object – Use: Compares two sets of objects. – Example: Compare-Object -ReferenceObject $(Get-Content file1.txt) -DifferenceObject $(Get-Content file2.txt)
Group-Object – Use: Groups objects that contain the same value for specified properties. – Example: Get-Process | Group-Object -Property ProcessName
Sort-Object – Use: Sorts objects by property values. – Example: Get-Process | Sort-Object -Property CPU -Descending
Tee-Object – Use: Saves command output in a file or variable and also sends it down the pipeline. – Example: Get-Process | Tee-Object -FilePath processes.txt
Write-Output – Use: Sends the specified objects to the next command in the pipeline. – Example: Write-Output "Hello, World!"
Write-Host – Use: Writes customized output to a host/screen. – Example: Write-Host "Hello, World!" -ForegroundColor Cyan
Write-Warning – Use: Writes a warning message. – Example: Write-Warning "This is a warning message."
Write-Error – Use: Writes an error message to the error stream. – Example: Write-Error "This is an error message."
Write-Verbose – Use: Writes text to the verbose message stream. – Example: Write-Verbose "This is a verbose message." -Verbose
Write-Debug – Use: Writes debug information to the console. – Example: Write-Debug "Debugging information."
Start-Transcript – Use: Starts a transcript of all subsequent commands in the session. – Example: Start-Transcript -Path "C:\transcript.txt"
Stop-Transcript – Use: Stops the transcription process. – Example: Stop-Transcript
Get-HotFix – Use: Retrieves information about Windows updates installed on the computer. – Example: Get-HotFix
Add-Content – Use: Appends content to a specified item (e.g., a file). – Example: Add-Content -Path "log.txt" -Value "New log entry"
Checkpoint-Computer – Use: Creates a system restore point on the local computer. – Example: Checkpoint-Computer -Description "Pre-Upgrade Snapshot"
Get-ComputerInfo – Use: Retrieves a comprehensive set of system properties and configurations. – Example: Get-ComputerInfo
Get-Counter – Use: Retrieves live performance counter data from local or remote computers. – Example: Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 2 -MaxSamples 5
Get-Culture – Use: Retrieves information about the current culture settings. – Example: Get-Culture
Get-Date – Use: Gets the current date and time. – Example: Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Set-Date – Use: Sets the system date and time. – Example: Set-Date -Date "2024-03-15 8:00 AM"
Get-DscConfiguration – Use: Retrieves the current configuration from a node. – Example: Get-DscConfiguration
Start-DscConfiguration – Use: Applies Desired State Configuration (DSC) configurations to nodes. – Example: Start-DscConfiguration -Path .\Configuration -Wait -Verbose
Get-EventSubscriber – Use: Lists event subscribers in the current session. – Example: Get-EventSubscriber