Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View LawrenceHwang's full-sized avatar
☁️

Lawrence Hwang LawrenceHwang

☁️
View GitHub Profile
@LawrenceHwang
LawrenceHwang / Set-MonitorInputSource.ps1
Created February 18, 2022 20:50
Set-MonitorInputSource - wraps around the ControlMyMonitor.exe
function Set-MonitorInputSource {
<#
.SYNOPSIS
Helper function to set the monitor state.
.EXAMPLE Switch to HDMI
Set-MonitorInputSource -InputSource HDMI
.EXAMPLE Switch to DisplayPort
Set-MonitorInputSource -InputSource DisplayPort
@LawrenceHwang
LawrenceHwang / Convert-FromApplePrivacyReport.ps1
Created October 16, 2021 03:25
Helper function to convert the iOS app activity report into custom objects
function Convert-FromAppActivityReport {
<#
.SYNOPSIS
Helper function to convert the iOS app activity report into custom objects
https://developer.apple.com/documentation/foundation/urlrequest/inspecting_app_activity_data
.EXAMPLE
Get apps accessed iOS resources
Convert-FromAppActivityReport -Path $path -Type access | Select-Object accessor_id -Unique
@LawrenceHwang
LawrenceHwang / Set-TaskbarFontSize.ps1
Created October 14, 2021 04:57
Helper function to set the taskbar icon size
function Set-TaskbarIconSize {
# Sets the windows 11 task bar icon size. Default value is medium.
[CmdletBinding()]
param(
[validateset("small", "medium", "large")]
[string]$Size = "medium"
)
$sizeChart = @{
"small" = 0
"medium" = 1
@LawrenceHwang
LawrenceHwang / Pre-Meeting-Check.ps1
Created July 15, 2020 17:59
Pre-meeting system health check using PowerShell's Pester 5.
Describe 'Pre-meeting Check List' { # These are a Pester 5 compliant tests.
Context 'Device Check' {
It 'Device should be present and have OK status: [<deviceName>]' -TestCases @(
@{deviceName = 'Blue Snowball' }
@{deviceName = '*TrackBall Mouse' }
@{deviceName = 'Microphone (Blue Snowball)' }
@{deviceName = 'Canon EOS 6D Mark II' }
) {
$device = (Get-PnpDevice -FriendlyName $deviceName -Status 'OK' -PresentOnly -ErrorAction SilentlyContinue)
$device.count | Should -BeGreaterOrEqual 1
@LawrenceHwang
LawrenceHwang / ScriptWithFunction.tests.ps1
Created January 27, 2020 02:45
ScriptWithFunction.tests.ps1
Describe 'Unit testing the helper functions in self contained script' {
BeforeAll {
# Using AST to parse the function definitions from the self contained script.
# Then, save the script of the Pester test drive.
$FilePath = Join-Path -Path '.' -ChildPath 'ScriptWithFunction.ps1'
$ast = [System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$null, [ref]$null)
$functionDefinition = $ast.FindAll( {
param([System.Management.Automation.Language.Ast] $AstInput)
$AstInput -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
# Class methods have a FunctionDefinitionAst under them as well, but we don't want them.
@LawrenceHwang
LawrenceHwang / Get-BrainCandy.ps1
Last active September 7, 2019 23:15
Answer to dfinke@'s Powershell brain candy tweet.
# https://twitter.com/dfinke/status/1167559940598370304
function Get-Exponent {
param(
[int]$Base,
[int]$Power
)
$exponent = [Math]::Pow($Base, $Power)
$exponent
}
function Get-OneSeries {
@LawrenceHwang
LawrenceHwang / Show-WeTheNorth.ps1
Created June 6, 2019 07:11
PowerShell function to shows the 'We The North' and the Toronto Raptor's logo ascii art.
function Show-WeTheNorth {
<#
.SYNOPSIS
Shows the 'We The North' and the Toronto Raptor's logo ascii art.
.DESCRIPTION
Go Raptors Go! 🏀🏀🏀🏀
.EXAMPLE
11:49 PM> Show-WeTheNorth
I8, 8 ,8I 88888888888 7777,,,,7777777
`8b d8b d8' 88 77,,,,,,,,,,,,,77,,777
@LawrenceHwang
LawrenceHwang / ColourfulProgressBar.ps1
Last active June 8, 2019 18:20
ColourfulProgressBar.ps1
$max = 600
(1..$max).foreach{$x1 = Get-Random -Minimum 0 -Maximum ([math]::ceiling($host.ui.RawUI.WindowSize.Width* ($_/$max))); $x2 = $x1 + 1; $y1 = Get-Random -Minimum 0 -Maximum 1; $y2 = $y1 ;$Host.ui.RawUI.SetBufferContents([System.Management.Automation.Host.Rectangle]::new($x1,$y1,$x2,$y2),([System.Management.Automation.Host.BufferCell]::new([char](Get-Random -Minimum 32 -Maximum 33),([System.ConsoleColor].GetEnumValues() | Get-Random),([System.ConsoleColor].GetEnumValues() | Get-Random),[System.Management.Automation.Host.BufferCellType]::Complete)))}
@LawrenceHwang
LawrenceHwang / VSCode-CloudFormation-yaml-customTags.json
Created March 6, 2019 22:36
These custom tags adds the CloudFormation yaml shorthands tags in the VSCode.
{
"yaml.customTags": [
"!And",
"!Cidr",
"!Equals sequence",
"!Equals",
"!FindInMap sequence",
"!GetAtt",
"!GetAZs",
"!ImportValue",
@LawrenceHwang
LawrenceHwang / ConvertTo-SSMDocument.ps1
Created January 18, 2019 19:49
ConvertTo-SSMDocument.ps1
function ConvertTo-SSMDocument
{
<#
.Synopsis
Convert a script into SSM Command document
.DESCRIPTION
This cmdlet convert a script into SSM Command document.
.EXAMPLE
PS:\ > ConvertTo-SSMDocument -Expression 'Get-Service'
{