Get Powershell version

PS C:\> $PSVersionTable.PSVersion

which will display something like the table below, which means we're running v4:

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

Get Machine's IP Address

Complex way of getting the current machines IP address, when the get-netadapter or Get-NetIPAddress it's working for you.

funcion Get-CurrentMachinesInternalIpAddres{
  Write-Host "Getting this machines IP address"
  return ((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
}

Cheers for this.

Get your public IP

function Get-MyPublicIPAddress
{
  Write-Host "Getting public IP address"
  $downloader = new-object System.Net.WebClient
  $ip = $downloader.DownloadString("http://ifconfig.me/ip")
  return $ip
}

Cheers for this

Change Execution Policies

In order to run our scripts, we must change the policy from "Restricted” to "Unrestricted”. For security reasons, we need to change to back to "Restricted” afterwards. To run our scripts, perform the following:

  • Open PowerShell Command Prompt
Type "Get-ExecutionPolicy"

This should display: "Restricted"

Type "Set- ExecutionPolicy Unrestricted"

Run your .ps1 script

  • To revert back
Type "Set- ExecutionPolicy Restricted"
Type "Get-ExecutionPolicy", to verify that the policy has been changed back to Restricted"

Stop Transactiption if it's running

try{
  stop-transcript|out-null
}
catch [System.InvalidOperationException]{}

Details on Stack Overflow

Replace Character within a string

$someString = $someString -replace('[*]','')
this replaces the * in the string with nothing

IIS PowerShell Commands

All of the IIS PowerShell Commands

Pester (BDD) Powershell Testing

choco install pester
{Import-Module "C:\ProgramData\chocolatey\lib\pester.3.3.1\tools\Pester.psm1"} | New-Item -path $profile -type file -force;. $profile
New-Fixture
Invoke-Pester

SSL Certificate Bindings

  • A workaround to using a shared certificate is here
  • Another one is here
  • Tomorrow, I will verify which one is the best :)