Skip to content

Instantly share code, notes, and snippets.

View craig-martin's full-sized avatar

Craig Martin craig-martin

View GitHub Profile
@craig-martin
craig-martin / Demo-BaseVM.ps1
Last active October 4, 2023 21:26
Create a VM in Hyper-V then Run DSC to Install SQL
#Install-Module -Name Convert-WindowsImage
#Requires module dism : https://docs.microsoft.com/en-us/powershell/module/dism/get-windowsoptionalfeature?view=win10-ps
Set-Location $HOME
$isoFilePath = 'F:\ISO\en_windows_server_2016_updated_feb_2018_x64_dvd_11636692.iso'
$SwitchName = Get-VMSwitch -SwitchType External | Select-Object -expand Name -First 1
$ImageName = 'Windows Server 2016 Datacenter (Desktop Experience)'
$ImageVhdFilePath = 'F:\VMs\Virtual Hard Disks\WindowsServer2016-Image.1.vhdx'
@craig-martin
craig-martin / ConvertEpoch-ToDateTime.ps1
Created August 8, 2019 21:34
Convert Epoch to DateTime with PowerShell
function ConvertEpoch-ToDateTime
{
<#
.Synopsis
Converts an epoch to a DateTime
.DESCRIPTION
Needed this for validating JWT tokens using PowerShell. Times were specified as NumericDate per RFC7519 (https://tools.ietf.org/html/rfc7519#section-4.1.4)
.EXAMPLE
ConvertEpoch-ToDateTime -NumericDate 1565298477
.EXAMPLE
@craig-martin
craig-martin / Renew-AccessToken.ps1
Created August 8, 2019 21:49
Using a Refresh Token in PowerShell
<#
This snippet assumes a valid refresh token. To see how to get one of those, check out:
https://www.thelazyadministrator.com/2019/07/22/connect-and-navigate-the-microsoft-graph-api-with-powershell/#3_Authentication_and_Authorization_Different_Methods_to_Connect
#>
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2" # This is the standard client ID for Windows Azure PowerShell
$redirectUrl = [System.Uri]"urn:ietf:wg:oauth:2.0:oob" # This is the standard Redirect URI for Windows Azure PowerShell
$tenant = "fabrikam.onmicrosoft.com" # TODO - your tenant name goes here
$resource = "https://graph.microsoft.com/";
$serviceRootURL = "https://graph.microsoft.com//$tenant"
@craig-martin
craig-martin / Split-JsonFile.ps1
Created November 20, 2025 17:34
PowerShell script function to split a JSON file into chunks
function Split-JsonFile
{
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string]$Path,
[Parameter()]
[long]$MaxChunkBytes = 8MB, # Keep chunks safely under 10MB for the Kusto ingestion REST API