Skip to content

Instantly share code, notes, and snippets.

                GNU GENERAL PUBLIC LICENSE
                   Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

                        Preamble

The GNU General Public License is a free, copyleft license for

@codaamok
codaamok / xmlserialisation.ps1
Created November 26, 2022 17:31
PowerShell max depth for serialising data objects into child scopes. Execute this and observe how data is progressively lost while PowerShell serialises the object into the scopes.
$xml = [xml]"<parent><child name='Adam'><grandchild name='Charlie'></grandchild></child></parent>"
$xml.parent
$xml.parent.child
$xml.parent.child.grandchild
Invoke-Command -ComputerName 'hostname' -ArgumentList $xml.parent -ScriptBlock {
param($xml)
$xml.child
$xml.grandchild
}
@codaamok
codaamok / Get-BusinessHoursElapsed.Tests.ps1
Last active April 12, 2022 09:12
The below code is old and was made during initial development, it is now module PSBusinessTime https://github.com/codaamok/psbusinesstime
BeforeAll {
function GetElapsedTime {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[DateTime]$StartDate,
[Parameter(Mandatory)]
[DateTime]$EndDate,
@codaamok
codaamok / freedom.to proxy list
Last active December 30, 2020 10:14
A list of domains to bypass the Windows proxy configured by Freedom, for Microsoft / Office 365 services
freedom.to;*.localhost;*.127.0.0.1;*.office.com;*.office365.com;*.office.net;*.onedrive.com;*.sharepoint.com;*.optimizely.com;*.microsoftonline.com;*.production.us.trafficmanager.net;*.microsoft.com;*.live.com;*.oneclient.sfx.ms;*.sharepointonline.com;*.spoprod-a.akamaihd.net;*.prod.msocdn.com;*.svc.ms;*.lync.com;*.broadcast.skype.com;*.skypeforbusiness.com;*.sfbassets.com;*.skypemaprdsitus.trafficmanager.net;*.windows.net;*.msecnd.net;*.aspnetcdn.com;*.live.net;*.aka.ms;*.azure.net;*.windows.com;*.windows.net;*.msedge.net;*.mstea.ms;*.skypeassets.com;*.azureedge.net;*.tenor.com;*.microsoftstream.com;*.assets-yammer.com;*.azureedge.net;*.onenote.com;*.onenote.net;*.aspnetcdn.com;*.optimizely.com;*.msappproxy.net;*.msftidentity.com;*.msidentity.com;*.windowsazure.com;*.microsoftazuread-sso.com;*.microsoftonline-p.net;*.msauth.net;*.msauthimages.net;*.msftauth.net;*.msftauthimages.net;*.phonefactor.net;*.visualstudio.com;*.cloudapp.net;*.staffhub.ms;*.gfx.ms;*.appex.bing.com;*.appex-rf.msn.com;*.getmicrosoftkey
@codaamok
codaamok / New-PSSouthamptonVirtualSession.ps1
Created July 12, 2020 16:24
PSSouthampton streaming content
<#
.SYNOPSIS
Create a new properties.json file containing the speaker's name, session title, Twitter handle and local path to their Twitter profile picture. This script also downloads said profile picture. The produced properties.json file is intended to be consumed by index.php within this gist.
.EXAMPLE
PS C:\> .\New-PSSouthamptonVirtualSession.ps1 -SessionTitle "Some session title goes here" -SpeakerName "Adam Cook" -TwitterHandle "codaamok"
Downloads the profile picture of Twitter account @codaamok to "C:\xampp\htdocs\PSSouthampton"
Creates properties.json file with the below object:
@codaamok
codaamok / ConvertTo-Ini.ps1
Created June 3, 2020 21:25
Using StringBuilder class, create a multi line string in typical .ini format from an array of hash tables or ordered dictionaries.
function ConvertTo-Ini {
param (
[Object[]]$Content,
[String]$SectionTitleKeyName
)
begin {
$StringBuilder = [System.Text.StringBuilder]::new()
$SectionCounter = 0
}
process {
### Keybase proof
I hereby claim:
* I am codaamok on github.
* I am codaamok (https://keybase.io/codaamok) on keybase.
* I have a public key ASAJfgIjA29owfyPLxBNLSM9ssUv-voCVrtVruiP46vWhQo
To claim this, I am signing this object:
@codaamok
codaamok / Invoke-CM1902LabBuild.ps1
Last active February 17, 2020 13:16
Install AutomatedLab and start CM-1902 lab build
function Invoke-CM1902LabBuild {
if (-not(Get-Package -Name "AutomatedLab" -ProviderName "msi" -MinimumVersion "5.17.0")) {
$Path = "{0}\Downloads\AutomatedLab.msi" -f $HOME
Invoke-WebRequest -Uri "https://github.com/AutomatedLab/AutomatedLab/releases/latest/download/AutomatedLab.msi" -OutFile $Path -ErrorAction "Stop"
Start-Process "msiexec" -ArgumentList @("/i", $Path, "/qb") -Wait -ErrorAction "Stop"
}
try {
$Path = "{0}\Downloads\codaamok-PoSH" -f $HOME
git clone https://github.com/codaamok/PoSH.git $Path
function Copy-CMTSDeployments {
<#
.SYNOPSIS
A function to copy deployments from one task sequence to another. Modify the New-CMTaskSequenceDeployment parameters in the splat as desired.
.EXAMPLE
PS C:\> Copy-CMTSDeployments -taskSequenceId_old "ABC0037A" -taskSequenceId_new "ABC004EA" -ExcludeCollections "ABC0133F", "ABC01340"
Gathers all deployments from task sequence ABC0037A and deploys them to ABC004EA, excluding ABC0133F and ABC01340.
.NOTES
Author: Adam Cook
#Requires -Module AutomatedLab
Param (
[Parameter(Mandatory=$true)]
$LabName,
[Parameter(Mandatory=$true)]
$Domain
)
New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV