Skip to content

Instantly share code, notes, and snippets.

@SimonWahlin
SimonWahlin / demo.psm1
Created February 8, 2023 13:59
PowerShell Demo
# Save this file and import it using the command `Imort-Module '<path to file'`
$Script:Demo = @(
@'
$PSVersionTable
'@
@'
Get-Command *AzAccount*
@SimonWahlin
SimonWahlin / profile.ps1
Last active January 26, 2023 14:41
PowerShell Profile
#region BootstrapProfile
try {
Import-Module 'posh-git' -ErrorAction 'stop'
}
catch {}
if (
$host.Name -eq 'Visual Studio Code Host' -or
(Get-Process -Id $PID).Parent.ProcessName -like 'Code*'
) {
@SimonWahlin
SimonWahlin / Start-TypedDemo.ps1
Last active July 4, 2019 19:53
Start-TypedDemo
# Script originally from: https://jdhitsolutions.com/blog/powershell/4445/simulating-a-powershell-demo/
# Slightly modified by @SimonWahlin
Function Start-TypedDemo {
<#
.SYNOPSIS
Simulate a PowerShell session
.DESCRIPTION
This command simulates an interactive PowerShell session. It will process a text file of PowerShell commands. The function will insert your prompt and "type" out each command when you press any key. At the end of the typed command or whenever a pipe character is inserted, the script will pause. Press Enter or any key to continue.
If it is the end of the command pressing Enter will execute the command. Use the -NoExecute parameter to run through the demo without executing any commands. Commented lines will be skipped. Press 'q' or ESC at any pause to quit the demo.
#requires -Version 4.0
<#
Author: Luke Murray (Luke.Geek.NZ)
Version: 0.1
Purpose: Windows 10 Baseline Hardening using DSC per DoD DISA STIG recommendations 22/06/18.
Modified to include comments explaining config by Frankie McDonough 01/23/19.
#>
Configuration 'Win10'
{
@SimonWahlin
SimonWahlin / Test.ps1
Last active January 18, 2019 07:46
Testing Speed
function Send-PSNotification {
[cmdletbinding()]
param(
[Parameter(Mandatory,ValueFromPipeline,Position=0)]
[object]
$Body,
[String]
$Summary = 'PowerShell Notification',
@SimonWahlin
SimonWahlin / sillyparameterchecking.ps1
Last active January 17, 2019 20:21 — forked from TylerLeonhardt/sillyparameterchecking.ps1
silly parameter checking
function Send-PSNotification {
[cmdletbinding()]
param(
[Parameter(Mandatory,ValueFromPipeline,Position=0)]
[object]
$Body,
[String]
$Summary = 'PowerShell Notification',
<#
.SYNOPSIS
Change language settings for a PowerPoint presentation
.EXAMPLE
PS> Set-PowerPointLanguage -Path MyPres.pptx
Writes a copy of MyPres.pptx to MyPres.en-us.pptx with the language set to 'en-US' - English (the default)
.EXAMPLE
PS> Set-PowerPointLanguage -Path MyPres.pptx -Language de-DE
@SimonWahlin
SimonWahlin / pre-commit
Created March 27, 2018 12:22
Pre-Commit hook for git that will fix my user.email setting for me
#!C:\Program\ Files\PowerShell\6.0.0\pwsh.exe -File
$Pattern = '^origin\s+https://(\S+)\s\(push\)'
$Origin = (& 'git' 'remote' '-v') -match $Pattern | Where-Object -FilterScript {$_ -is [string]}
$RemoteDomain = if($Origin -match $Pattern) {$Matches[1]}
$Email = & 'git' 'config' '--get' 'user.email' | Where-Object -FilterScript {$_ -is [string]}
$DesiredEmail = switch -Wildcard ($RemoteDomain) {
'simonwahlin.visualstudio.com*' {
'simon@simonw.se'
break
@SimonWahlin
SimonWahlin / test.ps1
Created October 13, 2016 17:27
Example of dynamic parameters with PowerShell
function Test {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true,Position=1)]
[string]$smtpServer,
[Parameter(Position=2)]
[switch]$logging,
[Parameter(Position=4)]
Verifying that +simonwahlin is my blockchain ID. https://onename.com/simonwahlin