How to delete a group of users in powershell

I have a powershell script which will return a list of usernames that are no longer using Octopus to a variable, this wass quite simple.
The difficulty I am having is a command to delete the users i have in a variable.
Is there a simple command or syntax that can do this?

$usernames

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $OctopusURI,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$repository.Users.Delete($usernames)

The delete method doesnt work,

thanks

B

Hi B,

Thanks for reaching out! You need to pass an Octopus.Model.UserResource object to that method and not just their usernames.

I’d recommend you to take a look at the Powershell module Octoposh, which has a lot of cmdlets to interact with Octopus, including one to delete resources such as users: https://github.com/Dalmirog/OctoPosh/wiki/Deleting-Resources#users

Hope that helps!
Dalmiro