Skip to content

Instantly share code, notes, and snippets.

@SimonWahlin
SimonWahlin / gist:3c69d10a1c13aa439063
Created January 16, 2015 20:14
Contraproff empty pipelines
Function Init {
$File = "$env:tmp\testfile.tmp"
if(-Not (Test-Path -Path $File)){[Void](New-Item -Path $File -Type File)}
Start-Service -Name Spooler
}
Function Validate {
$File = "$env:tmp\testfile.tmp"
$FileStatus = if(Test-Path -Path $File){'Exists'}else{'Removed'}
$SrvStatus = (Get-Service -Name Spooler).Status
# Oneliner:
Invoke-RestMethod -Uri http://telize.com/geoip | Select-Object -Property longitude, latitude, continent_code, timezone
# Advanced function:
Function Get-GeoInformation
{
<#
.Synopsis
Get geo information for current IP address or
any specified IP address.
[cmdletbinding(DefaultParameterSetName='Default')]
param
(
[Parameter(ParameterSetName = 'Default',
Mandatory=$true,
Position = 0)]
[String[]]$Word,
[Parameter(ParameterSetName = 'Default',
Position = 1)]
Verifying that +simonwahlin is my blockchain ID. https://onename.com/simonwahlin
@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)]
@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
<#
.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 / 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',
@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',
#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'
{