Skip to content

Instantly share code, notes, and snippets.

@jkdba
jkdba / ToastNotification_Windows10.ps1
Created May 9, 2016 17:30 — forked from altrive/ToastNotification_Windows10.ps1
Windows 10 toast notification sample
$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: " + [DateTime]::Now.ToShortTimeString()
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
#Convert to .NET type for XML manipuration
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
@jkdba
jkdba / Microsoft.PowerShell_profile.ps1
Last active August 25, 2016 19:15
Updated PowerShell Console Window Title to Last Command and Current Path
## Use PowerShell Engine Event (OnIdle) to Update the PowerShell
## Console Window's Title to have the current path and last command executed.
## For this to work Nicely add it to your PowerShell Profile.
## Subscribe to PowerShell.OnIdle Event
## Out to null to hide Register-EngineEvent output
$null = Register-EngineEvent PowerShell.OnIdle -Action {
## Get Last Command ran from history
$LastCommand = Get-History | Sort-Object -Property Id -Descending | Select-Object -First 1 -exp CommandLine
## Updated the console window's title to have the path and command.
@jkdba
jkdba / AutomaticJobCleanup.ps1
Last active June 12, 2022 23:57
PowerShell Automatically Cleanup Job on Completion Using a Registered Object StateChanged Event
#Build Job Name to be unique
$JobName = "ExampleJob"
$JobNameCount = (get-job | Where-Object Name -like $JobName*).Count
$JobName = "$($JobName)_$($JobNameCount)"
#Define and Start job
$Job = Start-Job -Name $JobName -ScriptBlock { Start-Sleep 60 }
#Create Event to clean up job after complete
Register-ObjectEvent -InputObject $Job -EventName "StateChanged" -Action {
@jkdba
jkdba / MSSQL_RepetitiveReplace_fn.sql
Last active December 1, 2022 20:10
Simple function to recursively replace a pattern in a string.
CREATE FUNCTION dbo.RepetitiveReplace_fn
(
@P_String VARCHAR(MAX),
@P_Pattern VARCHAR(MAX),
@P_ReplaceString VARCHAR(MAX),
@P_ReplaceLength INT = 1
)
RETURNS VARCHAR(MAX)
BEGIN
DECLARE @Index INT;
@jkdba
jkdba / MauiProgram.cs
Created August 18, 2023 21:53
.Net Maui Windows & WinUI3 System/Global Hotkey
using MauiApp1.Data;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.Platform;
using System.Runtime.InteropServices;
using MauiApp1.Shared;
namespace MauiApp1
{
public static class MauiProgram
@jkdba
jkdba / PS7_HttpClientHandler_Custom_ServerCertificateCustomValidationCallback.ps1
Created March 12, 2024 16:08
PowerShell 7 HttpClientHandler with custom Certification Validation Logic
using namespace System;
using namespace System.Net;
using namespace System.Net.Http;
## handler to bypass invalid certificate
$handler = [HttpClientHandler]::new()
# $handler.AllowAutoRedirect = $false
$handler.ServerCertificateCustomValidationCallback = [HttpClientHandler]::DangerousAcceptAnyServerCertificateValidator ## System.Net.Http.
$location = [Uri]::New("https://some_invalid_cert_server")
@jkdba
jkdba / Invoke-URLInDefaultBrowser.ps1
Created June 13, 2016 22:59
PowerShell cmdlet to open a URL in the user's default browser.
function Invoke-URLInDefaultBrowser
{
<#
.SYNOPSIS
Cmdlet to open a URL in the User's default browser.
.DESCRIPTION
Cmdlet to open a URL in the User's default browser.
.PARAMETER URL
Specify the URL to be Opened.
.EXAMPLE