Power of Powershell — Introduction for Testers
What is Power-Shell?
PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework.
PowerShell runs on Windows, Linux, and macOS.
Download Power-Shell for Windows.
https://github.com/PowerShell/PowerShell/releases/download/v7.2.2/PowerShell-7.2.2-win-x64.msi
Once, MSI package is downloaded, Right click on the file and click properties and unlock it as shown below.
Install the MSI and follow the install steps.
Search for Power-Shell and open it its CLI locally.
Now play with the following PowerShell commands
Get-Command will list you the commands you can execute on your system. If you expect a command which is not listed you must install the PowerShell package to install and enable it on the system.
Get-Command
Get-HelpGet-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy Restricted -Scope LocalMachineGet-Service
Get-Service | Where-Object {$_.status -eq "stopped"}get-alias | convertto-html > aliases.htm
invoke-item aliases.htmGet-Process | Export-Csv -Path .\Processes.csv -NoTypeInformation
Get-Content -Path .\Processes.csvGet-EventLog -Log "Application"Get-ProcessStop-Process -processname notepadhistoryClear-History -Command *Get-ExecutionPolicy*Get-Service | Where-Object {$_.Status -eq 'Running'}
Create a string loop in PowerShell.
$employees = @("Bob","Ram","John","Lakshmi")
for ($i=0; $i -lt $employees.Length; $i++){ if ($employees[$i] -eq "Ram") { write-host "Boss $($employees[$i])" } else { write-host "Employee $($employees[$i])" }};
You can follow more commands to get familiar with PowerShell
https://devblogs.microsoft.com/scripting/table-of-basic-powershell-commands/
https://stackify.com/powershell-commands-every-developer-should-know/