Skip to content

Instantly share code, notes, and snippets.

View dfinke's full-sized avatar

Doug Finke dfinke

View GitHub Profile
@dfinke
dfinke / CountryLoopup.ps1
Created November 27, 2013 16:15
Use a PowerShell hash table/associative array to translate a country abbreviation to its full name.
$CountryLookup = [ordered]@{
"AD"="ANDORRA"
"AE"="UNITED ARAB EMIRATES"
"AF"="AFGHANISTAN"
"AG"="ANTIGUA AND BARBUDA"
"AI"="ANGUILLA"
"AL"="ALBANIA"
"AM"="ARMENIA"
"AO"="ANGOLA"
"AQ"="ANTARCTICA"
@dfinke
dfinke / Find-GuidUsage.ps1
Last active July 15, 2024 09:25
Developers use GUIDs in there code. This PowerShell function takes a path, looks for C# files and searches (greps) for a GUID pattern. `Find-GuidUsage c:\<Your Code>`
function Find-GuidUsage {
param(
[Parameter(Mandatory=$true)]
$path,
$filter="*.cs"
)
$GuidPattern = "({|\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\))?"
dir $path -Recurse $filter |
@dfinke
dfinke / ConvertTo-PigLatin.ps1
Last active January 1, 2016 09:49
Write-Output Merry Christmas And Happy New Year | ConvertTo-PigLatin
function ConvertTo-PigLatin {
param(
[Parameter(ValueFromPipeline)]
[string[]]$string
)
Process {
$r += $(foreach($s in $string) {
if(Write-Output b c d f g h j k l m n p q r s t v w x y z -eq $s[0]) {
function Invoke-Thesaurus {
param(
$Word='Thesaurus',
$FilterCategory
)
$language='en_US'
$key='<get key here http://thesaurus.altervista.org/mykey>'
$result="json"
@dfinke
dfinke / Get-GithubEvent.ps1
Created May 10, 2014 14:04
Use PowerShell to list GitHub events that a user has received
function Get-GithubEvent {
param($userId,$Password)
function Get-GitHubAuthHeaders {
param($userId,$Password)
$authInfo = "$($userId):$($Password)"
$authInfo = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($authInfo))
@dfinke
dfinke / Get-GithubEmojis.ps1
Created June 21, 2014 12:28
Download Github Emojis Using PowerShell Workflow
workflow Get-GithubEmojis {
param($TargetPath="c:\temp\emojis")
if(!(Test-Path -Path $TargetPath)) {
$null= New-Item -ItemType Directory -Path $TargetPath
}
$emojis = Invoke-RestMethod -Uri https://api.github.com/emojis
@dfinke
dfinke / Get-TimeStamp.ps1
Created July 23, 2014 13:04
`Get-TimeStamp -Yesterday -ToClipboard` - Example, copy a TS to the clipboard, using it to name files
function Get-TimeStamp {
param(
[Switch]$Yesterday,
[Switch]$ToClipboard
)
$date = Get-Date
if($Yesterday) {
$date = $date.AddDays(-1)
@dfinke
dfinke / Edit-NewIseFile.ps1
Last active July 15, 2024 09:24
Create a new PowerShell script, with correct encoding and edit it in ISE
function Edit-NewIseFile {
param(
[Parameter(ValueFromPipeline=$true)]
$Filename,
[Switch]$AddFunction
)
Process {
$content=""
@dfinke
dfinke / CFSBuddy.ps1
Created September 17, 2014 14:37
PowerShell v5.0 ConvertFrom-String Buddy - A GUI that helps you work with this new powerful cmdlet
#Requires -Version 5.0.9814.0
if(!($PSVersionTable.PSVersion.Major -ge 5 -and $PSVersionTable.PSVersion.Build -ge 9814)) {
"Sorry you need PSVersion 5.0.9814.0 or newer"
$psversiontable
return
}
Add-Type -AssemblyName presentationframework
@dfinke
dfinke / GetOutlookMessages.ps1
Last active October 31, 2016 10:42
Uses COM to Look at yesterdays messages for a particular outlook account. Reporting Date, Subject and # Of Attachments
$email = '[email protected]'
$targetDate = (Get-Date).AddDays(-1).ToString("d") # yesterday
if(Get-Process outlook -ErrorAction Ignore) {
return "Please stop Outlook and re-run"
}
Write-Progress -Activity "Outlook" -Status "Connecting"
if($script:outlook -eq $null) { $script:outlook = new-object -com outlook.application }