PowerShell commands

PowerShell is a scripting language that helps administrators to automate tasks and manage operating systems like Linux, Windows, macOS, and their processes. It is an open-source command-line shell and scripting language built-in dot net. With the help of PowerShell, the administrator can manage computers from the command line.

The Windows PowerShell commands are known as cmdlets, which will help administrators to manage from the command line. The speed of the command line and the flexibility of the scripting language make PowerShell a valuable administration tool. To appreciate the benefits of working on PowerShell, you must master some basic commands.

PowerShell Commands

Get-Help:

If you are a novice in PowerShell, then you may get into tricky situations. Get-help cmdlet will be your saviour. This cmdlet will provide information about commands, functions, scripts, workflows etc. This command helps you to get working with every other command.

Get-command:

Get-command displays all the commands and features. The Get-command displays all the commands of a specific feature

Invoke command:

Invoke command is simple to use and batch controls the computers. With invoke-command, you can run a command or a script on multiple systems or single system either locally or remotely.

Get-item:

If you need the information on any item, on any location, Get item is the right command. It does not get content.

Invoke-Expression:

The invoke-expression command runs a string as a command and returns the results as expression. Ig the Invoke-Expression command is not used, then the string submitted would return as it is without any change.

Invoke WebRequest:

The invoke WebRequest sends HTTP and HTTPS requests to the web page. It returns links, images and HTML elements.

Set-Execution policy:

The script creation and execution in PowerShell is possible with some security restrictions. The Set-Execution policy helps to switch the security levels. You can use the Set-Execution command followed by the security level (Restricted, Remote Signed, All Signed, or Unrestricted) to execute the Set-Execution policy command.

Copy-Item:

The copy-item command in PowerShell lets the developer copy files and folders from a source file path to the destination file path. The copy-item is applicable to a single file or folder or multiple files and folders. This is possible by using multiple source paths and merging them all to the destination path. By using recurse on copy-parameter to copy all the sub-folders contents recursively.

Remove-Item:

The remove-item command in the Power Shell can be used to delete items from specific locations like files, folders, registry keys, variables, and functions. The Remove-item also gives an option for the parameters to include or exclude.

Get-content:

The Get-content command in the PowerShell is used to get the first five lines of the content. The content can be retrieved without opening the file.

Get-Variable:

The Get-Variable command helps to visualize the value of the variables. The visualization is in a tabular form with include and excludes options using a wild card.

Get-Process:

The Get-process helps to find the running processes on the system just the way task manager does. Get-Processes helps to see the list of the running processes and process further.

Start-Process:

The Start-Process command helps to start single or multiple processes on the local computer. It is a common command that is used to invoke external processes.

Stop-Process:

Subscribe to our youtube channel to get new updates..!

A stopped process can be used to stop single or multiple running processes. It stops all the instances of a process.

Get-Service:

Get-service command displays all the services which are stopped or running. It also provides an option to include or exclude them

Start-Service:

The Start service command can be used to start a service on the system followed by the name of the service.

Stop-Service:

The stop service command is used to stop a command followed by the name of the service.

Convert-to-HTML:

The Convert-to-HTML command converts the information to HTML reports.

Convert-to-XML:

The convert-to-XML command is also called serialization. This command creates an XML based representation of the object. This command is useful for saving the data for future re-use.

Export CSV:

The Export CSV command helps to export PowerShell data to CSV file and open in excel. The output file name should be provided.

Select-Object:

The select-object command specifies the properties to be included in a CSV file. The command helps to narrow down the numerous properties contained in the CSV file.

Get-EventLog:

The Get-EventLog command can parse the computer log events. The command can be executed by providing command followed by the log file name.

Clear History:

The Clear History command helps to delete specific commands from the command history.

Where-object:

The Where-Object command helps to filter a data set in the PowerShell.

Set-AuthenticodeSignature:

The set-Authenticode signature command helps to keep the work-in-production secured, by adding the Authenticode signature to the script or to a file.

For-Each Object:

The For-Each Object command performs specific modification or formatting on every item in a specified group of input objects

Clear content:

The Clear Content command is used to delete specific data from items but retains the item. The command can also be used to clear the contents of a file with a specific extension.

Checkpoint-Computer:

The checkpoint-computer command is useful when a critical program is run or while making major changes. This command can restore up to a certain point specified by the user for 24 hours. If the command is run after 24 hours again, then the previous restore point is maintained.

Compare-Object:

The compare-object command helps to compare two objects directly by generating reports on the differences in the two objects.

ConvertFrom-String data:

The ConvertFrom-String data command is useful when the user wants to save the settings of the script. The others can work on the script without working on the script directly.

Convertto-SecureString:

convertto-SecureString command converts a standard string or a plain text to a secure string. Generally, this command is used in conjunction with the ConvertFrom-String data and read-host command.

Read-Host:

The Read-Host command performs dual functions in the script. It is useful when the script user needs some information. The command pauses the current execution and receives inputs.

Set-Alias:

Set-Alias command as the name suggests, creates an alias for other commands in PowerShell. This function helps to increase the productivity of the user. This is similar to creating short-cuts on keyboards. For example, the note pad can be np.

Receive Job:

The Receive-Job command lets the user view the data stored in the PowerShell job. The Receive job command can be used in conjunction with start Job. The user can troubleshoot the data using Get-Job.

Wait Job:

The wait job suppresses all the jobs and commands until all the jobs running in the background are completed. This command only halts but does not show the results from other jobs. The Wait Job can be implemented in concurrence with the receive job.

Test-Path:

If a user wants to execute a command on a definite file, he would want to verify if that file exists or not to avoid throwing an error. The Test-Path command will return a true value if the file exists or return a false if the file does not exist.

Invoke Troubleshooting pack:

The invoke-troubleshooting pack as the name suggests provides the list of all the troubleshooting packs available on the current system. These troubleshooting packs in PowerShell are a list of scripts that help to diagnose, repair and troubleshoot the common bugs and issues that arise in the system.

Measure-Command:

The Measure-Command object is useful if the output is a time-bound object. This command measures the time length of the script run. The time is displayed in hours, minutes and seconds accurately.

Measure-Object:

The Measure Object calculates how large the object is. The command calculates the numeric properties of the object in terms of characters, words and lines. The command can also perform numeric functions like sum, average, minimum, and maximum.

Start-Sleep:

The Start-Sleep command is used to suspend a session or script for a specified period of time.

New-object:

This command is used for creating an object for the .NET framework or Component Object Model(COM). Example of New-object command is as follows:

New Event:

This command is used to create a new event or event log. In an automation engine assisted by Powershell, it is good to have an event log to log all the PowerShell messages.

Remove-Event:

The remove-event command is used to remove the registered events. We can use the Remove-EventLog command to remove a whole event log.

Register-engine event:

To subscribe to the events created by the PowerShell engine, we will use this command.

Conclusion:

The Microsoft power Shell is a wonderful scripting platform. There are many cmdlets available for the Windows operating system. PowerShell can manage 90% of the Windows operating system.

The capability of PowerShell has extended to the Azure cloud also. PowerShell helps in time reduction and also improves the organization’s CAPEX and OPEX.