Skip to content

Instantly share code, notes, and snippets.

View thedavecarroll's full-sized avatar
🧑‍💻
PowerShell Summit

Dave Carroll thedavecarroll

🧑‍💻
PowerShell Summit
View GitHub Profile
@thedavecarroll
thedavecarroll / markdown.json
Created May 11, 2020 19:16
Markdown Snippet for Visual Studio Code
{
// insert markdown links
"Insert Link" : {
"prefix": "link",
"body": [
"[text][text]{:target=\"_blank\"}"
]
},
"Insert Reference" : {
"prefix": "ref",
@thedavecarroll
thedavecarroll / SearchADDnsRecord.psm1
Last active January 8, 2024 16:09
This simple PowerShell script module uses a custom class and Get-ADObject to search an Active Directory-integrated DNS Zone by name or partial name.
#Requires -Version 5.1
#Requires -Module ActiveDirectory
$script:ADRootDSE = Get-ADRootDSE
class ADDnsNode {
# AD Object Properties
[String]$Name
[String]$CanonicalName
@thedavecarroll
thedavecarroll / Part1-ConvertTo-ClassDefinition.ps1
Last active May 30, 2023 13:35
Creating a Class Definition from an Existing Object - Ironscripter Challenge
#Requires -Version 5.1
function ConvertTo-ClassDefinition {
param(
[Parameter(Position = 0, Mandatory, ValueFromPipeline)]
[object]$Object,
[ValidateNotNullOrEmpty()]
[string]$ClassName,
@thedavecarroll
thedavecarroll / 1 - SimpleFunctions.ps1
Last active January 10, 2023 23:15
IronScripter Challenge - November 15, 2019 - Beginner PowerShell Function
function ConvertTo-Celsius {
param($Fahrenheit)
($Fahrenheit - 32) * 5/9
}
function ConvertTo-Fahrenheit {
param($Celsius)
($Celsius * 9/5) + 32
}
@thedavecarroll
thedavecarroll / Join-OxfordComma.ps1
Last active November 19, 2022 04:23
The Join-OxfordComma command can provide you a comma separated list using the Oxford comma and either 'and' or 'or'.
function Join-OxfordComma {
[CmdletBinding(DefaultParameterSetName='And')]
[Alias('jox')]
param(
[Parameter(Mandatory,ValueFromPipeline)]
[string[]]$JoinList,
[Parameter(ParameterSetName='And')]
[switch]$And,
[Parameter(ParameterSetName='Or')]
[switch]$Or
@thedavecarroll
thedavecarroll / cibuild
Last active September 9, 2022 05:29
Recent Changes to the Site - thedavecarroll.com
#!/usr/bin/env bash
set -e # halt script on error
echo
echo "------------------------------------------------------------------------------------------------------------------------"
echo
if [ "$TRAVIS_PULL_REQUEST" != "false" -a "$TRAVIS_BRANCH" == "comments" ]; then
echo "Building site for pull request for $TRAVIS_BRANCH..."
echo
@thedavecarroll
thedavecarroll / Add-TimeSpan.sp1
Created August 10, 2022 08:11
Simple function to add timespan
function Add-TimeSpan {
[CmdLetBinding(DefaultParameterSetName='TimeSpan')]
param(
[Parameter()]
[datetime]$Timestamp = (Get-Date),
[Parameter(Mandatory,ParameterSetName='TimeSpan')]
[timespan]$TimeSpan,
[Parameter(ParameterSetName='TimeSlice')]
[int]$Days,
[Parameter(ParameterSetName='TimeSlice')]
@thedavecarroll
thedavecarroll / WindowsForms.psm1
Last active July 4, 2022 09:24
WindowsForms ad hoc module and an example script
# ----------------------------------------------------------------------------------------------------------------------
# Functions required to create PowerShell GUI using System.Windows.Forms
# ----------------------------------------------------------------------------------------------------------------------
#region load assemblies
try {
[Void][reflection.assembly]::loadwithpartialname('System.Windows.Forms')
[Void][reflection.assembly]::loadwithpartialname('System.Drawing')
}
catch {
@thedavecarroll
thedavecarroll / myboto3_client.py
Last active March 30, 2022 15:24
Python Exception Logger and Boto3 Client
import boto3
from mylogger import logger,log_exception
def create_session(profile_name='default'):
logger.info(f'Creating new boto3 session with profile {profile_name}')
try:
return boto3.session.Session(profile_name=profile_name)
except:
raise Exception( log_exception() )
function Split-Array {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[String[]] $InputObject
,
[ValidateRange(1, [int]::MaxValue)]
[int] $Size = 10
)
begin { $items = New-Object System.Collections.Generic.List[object] }