# Using PowerShell with the new v2 ZOOM API

**URL:** https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863
**Category:** API and Webhooks
**Created:** [January 10, 2018, 8:05pm UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863 "2018-01-10T20:05:02Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Test\_SSO](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Test\_SSO](https://devforum.zoom.us/u/Test_SSO)
#### Post date: [January 10, 2018, 8:05pm UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/1 "2018-01-10T20:05:02Z")

</div>

I tend to use PowerShell for most of my admin activities so when I started getting requests to automate things for Zoom I didn’t see any reason to change.&nbsp;&nbsp;

Requiring a JWT token was a little bit of a challenge in PS but since I took the time to figure it out I thought I would share it here.

The function to create a token is:

function Get-ZoomToken  
{  
\<#  
.Synopsis  
Create a JWT token using HMAC-256  
.DESCRIPTION  
Create a JWT token using HMAC-256 for use with the ZOOM version 2 API  
.EXAMPLE  
Get-ZoomToken -api\_key \<zoom api key\> -api\_secret \<zoom api key secret\>  
.AUTHOR  
Anthony Brown ([anthony.brown@asurion.com](mailto:anthony.brown@asurion.com))  
#\>  
[cmdletBinding()]  
param(  
[Parameter(Mandatory=$true)][String]$api\_key,  
[Parameter(Mandatory=$true)][String]$api\_secret,  
[int]$timeout = 15  
)

# Sadly, the easiest way to get these DLLs is to create a new VS project and install Microsoft.IdentityModel.Tokens

# and System.IdentityModel.Tokens.Jwt packages via NuGet and then copy them out of the packages \<navigate to correct .NET version\>

# folder under your VS project directory.

$null = [System.Reflection.Assembly]::LoadFrom(“C:\PS Script\MyAssemblies\Microsoft.IdentityModel.Tokens.dll”)  
$null = [System.Reflection.Assembly]::LoadFrom(“C:\PS Script\MyAssemblies\System.IdentityModel.Tokens.Jwt.dll”)

$SecurityKey = [Microsoft.IdentityModel.Tokens.SymmetricSecurityKey]::new([System.Text.Encoding]::UTF8.GetBytes($api\_secret))  
$credentials = [Microsoft.IdentityModel.Tokens.SigningCredentials]::new($SecurityKey, [Microsoft.IdentityModel.Tokens.SecurityAlgorithms]::HmacSha256)

$header = [System.IdentityModel.Tokens.Jwt.JwtHeader]::new($credentials)  
$payload = [System.IdentityModel.Tokens.Jwt.JwtPayload]::new()

$payload.Iss = “$api\_key”  
$payload.Exp = (Get-Date).AddMinutes($timeout).ToFileTime().ToString()

$secToken = [System.IdentityModel.Tokens.Jwt.JwtSecurityToken]::new($header, $payload)  
$handler = [System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler]::new()

$token = $handler.WriteToken($secToken)

$token  
}

An example of using the token to pull a list of zoom users may look like this:

function Get-ZoomUsers  
{  
[cmdletBinding()]  
param(  
[Parameter(Mandatory=$true)][String]$token  
)  
$headers = @{“Authorization” = “Bearer $token”}

$BaseUri = ‘[https://api.zoom.us/v2/users](https://api.zoom.us/v2/users)’

$page\_number = 1  
$page\_count = 1

$Users = @()

do  
{  
Uri = "($BaseUri)?page\_size=200&page\_number=$page\_number"

$UserList = Invoke-RestMethod -Method Get -Uri $Uri -Headers $headers

$Users += $UserList.users

$page\_number++

Sleep -Seconds .2  
}  
until ($page\_number -gt $UserList.page\_count)

$Users  
}

I hope this is helpful.

---

<div class="post-metadata">

### Author: ![harris\_yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/harris_yang/32/155_2.png) [@harris\_yang](https://devforum.zoom.us/u/harris_yang)
#### Post date: [January 11, 2018, 1:32am UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/2 "2018-01-11T01:32:25Z")

</div>

Hello, you can set the JWT expiration time a little longer, so you don’t need to get JWT token every time.&nbsp;

---

<div class="post-metadata">

### Author: ![Zoom\_Developer](https://avatars.discourse-cdn.com/v4/letter/z/eb8c5e/32.png) [@Zoom\_Developer](https://devforum.zoom.us/u/Zoom_Developer)
#### Post date: [January 11, 2018, 3:50am UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/3 "2018-01-11T03:50:54Z")

</div>

thanks for sharing

---

<div class="post-metadata">

### Author: ![Admin\_Zoom](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@Admin\_Zoom](https://devforum.zoom.us/u/Admin_Zoom)
#### Post date: [July 8, 2018, 12:13pm UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/4 "2018-07-08T12:13:04Z")

</div>

Very helpfull! Thanks!

---

<div class="post-metadata">

### Author: ![georgi.lubomirov](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@georgi.lubomirov](https://devforum.zoom.us/u/georgi.lubomirov)
#### Post date: [June 14, 2019, 12:33pm UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/5 "2019-06-14T12:33:13Z")

</div>

This works great without the DLLs

> **[r/PowerShell - Generate JWT (JSON Web Token) in Powershell](https://www.reddit.com/r/PowerShell/comments/8bc3rb/generate_jwt_json_web_token_in_powershell/)**
>
> 8 votes and 9 comments so far on Reddit

---

<div class="post-metadata">

### Author: ![satwinder.dhillon](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@satwinder.dhillon](https://devforum.zoom.us/u/satwinder.dhillon)
#### Post date: [April 7, 2020, 6:25pm UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/6 "2020-04-07T18:25:56Z")

</div>

thanks Test\_SSO…this helped a lot!

---

<div class="post-metadata">

### Author: ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)
#### Post date: [April 8, 2020, 7:27am UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/7 "2020-04-08T07:27:15Z")

</div>

Hey @satwinder.dhillon,

Happy to hear you found valuable info! 🙂

-Tommy

---

<div class="post-metadata">

### Author: ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)
#### Post date: [August 21, 2020, 8:13pm UTC](https://devforum.zoom.us/t/using-powershell-with-the-new-v2-zoom-api/863/8 "2020-08-21T20:13:38Z")

</div>


