Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
midnightfreddie / FirstWeekdayAfterWeekday.ps1
Created November 8, 2017 19:45
Returns a date object of the first weekday of the month following another weekday, e.g. first Monday after Friday. In reply to https://www.reddit.com/r/PowerShell/comments/7bda01/calculate_first_monday_after_first_friday_of/
function Compare-WeekDays {
# Return days between weekdays
param (
[Parameter(Mandatory=$true)]
[System.DayOfWeek]$Minuend,
[Parameter(Mandatory=$true)]
[System.DayOfWeek]$Subtrahend
)
# In case they change how many days are in a week :)
$DaysInWeek = [System.Enum]::GetNames('System.DayOfWeek').Count
@midnightfreddie
midnightfreddie / ExportRegistry.ps1
Created November 8, 2017 05:08
Export remote registry in the same fashion as RegEdit's export function. In reply to https://www.reddit.com/r/PowerShell/comments/7bht8c/exporting_registries/
function Export-Registry {
Param (
$ComputerName = "iis",
$Key = "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
$LocalPath = "."
)
$DateText = (Get-Date -Format s) -replace ':', '-'
$FileName = "$DateText-$ComputerName.reg"
# PowerShell 5 and above
Enum MyConColor {
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
$Services = @(
"netlogon"
"spooler"
)
$Computers = @(
"."
"iis"
)
Get-Service -Name $Services -ComputerName $Computers -ErrorAction SilentlyContinue |
$test = 5, 4, 5, $null, 4, 8, 3, 5, 4
$chartdatasource = $test | ForEach-Object {
Write-Output @{ Value = $PSItem }
}
# load the appropriate assemblies
[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms.DataVisualization”)
@midnightfreddie
midnightfreddie / New-RandomPassword.ps1
Created October 6, 2017 19:01 — forked from dotps1/New-RandomPassword.ps1
Create a new random password with powershell, specify length, upper case, lower case, numbers, symbols. all are ASCII mapped arrays.
<#
.SYNOPSIS
Creates random password string of length 1 to 100.
.DESCRIPTION
Creates random password with ability to choose what characters are in the string and the length, the symbols can be specificlly defined.
.EXAMPLE
New-RandomPassword -Length 8 -Lowercase
In this example, a random string that consists of 8 lowercase charcters will be returned.
.EXAMPLE
New-RandomPassword -Length 15 -Lowercase -Uppercase -Numbers -Symbols
@midnightfreddie
midnightfreddie / lemonade_stand.bas
Created May 12, 2017 14:31 — forked from badvision/lemonade_stand.bas
Lemonade stand (Applesoft basic)
1 LOMEM: 14080
5 GOSUB 10000: GOSUB 11000: GOSUB 16000: GOTO 135
10 REM <<< LEMONADE STAND >>>
15 REM
20 REM FROM AN ORIGINAL PROGRAM
30 REM BY BOB JAMISON, OF THE
40 REM MINNESOTA EDUCATIONAL
50 REM COMPUTING CONSORTIUM
60 REM * * *
70 REM MODIFIED FOR THE APPLE
<#
.Synopsis
Roll dice
.DESCRIPTION
Given a role-playing description of dice, e.g. "2d6", return an object
with the randomly rolled results
.EXAMPLE
Invoke-Dice 2d6
.EXAMPLE
Invoke-Dice 2d6 -Bonus 3
@midnightfreddie
midnightfreddie / psISEfontTest.ps1
Created December 24, 2016 22:44
The script I used to automate font and size testing on YouTube https://www.youtube.com/watch?v=T0oKmXYMnbc
###############################
### Font and size info here ###
###############################
9..32 | ForEach-Object {
$Size = $PSItem
"Lucida Console", "Consolas" | ForEach-Object {
$psISE.Options.FontSize = $Size
$psISE.Options.FontName = $PSItem
$psISE.CurrentPowerShellTab.Files.SelectedFile.Editor.SetCaretPosition(2,1)
@midnightfreddie
midnightfreddie / JekyllHelper.ps1
Last active December 13, 2016 21:06
A couple of quickie functions to generate filename and front matter for Jekyll posts for copy/paste
<#
.Synopsis
Generates file name and front matter scaffolding for a Jekyll post.
.DESCRIPTION
Given a post title string, creates file name and front matter for a Jekyll
post using the current date and time. Optionally creates the file in the
.\_posts directory or designated -Path\_posts or -PostsPath.
.EXAMPLE
New-JekyllPost "Title of the new post"
.EXAMPLE