Skip to content

Instantly share code, notes, and snippets.

Dave Carroll thedavecarroll

View GitHub Profile
@thedavecarroll
thedavecarroll / 1-Measure-PSCodeLine.ps1
Last active Jun 24, 2020
IronScripter Challenge - June 9, 2020 - Building a PowerShell Command Inventory
View 1-Measure-PSCodeLine.ps1
function Measure-PSCodeLine {
[CmdLetBinding()]
param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateScript({Test-Path -Path $_})]
[string]$Path
)
$TotalLines = $CodeLines = 0
$Files = Get-ChildItem -Path $Path -Recurse -Include *.ps1,*.psm1 -File
$Files | Foreach-Object {
@thedavecarroll
thedavecarroll / OAuthParameters.class.ps1
Last active Jun 5, 2020
PowerShell 7 Class for OAuth 1
View OAuthParameters.class.ps1
#requires -version 7.0
class OAuthParameters {
[string]$HttpMethod
[String]$BaseUri
[hashtable]$Query
[System.UriBuilder]$UriBuilder
[string]$UnescapedQueryString
[string]$EscapedQueryString
[object]$Body
@thedavecarroll
thedavecarroll / ValidateTwoLetterRegionName.ps1
Created May 18, 2020
Validate Two Letter Region Names with PowerShell
View ValidateTwoLetterRegionName.ps1
$TwoLetterISORegionNames = Get-Culture -ListAvailable |
Foreach-Object {
try { [System.Globalization.RegionInfo]::new($_.Name) }
catch {}
} |
Select-Object -ExpandProperty TwoLetterISORegionName | Sort-Object -Unique
'US','CA','UK' | % { $_ -in $TwoLetterISORegionNames ? '{0} is valid' -f $_ : '{0} is not valid' -f $_ }
@thedavecarroll
thedavecarroll / Get-NetworkUsage.ps1
Last active May 13, 2020
IronScripter Challenge - April 27, 2020 - Building a Network Usage PowerShell Monitor
View Get-NetworkUsage.ps1
function Get-NetworkUsage {
[CmdletBinding(DefaultParameterSetName='Default')]
param(
[string]$ComputerName = $env:COMPUTERNAME,
[int]$WarnSentBytes = 10000,
[Parameter(ParameterSetName='Default')]
[int]$MaxSamples = 5,
[Parameter(ParameterSetName='Default')]
[int]$SampleInterval = 1,
[Parameter(ParameterSetName='Default')]
@thedavecarroll
thedavecarroll / 1 - Get-IntermediateCountingChallenge .ps1
Created May 11, 2020
IronScripter Challenge - May 11, 2020 - A PowerShell Counting Challenge
View 1 - Get-IntermediateCountingChallenge .ps1
# Intermediate Challenge
# Create a PowerShell function to get the sum and average of every X number between 1 and a user specified maximum
function Get-IntermediateCountingChallenge {
param(
[int]$Step,
[int]$Max
)
$NumberArray = for ($i = 1; $i -le $Max; $i = $i + $Step) { $i }
@thedavecarroll
thedavecarroll / markdown.json
Created May 11, 2020
Markdown Snippet for Visual Studio Code
View markdown.json
{
// insert markdown links
"Insert Link" : {
"prefix": "link",
"body": [
"[text][text]{:target=\"_blank\"}"
]
},
"Insert Reference" : {
"prefix": "ref",
@thedavecarroll
thedavecarroll / DemoExperimentalFeatures.psd1
Last active Mar 12, 2020
PowerShell 7 Experimental Features Demo
View DemoExperimentalFeatures.psd1
@{
RootModule = 'DemoExperimentalFeatures.psm1'
ModuleVersion = '0.7.0'
CompatiblePSEditions = 'Core'
GUID = 'a007643e-c876-4806-b6cb-367963716e98'
Author = 'Dave'
CompanyName = 'thedavecarroll'
@thedavecarroll
thedavecarroll / Test-MarkdownFileLinks.ps1
Last active Feb 2, 2020
Test Links in Markdown Files with PowerShell (and Regex)
View Test-MarkdownFileLinks.ps1
@thedavecarroll
thedavecarroll / 1 - WordPressApi.psm1
Last active Dec 22, 2019
IronScripter Challenge - December 17, 2019 - A PowerShell Challenge for Challenges
View 1 - WordPressApi.psm1
function Get-WPSite {
[CmdLetBinding()]
param(
[Parameter(Mandatory)]
[uri]$Url
)
if ($Url.AbsoluteUri -notmatch 'wp-json') {
[uri]$Url = $Url.AbsoluteUri,'wp-json' -join '/'
}
@thedavecarroll
thedavecarroll / EventData.psm1
Last active Apr 23, 2020
Create New Windows Event Source (Provider) and Write Unnamed EventData
View EventData.psm1
function New-EventSource {
[CmdLetBinding()]
param(
[string]$EventLog,
[string]$Source
)
if ([System.Diagnostics.EventLog]::SourceExists($Source) -eq $false) {
try {
[System.Diagnostics.EventLog]::CreateEventSource($Source, $EventLog)
You can’t perform that action at this time.