Otto  background

Introduction to PowerShell

The Swiss Army Knife of Automation

Connect With Us

Start now, and patch, configure, and control all your endpoints in just 15 minutes.

Do you wish you could automate the dull and repetitive tasks you perform on your computer? Do you want to write scripts that can do almost anything imaginable? PowerShell is the answer.

PowerShell is an impactful tool that combines the best features of other popular shells such as BASH, CMD, and Python. It is also a scripting language that lets you create and run scripts to automate your work.

This article offers an overview of PowerShell, what it can do, and how to get started.

What is PowerShell?

PowerShell is a scripting language that lets you create and run scripts to automate your work. Microsoft created PowerShell in 2006 as a way to improve the administration of Windows systems. Since then, it has evolved into a versatile tool for almost any technology you may use. 

For example, you can use PowerShell to:

  • Manage Microsoft Azure, Windows, Exchange, SQL, and other products

  • Interact with third-party services like AWS, VMWare, Google Cloud, etc.

  • Work with standard data formats like CSV, JSON, XML, etc.

  • Create custom functions, classes, modules, and dynamic types

  • Remotely execute commands on multiple machines

  • Build CI/CD pipelines with DSC (Desired State Configuration)

How to use PowerShell?

PowerShell commands are called cmdlets (pronounced “command-lets”). They follow a verb-noun naming convention that makes them easy to remember and discover. For example:

  • Get-Process: Gets information about the processes running on your machine

  • Start-Service: Starts one or more services

  • New-Item: Creates a new item such as a file or a folder

  • Invoke-RestMethod: Sends an HTTP request to a web service and parses the response

You can use the Get-Help cmdlet to get more information about any cmdlet or topic. For example,

Get-Help Get-Process

Executing the script will show you the syntax, parameters, examples, and other details about the Get-Process cmdlet. In addition, the pipeline lets you chain multiple commands by passing the output of one command to another. This way, you can perform complex operations with simple commands.

Get-Process | Where-Object {$_.CPU -gt 10} | Sort-Object CPU -Descending | Select-Object -First 5

This command will get all the processes running on your machine, filter them by CPU usage greater than 10%, sort them by CPU usage in descending order, and select the top 5 processes. The output will look something like this:

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
   1319      77   224812     258832   1,234.45   1234   1 chrome
    987      54   123456     145678     789.01   5678   1 firefox
    654      32    87654      98765     456.78   9012   1 edge
    321      21    54321      65432     123.45   3456   1 notepad
    210      15    32109      43210      67.89   7890   1 powershell

As you can see, the pipeline is a powerful way to manipulate data and perform tasks with minimal code.

How to write PowerShell scripts?

PowerShell scripts are files that contain PowerShell commands and expressions. As customary to learning any new computer language, let’s start by making the computer print “Hello World.”

First, we’ll create a script with the file name hello and an extension of ps1. The script contains the following code:

Write-Host "Hello, world!"

You can execute the Powershell scripts by running the ”pwsh” command with the script name as an argument.

pwsh hello.ps1

This command will execute our newly created Powershell script “hello.ps1” and print “Hello, world!” to the console.

Also, Automox Worklets let you automate and execute PowerShell scripts to perform actions like those listed above or install or uninstall applications as advised below. And Worklets can be written once and applied to all your endpoints.

Installing and uninstalling applications is crucial for IT administrators to maintain a secure and stable IT environment. Applications are critical to perform various tasks, such as productivity, collaboration, and security, and to ensure they are up to date with the latest security patches and bug fixes. However, when an application is no longer needed or conflicts with other software, the administrator will uninstall the application.

Don’t have access to the Automox console? Sign up below for your free trial to get this content and much more.

When managing multiple devices in an organization, manually installing and uninstalling applications can be time-consuming. Therefore, automating these processes using PowerShell scripts can save IT administrators time and effort.

PowerShell scripts provide a customizable and repeatable process for installing and uninstalling applications, allowing administrators to deploy and remove software quickly and efficiently.

Dive deeper into this topic

loading...