Getting started - PowerShell


While many casual users know about the Command Prompt, only a few have heard about Windows PowerShell. PowerShell is a much more powerful tool than the Command Prompt. It is also intended to replace the Command Prompt, as it delivers more power and control over the Windows operating system.

Windows PowerShell is a shell initially developed by Microsoft for the purposes of task automation and configuration management . PowerShell is now an open source project, and it can be installed on Windows, macOS, and Linux platforms. PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. Initially a Windows component only, known as Windows PowerShell,

In PowerShell, administrative tasks are generally performed by cmdlets (pronounced command-lets), which are specialized .NET classes implementing a particular operation. These work by accessing data in different data stores, like the file system or registry, which are made available to PowerShell via providers. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and CIM enabling management of remote Linux systems and network devices. PowerShell also provides a hosting API with which the PowerShell runtime can be embedded inside other applications. These applications can then use PowerShell functionality to implement certain operations, including those exposed via the graphical interface. This capability has been used by Microsoft Exchange Server 2007 to expose its management functionality as PowerShell cmdlets and providers and implement the graphical management tools as PowerShell hosts which invoke the necessary cmdlets. Other Microsoft applications including Microsoft SQL Server 2008 also expose their management interface via PowerShell cmdlets.

Yarado has built-in integration for PowerShell, instead of rebuilding automation scripts in RPA simply include and incorporate them. This integration is done via the System.Automation.Dll, which has an extra advantage by eliminating the need for traditional PowerShell to store scripts on disk, making it unsafe to store passwords and secrets.

Exercise 1: Who Am I, get powershell result from script

In this exercise whe are going to use the environment variable username to get the currently logged on user.

Start Yarado and Create a variable ScriptResult

Double Click Powershell in the left Toolbar

As Powershell script use [Environment]::Username

Link script output to %ScriptResult%

Click Save

Click Start to run the task.

The Result should be the current logged on username into the variable %scriptresult%

Exercise 2: Hello My name is:

Change the powershell script to :

$username = [Environment]::UserName

Write-Output "Hello my name is : " " $username"

Click Save and start the task

Double click on the Variable Value % ScriptResult%

The Result

Hello my name is :


Tip When you want to output something from PowerShell always use The Write-Output command ! The Write-host command, only outputs direct to console no output can be collected by Yarado.

Exercise 3: Get the number of notepad processes running

Add a variable processname , with the value Notepad

Start the Notepad App via the Start Menu of Windows

Double Click Step 1.1

Change the powershell script to :

(Get-Process | Where-Object {$_.Name -eq ‘%processname%’}).count

Tip Notice the Yarado variable %processname% in the Powershell Script. Yarado variables are replacing by the values in before the Powershell script is started.

Click Save and start the task

Look at the %ScriptResult% Value, this should be 1, or the amount of notepad processes that are open

Start another Notepad App via the Start Menu of Windows

Start the Task again

Look at the %ScriptResult% Value, this should be 2 or the amount of notepad processes that are open

Exercise 4: Get Files Older Than x days

Add 3 variables

Directory : for example C:\Temp, but choose you’re directory

Days : 15

Edit step 1.1

Powershell script

ls -file %directory% | where { (get-date) - $_.creationtime -gt %days%. }

Click Start to get the result

Double click Variable value of %scriptresult% to display the result