Skip to content

Instantly share code, notes, and snippets.

View markwragg's full-sized avatar

Mark Wragg markwragg

View GitHub Profile
@markwragg
markwragg / Check-Modules.ps1
Last active January 29, 2019 22:08
Check for out of date PowerShell modules
$Modules = Get-Module -ListAvailable |
Where-Object { $_.RepositorySourceLocation -like '*powershellgallery*'} |
Group-Object Name |
ForEach-Object { $_.Group | Sort-Object Version -Descending | Select-Object -First 1 }
$ModuleCheck = ForEach ($Module in $Modules) {
Find-Module -Name $Module | Select-Object Name,Version,@{N='InstalledVersion';E={$Module.Version}}
}
$OutOfDateModules = $ModuleCheck | Where-Object {[version]$_.Version -gt [version]$_.InstalledVersion}
@markwragg
markwragg / AddOne.tests.ps1
Created August 17, 2018 10:27
Add one tests
function AddOne ([int16]$Num) {
$Num = $Num + 1
Return $Num
}
Describe 'Add One Tests' {
32000..32766 | ForEach-Object {
It "Should Add 1 to $_" {
AddOne $_ | Should -Be ($_ + 1)
}
}
@markwragg
markwragg / mactweaks.md
Last active April 25, 2023 18:10
Mac tweaks

Changes to my Mac

Turn off "press and hold" for foreign letters, allowing you to then press and hold for repeat letters. Open Terminal and run:

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

Then you need to close/reopen any app before it takes effect.

Make the dock appear faster when using auto hide:

@markwragg
markwragg / Invoke-Puppet.ps1
Last active June 5, 2018 09:09
A PowerShell function to invoke Puppet after it has completed its current run
Function Invoke-Puppet {
Param(
$Environment
)
if ($Environment) { $Environment = "--environment='$Environment'" }
while (Test-Path C:/ProgramData/PuppetLabs/puppet/cache/state/agent_catalog_run.lock) {
Write-Warning 'Puppet is already running. Waiting for it to finish..'
Start-Sleep 5
}
@markwragg
markwragg / scrape-rt.ps1
Last active August 23, 2019 22:24
Top 100 scrape from Rotten Tomatoes with rating
Function Get-Top100Movies {
[cmdletbinding()]
Param(
[Int[]]$Year = ((Get-Date).Year -1)
)
foreach ($Yr in $Year) {
$Result = (Invoke-WebRequest "https://www.rottentomatoes.com/top/bestofrt/?year=$Yr") -split '</tr>'
$Result | Select -Skip 1 | ForEach-Object {
$_ -match '(?smi)<td>\s*?<a href="/m/.*?>\s*(.*?)</a>.*?</td>' | Out-Null
@markwragg
markwragg / Sort-AzureSubnets.ps1
Last active April 5, 2018 09:11
Get Azure subnets for a VNET and sort them correctly by address by recasting them to [version]
$VNET = Get-AzureRmVirtualNetwork -name VNET_NAME -ResourceGroupName RG_NAME
(Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $VNET).AddressPrefix | ForEach-Object {
$Net = $_ -split '/'
[pscustomobject]@{
Address = [version]$Net[0]
Mask = $Net[1]
}
} | Sort Address
@markwragg
markwragg / Test-URL.ps1
Created February 7, 2018 16:29
Testing URLs with added personality
ForEach ($URL in $URLs) {
Write-Host $URL -NoNewline ": "
Try {
Invoke-WebRequest $URL -UseBasicParsing | Out-Null
Write-Host ('Yup','Looks Good','OK' | Get-Random) -ForegroundColor Green
}Catch{
Write-Host $_ -ForegroundColor Red
}
}
@markwragg
markwragg / Get-CoinFlip.ps1
Created November 28, 2017 08:49
PowerShell Function for deciding between two choices. E.g Get-CoinFlip -Heads Coffee -Tails Tea
Function Get-CoinFlip {
Param(
$Heads = 'Heads',
$Tails = 'Tails'
)
Get-Random $Heads,$Tails
}
@markwragg
markwragg / Format-ColourList.ps1
Last active September 4, 2017 08:48
PowerShell function to create a partially coloured version of Format-List to highlight defined keywords in one or more colours.
Function Format-ColourList {
Param(
#The input object to be formatted.
[Parameter(Position=0,ValueFromPipeline)]
$InputObject,
#A hashtable of text to colour and the colour of that text. By default colours 'True' as Green and 'False' as Red.
[Hashtable]$Colour = @{True = 'Green'; False = 'Red'}
)
Begin {
@markwragg
markwragg / Install.ps1
Last active August 30, 2017 07:39
PowerShell script to install a module from a source control system. For use where package management is not an option.
[cmdletbinding()]
Param()
<#
.SYNOPSIS
Installs a module.
#>
Function Install-Module {
[cmdletbinding(SupportsShouldProcess)]
Param (