Skip to content

Instantly share code, notes, and snippets.

@rfennell
rfennell / Set-Azure DevOpsBrnachPolicies.ps1
Created November 12, 2021 12:40
Set Azure DevOps All Repositories Branch policies
param
(
[parameter(Mandatory=$true,HelpMessage="The target Azure DevOps Instance")]
$org,
[parameter(Mandatory=$true,HelpMessage="The new project name")]
$projectName,
[parameter(Mandatory=$true,HelpMessage="A PAT with access to target org")]
$pat
@rfennell
rfennell / KeyVaultFilter.yaml
Created February 7, 2023 18:54
An inline task to convert a regex based filter to a comma separated list as required to download Secrets from KeyVault in Azure DevOps
variables:
# the variable used to filter the KeyVault secret list
# This can be a simple prefix and wildcard e.g. 'Config-*''
# Or a more complex regex expression e.g. ^(?:Config-*|Settings-*)
- name: KV-Filter
value: '^(?:Config-*|Settings-*)'
# the variable used to KeyVault name
- name: KV-Name
value: 'bm-kv1'
@rfennell
rfennell / DependancyCheckToSonarCloudConvertor.ps1
Last active September 30, 2022 11:46
Script to convert OWASP Dependency Check Results to a format that can be ingested into SonarCloud
param
(
# The OWASP results XML file
$input = "dependancy-results.xml",
# The SonarCloud generic issue JSON file
$output = "dependancy-results.json",
# The file to associate issues with
$filename = "c:\folder\file.cs"
)
@rfennell
rfennell / Get-AgentPoolForNamedAgent.ps1
Created September 6, 2022 09:20
A sample script that shows how to find the Azure DevOps agent pool for a named agent. Also shows the call required to delete the agent
function Get-AgentPoolForNamedAgent {
param
(
$pat,
$url,
$agentName
)
$patToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))
@rfennell
rfennell / fixalias.ps1
Created July 1, 2022 10:17
A script to update a Hugo content file to provide an alias that matches a Wordpress permalink
$basepath = "C:\tmp\bmBlog\content"
$files = Get-ChildItem -path $basepath -Filter "*.md" -Recurse | % { $_.FullName}
foreach ($file in $files) {
$f = get-item $file
$content = (Get-Content -path $f.FullName)
foreach ($l in $content) {
@rfennell
rfennell / blog2md.js
Created June 25, 2022 10:58
A quick edit to the blog2md (https://github.com/palaniraja/blog2md) tools to place exported posts from a multi site WordPress Server in folders based on the sub site name
'use strict';
/***
Usage: blog2md b|w <BLOGGER/WordPress BACKUP XML> <OUTPUT DIR>
*/
const fs = require('fs');
const os = require('os');
@rfennell
rfennell / Unregister-Agent.ps1
Created December 20, 2019 17:09
Finds an Azure Build agent, takes it off line then removes it registration
param
(
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
$pat,
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance e.g. https://dev.aure.com/myinstance")]
$url,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps Agent Pool name")]
$pool ,
[parameter(Mandatory = $true, HelpMessage = "Based name for agent to search for e.g MyAgent as part of B1MyAgent-123")]
$agentBaseName ,
@rfennell
rfennell / Azure-DevOps-Variables-Sample-yml
Created May 5, 2022 08:47
Example of how to pass variables between Azure DevOps stages
pool:
vmImage: windows-latest
variables:
- name: system.debug
value: true
stages:
- stage: Stage1
jobs:
@rfennell
rfennell / add_issue_to_project
Created October 15, 2021 20:24
A GitHub Actions workflow to add any newly created issues to a Project within a GitHub user (pro or free) account as opposed to a GitHub Enterprise Organisation.in the main sample https://docs.github.com/en/issues/trying-out-the-new-projects-experience/automating-projects
name: Add Issue to project
on:
issues:
types: [opened]
jobs:
track_issue:
runs-on: ubuntu-latest
steps:
- name: Get project data
@rfennell
rfennell / Update-AppConfig.ps1
Created February 13, 2018 09:08
PowerShell script to update an app.config file based on a parameters.xml
function Update-AppConfig
{
[cmdletbinding()]
param
(
[parameter(Mandatory = $true, HelpMessage = "Name of app.exe.config file")]
[string]$AppConfigFile,
[parameter(Mandatory = $false, HelpMessage = "Name of parameters.xml file")]
[string]$ParametersFile = "parameters.xml"