View AddOne.tests.ps1
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)
}
}
View mactweaks.md

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:

View Invoke-Puppet.ps1
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
}
View scrape-rt.ps1
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
View Sort-AzureSubnets.ps1
$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
View Test-URL.ps1
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
}
}
View Get-CoinFlip.ps1
Function Get-CoinFlip {
Param(
$Heads = 'Heads',
$Tails = 'Tails'
)
Get-Random $Heads,$Tails
}
View Format-ColourList.ps1
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 {
View Install.ps1
[cmdletbinding()]
Param()
<#
.SYNOPSIS
Installs a module.
#>
Function Install-Module {
[cmdletbinding(SupportsShouldProcess)]
Param (
View working-days.ps1
#As a function
Function Get-WorkingDays ($Date) {
(0..((Get-Date $Date) - (Get-Date)).days | % { (Get-Date).AddDays($_) } | Where-Object DayOfWeek -notin 'Saturday','Sunday').count
}
Get-WorkingDays 15/09/2017
#One liner
(0..((Get-Date '15/09/2017') - (Get-Date)).days | % { (Get-Date).AddDays($_) } | ? DayOfWeek -notin 'Saturday','Sunday').count