Skip to content

Instantly share code, notes, and snippets.

View michaelkc's full-sized avatar

Michael Christensen michaelkc

View GitHub Profile
@michaelkc
michaelkc / adfs2016cmdlethangrepro.ps1
Last active March 9, 2018 08:33
ADFS v2016 cmdlet hang repro
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
# https://social.technet.microsoft.com/Forums/ie/en-US/8553bfcb-6170-4c25-8cb7-0f83e3bb0370/periodic-hangs-when-using-the-builtin-adfs-powershell-cmdlets-in-adfs-v2016?forum=ADFS
$iterations = 50
$sw = [system.diagnostics.stopwatch]::startNew()
$rpNames = 1..50|ForEach-Object { "HangReproRP$_" }
Write-Verbose "Ensuring repro RPs are created..."
@michaelkc
michaelkc / git-pull-all.ps1
Created March 27, 2018 20:11
Powershell variant of the git-pull-all command, to pull all git repos in subfolders of current folder
$git = "git.exe" # or change to absolute path if not in PATH
$gitRepos = Get-ChildItem -Recurse -Directory | Where-Object { Get-ChildItem $_.FullName -Directory -Hidden -Filter ".git" }
foreach ($gitRepo in $gitRepos)
{
Write-Host "Pulling $($gitRepo.Fullname)"
pushd
cd $gitRepo.Fullname
&$git pull
popd
}
@michaelkc
michaelkc / CallDlbrCommonLoginSecuredServiceWithToken.ps1
Created April 23, 2018 14:52
Call DLBR Common Login secured service from PowerShell
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# config.json example contents:
# {
# "Audience": "<some service audience>",
# "Serviceurl": "<some service url>",
# "Idp": "idp.dlbr.dk",
# "Serviceaccountusername": "<some service account username>",
# "Serviceaccountpassword": "<some service account password>"
@michaelkc
michaelkc / my_git_commits.ps1
Last active March 29, 2019 12:50
List my git commits in the last two months, made to any repo in subfolder
#https://gist.github.com/michaelkc/7dd3ff95d792dd859e5453b2f8547596/#file-my_git_commits-ps1
Set-StrictMode -Version Latest
$git = "C:\Program Files\Git\bin\git.exe"
function Find-GitRepos($root)
{
$blacklist = @("node_modules")
$isGitRepo = Get-ChildItem $root -Hidden -Directory | Where-Object {$_.Name -eq ".git"}
@michaelkc
michaelkc / build.cake
Created October 15, 2019 14:09
A real-world example of using CAKE, TeamCity and Octopus together
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.10.0"
#tool "nuget:?package=NUnit.Extension.TeamCityEventListener&version=1.0.6"
#tool "nuget:?package=JetBrains.dotCover.CommandLineTools&version=2019.2.1"
#tool "nuget:?package=OctopusTools&version=6.12.0"
#addin "nuget:?package=Octopus.Client&version=7.0.4"
#addin "nuget:?package=Newtonsoft.Json&version=12.0.2"
#addin "nuget:?package=Cake.Json&version=4.0.0"
#addin "nuget:?package=Cake.Git&version=0.21.0"
#addin "nuget:?package=Cake.FileHelpers&version=3.2.1"
#addin "nuget:?package=Cake.Http&version=0.7.0"
{
"Name": "Resource Group Creator",
"Id": "1326c8ca-30ea-4438-872b-ed80af0d0474",
"IsCustom": true,
"Description": "Lets you view everything (like reader) and create (but not change) Resource Groups.",
"Actions": [
"*/read",
"Microsoft.Resources/subscriptions/resourceGroups/write"
],
"NotActions": [],
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$git = "git.exe"
$master = "master"
$protectedBranches = "$master|main"
# This script was adapted from ZSH script at
# https://blog.takanabe.tokyo/en/2020/04/remove-squash-merged-local-git-branches/
# It is supplemented with code to track and pull all remote branches, to make sure all
/* Drop all security policies */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'SP' AND category = 0 ORDER BY [name])
WHILE @name is not null
BEGIN
SELECT @SQL = 'DROP SECURITY POLICY [dbo].[' + RTRIM(@name) +']'
EXEC (@SQL)
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsInstallerShell = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installershell.exe"
$vsInstallPath = &$vsWhere -format json|convertfrom-json|select -expand installationPath
foreach ($installPath in $vsInstallPath)
{
$argumentList = "update --passive --norestart --force --installpath `"$installPath`""
Start-Process -FilePath $vsInstallerShell -ArgumentList $argumentList -wait
}
@michaelkc
michaelkc / appInsightsCaps.ps1
Last active May 25, 2022 10:48
Application Insights data ingestion caps
$status = @()
foreach ($sub in Get-AzSubscription)
{
Set-AzContext -Subscription $sub |out-null
foreach ($appInsights in Get-AzApplicationInsights)
{
$details = Get-AzApplicationInsights -Name $appInsights.Name -ResourceGroupName $appInsights.ResourceGroupName -Full
$status+=(
@{
Name = $appInsights.Name