What is PowerShell?
Windows PowerShell is an object-oriented command environment that has scripting language features that use a program called cmdlets to simplify the administration, configuration, and management of various environments in both remote and standalone topologies by using standard-based remote protocols.
How to open PowerShell?
Click on Start and search for PowerShell.
PowerShell is supported by various platforms:
Platform | Version- 7.0 | Version- 7.1 |
Windows 8.1 and 10 | Yes | Yes |
Windows Server 2012 R2, 2016, 2019 | Yes | Yes |
Ubuntu 16.04, 18.04 | Yes | Yes |
Ubuntu 20.04 | No | Yes |
Debian 9, 10 | Yes | Yes |
CentOS 7,8 | Yes | Yes |
Red Hat Enterprise Linux 7, 8 | Yes | Yes |
Fedora 31+ | Yes | No |
MacOS 10.13+ | Yes | Yes |
Role in Automation:
PowerShell is used as a scripting tool. The major benefit of using PowerShell is its ability to remotely connect to another system. Any admin can use powershell to remotely connect to any servers which are not physically in the same location and can run commands as required. The various administrative tasks can be performed remotely which saves hours of time for IT professionals.
It is used to create scripts. The scripts are saved in .ps1 file format. These scripts are then used with the task scheduler to run the script at the desired time and without user intervention.
Example: In the below script, we are saving a timestamp in a file. And used that file, to create a task.
Get-Date | Out-File C:\Users\Administrator\Documents\log.txt -Append
Get-PSDrive -PSProvider FileSystem | Out-File C:\Users\Administrator\Documents\log.txt -Append
The script is saved as log.ps1.
In the below script, a task is created using the above file i.e. log.ps1
Now to verify, open the task scheduler, and check if the task is created or not. To open the task scheduler, click on Windows and search for the task scheduler.
This task will run on a system startup.
The task ran successfully.
From basic automation to advanced scripting, PowerShell can provide an excess of opportunities for simplifying tasks and saving time. PowerShell scripting is used to simplify many areas of an IT environment including server configuration and deployment, user creation and auditing, and administrative tasks.