Skip to content

Instantly share code, notes, and snippets.

@rfennell
rfennell / Update-WorkitemField.yml
Last active February 7, 2025 11:19
A sample Azure DevOps YAML Pipeline to update WI based on a WIQL query
# A pipeline to update a specific field in a work items that meeting a specific WIQL filter
# Do not trigger on a commit to the repo, but allow a manual run
trigger: none
# Run the pipeline at 1am every day
schedules:
- cron: '1 0 * * *'
displayName: Daily midnight build
always: true
@rfennell
rfennell / Update-WorkitemField.ps1
Created January 30, 2025 11:13
A PowerShell script that used the Azure DevOps CLI to increment a Work Item field based on a WIQL query
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, HelpMessage="The URL of the Azure DevOps organisation e.g. https://dev.azure.com/myorg")]
$org,
[Parameter(Mandatory=$true, HelpMessage="The name of the project e.g 'My Project' ")]
$project,
[Parameter(Mandatory=$false, HelpMessage="The name of the field to update, defaults to 'Custom.PBIAge'")]
$fieldName = "Custom.PBIAge",
[Parameter(Mandatory=$false, HelpMessage="The WIQL query to find the work items to update. This is used if --sharedWiQueryId is not specified")]
$query = "SELECT [System.Id] FROM workitems WHERE ([System.WorkItemType] = 'Bug' OR [System.WorkItemType] = 'Product Backlog Item' ) AND [System.State] IN ('Active', 'Committed')",
@rfennell
rfennell / agent-scheduled-job-yml
Last active August 30, 2024 09:12
Azure DevOps Custom Maintenance Jobs
# This is the pipeline that runs any scheduled maintainance jobs
# we wish to run in addition to the built in Azure DevOps Maintainance jobs
# The parameters to target each pool and agent
parameters:
- name: pool
- name: agent
- name: nvdapikey
# We cannot use to the parameters directly else we get a 'A template expression is not allowed in this context'
@rfennell
rfennell / revert-workitems.ps1
Last active April 17, 2024 14:45
A PowerShell script to revert the values in a specified list of fields for a list of work items returned by a WIQL query
[CmdletBinding()]
<#
.SYNOPSIS
Reverts work items to their previous state in Azure DevOps based on the specified criteria.
.DESCRIPTION
Reverts work items to their previous state in Azure DevOps based on the specified criteria.
@rfennell
rfennell / Copy-GitLabRepoToAzureDevOps.ps1
Last active April 23, 2024 12:35
Copy repos from GitLab to Azure DevOps
<#
.SYNOPSIS
Copies GitLab repositories to Azure DevOps.
.DESCRIPTION
This script retrieves GitLab repositories using the provided GitLab token and copies them to an Azure DevOps project.
.PARAMETER gitlabtoken
Specifies the GitLab token to authenticate with the GitLab API.
Create a personal access token in GitLab by navigating to Profile > Edit Profile > Access Tokens.
@rfennell
rfennell / Copy-LastBlogCommit.ps1
Created March 22, 2024 09:01
When run in a Hugo based Static website Git Repo will copy content to another repo
param (
[string]$blog = "rfennell",
[string]$destination = "C:\projects\bm-source\BMBlogs-Hugo"
)
write-host "Copying last blog commit"
$commandOutput = Invoke-Expression "git diff-tree --no-commit-id --name-only -r HEAD"
foreach ($sourceFile in $commandOutput) {
@rfennell
rfennell / export-tfs-upgate-log-to-csv.ps1
Last active October 5, 2023 10:44
Extracts the timestamps from a TFS/Azure DevOps upgrade log or ease of charting
param
(
$logfile = "TPC\_ApplyPatch.log",
$outfile = "out.csv"
)
# A function to covert the start and end times to a number of minutes
# Can't use simple timespan as we only have the time portion not the whole datetime
# Hence the hacky added a day-1 second
@rfennell
rfennell / DockerCompose.yml
Last active June 6, 2024 15:55
A BICEP file to deploy Snipe IT to Azure - see the comments below for usage details
version: "3"
services:
snipe-it:
image: snipe/snipe-it:latest
volumes:
- snipeit:/var/lib/snipeit
- snipeit-logs:/var/www/html/storage/logs
volumes:
@rfennell
rfennell / run.csx
Created July 14, 2023 12:24
Azure Function code to send a Tweet to the V2 Twitter API using OAUTH1.0
#r "Newtonsoft.Json"
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using OAuth;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
@rfennell
rfennell / Get-NugetPackage.ps1
Last active April 1, 2023 15:39
Downloading NuGet packages with 'System.Net.WebClient' from an Azure DevOps Artifact feed
param(
$package,
$version,
$azdoOrg,
$feedname,
# provide a, Azure DevOps PAT if it a private feed
$pat,
$DestinationPath = "$package-$version.zip"
)