Help with using Audit Logs

Hi all,
I need to trigger a pipeline in GOCD whenever changes are made for a specific project in Octopus. I can see the events(changes) that are made from Audit logs. Do you have an idea how can I use them in Powershell script? Thank you!

Hi @pro.semi,

Thanks for getting in touch!

The easiest way to interact with the server in Powershell is by using the octopus.client.
We have a repository of sample scripts here: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/Octopus.Client/PowerShell

One that may be useful as a starting point for you would be this script that returns all events between a specific date range:

# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll' 

$apikey = 'API-CMPCNOYGUU62FBUJF4GV9IVYG' # Get this from your profile
$octopusURI = 'http://localhost:80' # Your server address


$endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = new-object Octopus.Client.OctopusRepository $endpoint

[System.DateTimeOffset]$after = "1/1/2020"
[System.DateTimeOffset]$before = "1/28/2020"

#Using lambda expression to filter events using the FindMany method
$repository.Events.FindMany(
    {param($e) if(($e.Occurred -gt $after) -and ($e.Occurred -lt $before)){
        $true
        }
    })

I hope this helps, please let me know if you have any further questions.

Best regards,
Paul

Hi Paul,
Thank you for the help. I will try to implement this and then I will inform you.
Cheers!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.