Skip to content

Instantly share code, notes, and snippets.

View deadlydog's full-sized avatar

Daniel Schroeder deadlydog

View GitHub Profile
@deadlydog
deadlydog / Import-PfxCertificate.ps1
Last active January 28, 2022 20:03
PowerShell script that imports a .pfx certificate file. Useful to do before building the solution on a build server. For more info, see https://blog.danskingdom.com/creating-a-pfx-certificate-and-applying-it-on-the-build-server-at-build-time/
param([string] $PfxFilePath, $Password)
# You may provide a [string] or a [SecureString] for the $Password parameter.
$absolutePfxFilePath = Resolve-Path -Path $PfxFilePath
Write-Output "Importing store certificate '$absolutePfxFilePath'..."
Add-Type -AssemblyName System.Security
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($absolutePfxFilePath, $Password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet")
@deadlydog
deadlydog / PowerShell bug reproduction code.ps1
Last active March 10, 2022 04:35
Paste this into the PowerShell command line and you'll get an odd `An error occurred while creating the pipeline` error. Remove one "d" from the end and you'll get the expected `Get-Something is not recognized as a name of a cmdlet` error. This info is related to this tweet: https://twitter.com/deadlydog/status/1500295904615702531?s=20&t=7XvHRhT…
Get-Something dslkfjds lkjfdsl jflkdsfljdsalkf dslkf jlkdsjf lkdsj fljds lkf jdsalkf dslkfj dslfj lkdsjf ldskj flkds jflkjds lkf jdslfk jdsalkf jds jflkds jflkdsjflkds flkjdsflk jdslkf lkdsjflkdsj fljds lkf jdslfj sldjf kds flk jdsfl dsf dsljf ds jfhds lf jdsjf dsljflkds jfsjldsj fl jdsflkjdsflkjds dsfadsf dd
@deadlydog
deadlydog / MigrateIisAppsAndConfigurationToOtherServer.cmd
Created November 17, 2022 16:24
Migrate IIS Apps And Configuration ToOther Server
:: This script will migrate all of the IIS Applications and Configuration from the local server to the destination server.
:: This script needs to be ran from the source server that has the IIS configuration that you want to migrate.
:: MsDeploy will often generate a lot of output, so it's best to remote desktop onto the server that you want to migrate,
:: rather than running this command via PowerShell Remoting, as it will take a very long time to pipe the output back to
:: your local machine.
:: The server you are syncing to must also have Web Deploy installed on it. You can download it from:
:: http://www.microsoft.com/en-ca/download/details.aspx?id=43717
:: Be sure to do the "Complete" installation, not just the "Typical" so that the Web Deployment Agent Service gets installed.
@deadlydog
deadlydog / ExampleUsage.cs
Last active June 28, 2023 09:07
Wraps the .NET IMemoryCache in the Stale Cache pattern to provide Best-Before (Stale) date functionality, allowing apps to achieve better fault tolerance
using Caching;
using Microsoft.Extensions.Logging;
namespace App;
public class ExampleUsage
{
private readonly ILogger<ExampleUsage> _logger;
private readonly StaleMemoryCache _staleMemoryCache;
private readonly IAuthService _authService;
@deadlydog
deadlydog / SlackWebhookTest.ps1
Created November 28, 2023 23:12
PowerShell snippet for testing a Slack webhook
# This code shows how to easily test a Slack webhook from PowerShell. The URL here is a dummy URL.
$slackUri = "https://hooks.slack.com/services/T025sdfsdfsdf/B67sdfsdfsdf/khAfsdfsfsfsdfsdfsdf"
$body = ConvertTo-Json @{
pretext = "Testing Slack integration"
text = "This is just a test to ensure the Slack webhook works and sends messages to the correct Slack channel."
color = "#142954"
}
Invoke-RestMethod -Uri $slackUri -Method Post -Body $body -ContentType 'application/json'
@deadlydog
deadlydog / PowerShellUtilities.psm1
Last active December 17, 2023 18:26
Powershell function Invoke-ScriptBlockWithRetries to execute arbitrary PowerShell code and automatically retry if an exception is thrown
function Invoke-ScriptBlockWithRetries
{
param
(
[Parameter(Mandatory = $true, HelpMessage = 'The script block to execute.')]
[ValidateNotNullOrEmpty()]
[scriptblock] $ScriptBlock,
[Parameter(Mandatory = $false, HelpMessage = 'The maximum number of times to retry the script block.')]
[int] $MaxNumberOfRetries = 5,
@deadlydog
deadlydog / PowerShellSingleFileScriptTemplate.ps1
Last active February 28, 2024 23:44
PowerShell template for a single-file script
[CmdletBinding()]
Param
(
)
Process
{
}
@deadlydog
deadlydog / Repository's .editorconfig file
Last active March 12, 2024 21:04
This .editorconfig file should live in the repository and be committed to source control. This file should not contain personal preference settings like `indent_size`, as those should be specified in a parent .editorconfig file outside of the repository.
# This file should only include settings that affect the physical contents of the file, not just how it appears in an editor.
# Do not include personal preference presentation settings like a tab's `indent_size` in this file; those should be specified
# in a parent .editorconfig file outside of the repository.
# v1.7 - Source: https://gist.github.com/deadlydog/bd000162e85c155b243a712c16f7411c
# Ensure that personal preference presentation settings can be inherited from parent .editorconfig files.
root = false
#### Core EditorConfig Options ####