Skip to content

quickstart powershell

github-actions edited this page Mar 15, 2023 · 1 revision

Getting started with PSWattTime

Steps for using the module in PowerShell

To get started with this module you will need an account on WattTime. See the manual on registering an account. The module provides a function New-WattTimeAccount to create an account if you do not yet have one.

You will also need the Az.Resources PowerShell Module for Azure installed and connected to your Azure account. See the installation manual for the Az module for instructions.

To install the module from the PowerShell Gallery.

Install-Module -Name PSWattTime

To register an account with WattTime:

New-WattTimeAccount -Username <YOUR_USERNAME> `
  -Password '<YOUR_PASSWORD>' `
  -Email '<[email protected]>' `
  -Organization <YOUR_ORGANIZATION>

Authenticate to the WattTime API:

 $token = Get-WattTimeAuthToken -Username '<YOUR_WATTTIME_USERNAME>' `
  -Password '<YOUR_WATTTIME_PASSWORD>'

Get current percentage of energy with emissions the 'westeurope' Azure region:

PS C:\> Get-WattTimeForAzureRegion -Region westeurope -AuthToken $token

ba         : NL
freq       : 300
percent    : 94
point_time : 5-3-2023 13:15:00
region     : westeurope

Determine the lowest emissions for the list of northeurope, westeurope, francecentral and uksouth Azure regions:

PS C:\> Get-AzureRegionWithLowestWattTime -Regions westeurope,uksouth,northeurope,francecentral -AuthToken $token

ba         : IE
freq       : 300
percent    : 69
point_time : 5-3-2023 14:15:00
region     : northeurope

Module Functions