Skip to content

Instantly share code, notes, and snippets.

View michaelkc's full-sized avatar

Michael Christensen michaelkc

View GitHub Profile
$profile = $env:userprofile
$winget = "$profile\AppData\Local\Microsoft\WindowsApps\winget.exe"
&$winget install --silent "GitHub.GitHubDesktop"
&$winget install --silent "SublimeHQ.SublimeText.3"
&$winget install --silent "voidtools.Everything"
&$winget install --silent "Ghisler.TotalCommander"
&$winget install --silent "Git.Git"
#&$winget install --silent "LINQPad.LINQPad.8"
#&$winget install --silent "Microsoft.VisualStudioCode"
#&$winget install --silent "Mozilla.Firefox"
@michaelkc
michaelkc / rdpkeepalive.ahk
Created October 6, 2023 08:47
Keep RDP session alive in background
#SingleInstance Force ; replace old instance immediately
SetTitleMatchMode, 2
Loop
{
WinGet, id, List, Remote Desktop Connection
Loop, %id%
{
this_id := id%A_Index%
WinGetTitle, this_title, ahk_id %this_id%
; TrayTip, Found RDP session, %this_title%, 2, 17
@michaelkc
michaelkc / generateSelfSigned.ps1
Created October 3, 2023 09:27
Generate a self signed cert in passwordless pfx and Base64 cer formats (e.g. for Azure service principal authn)
param (
[Parameter(Mandatory = $true)]
[string]$certName
)
$validFrom = Get-Date -Year 2020 -Month 1 -Day 1
$validTo = Get-Date -Year 2099 -Month 1 -Day 1
$cert = New-SelfSignedCertificate -DnsName $certName -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeyProtection None -KeyUsage DigitalSignature,KeyEncipherment -NotBefore $validFrom -NotAfter $validTo
$thumbprint = $cert.Thumbprint
@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
$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
}
/* 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)
$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
{
"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": [],
@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"
@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"}