This file contains hidden or 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 hidden or 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
Add-Type -TypeDefinition @" | |
public enum PcType { | |
DESKTOP, | |
LAPTOP | |
} | |
"@ | |
$PcChoices = [System.Enum]::GetValues([type]"PcType") | |
# '^(DESKTOP|LAPTOP)\d{6}$' , but this lets us add/modify enum choices later with no code changes | |
$RegExMatch = "^({0})\d{{6}}$" -f ( ( $PcChoices | ForEach-Object { $_.ToString() } ) -join "|") |
This file contains hidden or 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
#$StockList = Get-Content -Path "stocks.json" | ConvertFrom-Json | |
$StockList = '[{ "TICK": "FDX", "EXCH": "NYSE" }, { "TICK": "G", "EXCH": "NYSE" }]' | ConvertFrom-Json | |
# ForEach ($Stock In $StockList) | |
$StockList | ForEach-Object { | |
$Stock = $_ | |
$Sym = $Stock.TICK | |
$Exc = $Stock.EXCH | |
$RawData = Invoke-WebRequest "http://finance.google.com/finance/info?q=$Exc%3a$Sym" |
This file contains hidden or 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
# Dot-source function file | |
. .\BusinessDays.ps1 | |
Describe 'Get-IsWeekDay' { | |
@{ Date = "2016-05-15"; IsWeekDay = $false}, | |
@{ Date = "2016-05-16"; IsWeekDay = $true }, | |
@{ Date = "2016-05-17"; IsWeekDay = $true }, | |
@{ Date = "2016-05-18"; IsWeekDay = $true }, | |
@{ Date = "2016-05-19"; IsWeekDay = $true }, | |
@{ Date = "2016-05-20"; IsWeekDay = $true }, |
This file contains hidden or 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
# Silliness. U0300 - U0036F are combining unicode characters | |
# https://en.wikipedia.org/wiki/Combining_Diacritical_Marks | |
$String = "The quick, brown fox jumped over the lazy dog" | |
$Combining = 0x0300 .. 0x036F | ForEach-Object { [char]$_ } | Sort-Object { Get-Random } | |
$i = 0 | |
($String.ToCharArray() | ForEach-Object { $_ -replace '[A-Za-z]', "`$0$($Combining[$i++])" }) -join "" |
This file contains hidden or 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 hidden or 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 isn't tested much as I don't have the original data, but I've tested varios snippets, and they seem to work | |
# $GraylogUrl = "http://example.tld:12201/gelf" | |
$GraylogUdpPort = 12201 | |
$GraylogUdpHost = "example.tld" | |
$UDPclient = new-Object System.Net.Sockets.UdpClient | |
$UDPclient.Connect($GraylogUdpHost, $GraylogUdpPort) | |
$Enc = [system.Text.Encoding]::UTF8 |
This file contains hidden or 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 Get-Hype { | |
param ( | |
[switch]$CleganeBowl, | |
[switch]$KingsMoot | |
) | |
New-Object psobject -Property ([ordered]@{ | |
CleganeBowl = $CleganeBowl | |
CleganeBowlIsPresent = $CleganeBowl.IsPresent | |
CleganeBowlBound = $PSBoundParameters.ContainsKey('CleganeBowl') | |
KingsMoot = $KingsMoot |
This file contains hidden or 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
# Get the weather | |
$wttr = Invoke-WebRequest http://wttr.in/ | |
# Regex to match lines with no data in them, including blank lines and decorative borders | |
$RegExNoData = '^[ ─┌┬┤├┐┼└┴┘]*$' | |
# This is used to match the phase line and exclude it. | |
# Also used to create an array of weather data for each date | |
$PhasesOfDay = @("Morning", "Noon", "Evening", "Night") |
This file contains hidden or 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
# In reply to https://www.reddit.com/r/PowerShell/comments/4a08hk/importcsv_with_as_a_hashtable/ | |
# Public Google Form at https://docs.google.com/a/jimnelson.us/forms/d/1dYmWTcw3c3q9p3HGWGvbNDvXWekUEKQfgsecZOpsV-k | |
# Results are at https://docs.google.com/spreadsheets/d/1G7J8qCL4gQ_NSYLiGE_3dauSaa75ppzPmcO-Rl7yV6w | |
[cmdletbinding()] | |
param( | |
$SheetKey = "1G7J8qCL4gQ_NSYLiGE_3dauSaa75ppzPmcO-Rl7yV6w", | |
$MaxRows = 5 |