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.
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 displays all the commands and features. The Get-command displays all the commands of a specific feature
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.
If you need the information on any item, on any location, Get item is the right command. It does not get content.
Related Article: PowerShell Interview Questions
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.
The invoke WebRequest sends HTTP and HTTPS requests to the web page. It returns links, images and HTML elements.
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.
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.
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.
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.
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.
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.
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.
A stopped process can be used to stop single or multiple running processes. It stops all the instances of a process.
Get-service command displays all the services which are stopped or running. It also provides an option to include or exclude them
The Start service command can be used to start a service on the system followed by the name of the service.
The stop service command is used to stop a command followed by the name of the service.
The Convert-to-HTML command converts the information to HTML reports.
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.
The Export CSV command helps to export PowerShell data to CSV file and open in excel. The output file name should be provided.
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.
The Get-EventLog command can parse the computer log events. The command can be executed by providing command followed by the log file name.
The Clear History command helps to delete specific commands from the command history.
The Where-Object command helps to filter a data set in the PowerShell.
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.
The For-Each Object command performs specific modification or formatting on every item in a specified group of input objects
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.
Related Article: PowerShell Operators
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.
The compare-object command helps to compare two objects directly by generating reports on the differences in the two objects.
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 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.
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 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.
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.
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 received job.
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.
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.
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.
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.
The Start-Sleep command is used to suspend a session or script for a specified period of time.
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:
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.
The remove-event command is used to remove the registered events. We can use the Remove-EventLog command to remove a whole event log.
To subscribe to the events created by the PowerShell engine, we will use this command.
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.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
PowerShell Training | Dec 21 to Jan 05 | View Details |
PowerShell Training | Dec 24 to Jan 08 | View Details |
PowerShell Training | Dec 28 to Jan 12 | View Details |
PowerShell Training | Dec 31 to Jan 15 | View Details |
Madhavi Gundavajyala is a Content contributor at Mindmajix.com. She is passionate about writing articles and blogs on trending technologies, project management topics. She is well-versed on AI & Machine Learning, Big data, IoT, Blockchain, STLC, Java, Python, Apache technologies, Databases.