This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Parameters = @{ | |
a = '{14}' | |
b = '{22}' | |
} | |
$UrlParameters = ($Parameters.Keys | ForEach-Object { | |
"{0}={1}" -f [System.Web.HttpUtility]::UrlEncode($_), [System.Web.HttpUtility]::UrlEncode($Parameters[$_]) | |
}) -join "&" | |
$Uri = "https://<rootURI>/calc/add?$UrlParameters" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$NinjaJs = @" | |
var NinjaQuerySelectorAll = function(selector) { | |
nodeList = document.querySelectorAll(selector); | |
output = []; | |
for (i=0; i < nodeList.length; i++) output.push(nodeList.item(i)); | |
console.log("Ninja JS function output"); | |
console.log(output); | |
return output; | |
} | |
"@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Uri = "http://midnightfreddie.com/reddit/simpletable.html" | |
$InfoPage = Invoke-Webrequest -Uri $Uri | |
# Iterate over each <tbody> which contain all the body rows for each table | |
$InfoPage.ParsedHtml.getElementsByTagName("tbody") | ForEach-Object { | |
$Headers = $null | |
# Might need to uncomment the following line depending on table being parsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given an array of rss xml document objects, return one rss document object with all the items sorted by date, descending | |
# Because of auto-deserialization, may need to build xml doc arrays with @(,$XmlDoc) trick | |
function Invoke-CombineRssXml { | |
[cmdletbinding()] | |
param ( | |
[Parameter(Mandatory=$true,ValueFromPipeline=$true)] | |
[xml[]]$Xml | |
) | |
begin { | |
Write-Verbose "Combining rss xml documents" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This just puts each array in a vertical column of a table. | |
# The rows are not related data unless the source data is keyed on array index | |
$Arr1 = @(1, 2, 3, 4, 5) | |
$Arr2 = @(1, 2, 3) | |
$Arr3 = @(1, 2, 3, 4, 5, 6) | |
$Arr4 = @(1, 2, 3, 4, 5, 6, 7) | |
$Arr5 = @(1, 2) | |
$Arr6 = @(1, 2, 3, 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myfunc{ | |
$myvar = new-object 'System.Collections.Generic.HashSet[string]' | |
# [void]$$myvar.add("value") | |
$myvar.add("value") | Out-Null | |
$myvar.add("value2") | Out-Null | |
# Write-Host $($myvar.GetType()) | |
@(,$myvar) | |
} | |
(myfunc).GetType() | |
$returnedvalue = myfunc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Export-Registry { | |
Param ( | |
$ComputerName = "iis", | |
$Key = "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", | |
$LocalPath = "." | |
) | |
$DateText = (Get-Date -Format s) -replace ':', '-' | |
$FileName = "$DateText-$ComputerName.reg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell 5 and above | |
Enum MyConColor { | |
Black | |
Red | |
Green | |
Yellow | |
Blue | |
Magenta | |
Cyan | |
White |
NewerOlder