PowerShell Automation: Scripts for Task Automation

Companies commonly use Microsoft Windows PowerShell to automate most of their administration and configuration procedures, from the simplest tasks to the most complex ones. Task automation provides several advantages to administrators, including eliminating potential human errors and reducing time investment when executing mundane jobs. Process automation offers enterprises the possibility to reach their goals for optimizing efforts. 

Day-to-Day Task Automation Using PowerShell 

Many common management processes can be executed using scripts. The following table shows types of tasks that can be automated with PowerShell: 

Execution time These tasks are typically executed manually, and they usually take a long time to be completed. Examples:

Server Role installation

Software/product installation

Windows Update installation

Repetitive Simple or complex tasks that due to daily operation requirements are frequently repeated. Examples:

Active Directory object management

File transfers

Machine deployments

Remediation Once monitoring tools have reported incidents, remediation tasks can be associated with different alert categories as a first attempt to solve the problem. Examples:

Windows Service stop/start/restart

Machine stop/start/restart

Service failover

Orchestration Different actions need to be scheduled over distinct resource types to successfully complete a task. Examples:

Cold backups

Software or platform migrations

Log or event correlation

PowerShell automation in the cloud

More and more companies are moving their services and resources partially or totally to the cloud. Regardless of the chosen cloud model service, several administration tasks are still required to optimize infrastructure usage and performance. 

In addition to traditional web management consoles, cloud service providers (CSPs) supply a complete set of tools based on PowerShell to manage all their resources and services. Administrators can now manage their cloud setups as they used to manage their legacy environments. 

In 2018, Microsoft released PowerShell Core—a cross-platform version of PowerShell. Microsoft has developed PowerShell Core on top of .NET Core rather than the .NET Framework that classical Windows PowerShell leverages. While Microsoft still supports the legacy Windows PowerShell, the current version (5.1) will not get any new cmdlets added to its framework. This privilege goes to future PowerShell Core releases, starting with version 6.0.  

With PowerShell Core, users can now write and execute scripts across Windows, macOS, Linux, and Advanced RISC Machines (ARM)-based platforms. As such, it is an ideal single scripting tool that IT administrators can use to automate the management of hybrid cloud systems.

Failover Automation Using PowerShell 

A disaster recovery site is a backup datacenter where companies can relocate their services and resources when their primary datacenter becomes temporarily unavailable because of an unforeseen incident.

Many companies choose cloud solutions to host their disaster recovery sites due to their scalability, flexibility and financial savings if a “pay as you go” model is used. Administrators can define different PowerShell tasks to deploy and configure services and resources, reducing business downtime when making the failover to the disaster recovery site. Furthermore, most CSPs offer specific PowerShell modules and procedures to simplify and ease the replication of virtual machines (VMs) between on-premises environments and cloud subscriptions.

Task automation with the Parallels RAS PowerShell SDK

The Parallels® Remote Application Server (RAS) PowerShell SDK provides a complete set of commands to automate the management of a Parallels RAS setup. Nearly all the administration and provisioning tasks can be executed through the command line. Administrators can easily define and automate different scripts to be executed when necessary without having to access the Parallels RAS Console.

Here are a few examples of using the Parallels RAS PowerShell SDK for user-session management and VM deployments.

Session Management

Using the Invoke-RDSSessionCmd cmdlet, administrators can monitor RDS sessions, send messages to the users and disconnect or logoff sessions.

#Send a message to Session ID “10” hosted in RD Session Host Server with ID 5

#To obtain the RD Session Host server ID, use the Get-RDS cmdlet

#To obtain the RDS Session ID, use the Get-RDSStatus cmdlet

Invoke-RDSSessionCmd -RDSId 5 -Command SendMsg -Id 10 -Message "This is a sample message"

New VM quick deployment

A new virtual desktop infrastructure (VDI) desktop based on an existing template can be easily deployed through the New-PubVDIDesktop cmdlet.

#Add published desktop making use of the VDI Template.

New-PubVDIDesktop -Name VDIDesktop -ConnectTo SpecificRASTemplate -VDITemplate $vmTemplate -Persistent $true

A detailed list of use cases and different script examples can be found in the following article Parallels RAS PowerShell SDK.

If you have any questions, please get in touch!


References

Amazon 

Microsoft

Redgate Hub

TechRepublic

Parallels