Skip to content

Instantly share code, notes, and snippets.


Mark Kraus markekraus

View GitHub Profile
markekraus / HttpClient-Example.ps1
Created Nov 25, 2020
Example using HttpClient in PowerShell
View HttpClient-Example.ps1
# Create single HttpClient
$client = [System.Net.Http.HttpClient]::new()
# Perform multiple GETs
foreach ($url in $urls) {
$clientResult = $client.GetStringAsync($url).
$clientResult | ConvertFrom-Json
markekraus / examples.ps1
Created Jul 15, 2020
PowerShell Core HTTP Redircet Capture
View examples.ps1
# PowerShell 7
$uri = ''
$result = Invoke-WebRequest -SkipHttpErrorCheck -Uri $uri -MaximumRedirection 0 -ErrorAction SilentlyContinue -ErrorVariable $err
$location = $result.Headers.Location
# PowerShell 6
$uri = ''
try {
Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Stop
} catch {
markekraus /
Last active May 22, 2020
PSConfBook3 Author Expectations

PSConfBook3 Author Expectations

While we want this to be a fun, collaborative, and creative process, we still wish to produce a high-quality book we can all be proud of, and readers will be happy to purchase. Editing large numbers of chapters, each from different authors is a significant effort. We have the following expectations of our authors to ease the editing process and ensure a baseline of quality.

What does the project expect of the authors?

  • The authors must follow our style and writing guidelines we publish in the GitHub repository.
  • The authors must proofread their chapters at least three (3) times before submitting their final draft.
markekraus /
Last active Mar 5, 2020
PSConfBook3 Copyright Information

Copyright Agreement

This document sets forth an understanding of copyright related issues between you, Contributor and the editors of the Book, tentatively titled The PowerShell Conference Book Volume 3. The Book is being developed and sold as a charitable, not-for-profit, venture. Your participation is considered entirely voluntary. Your contributions to the project, which includes your time, written material, and PowerShell code are to be considered charitable contributions. The only Contributor compensation will be one (1) free electronic copy of the Book from the original publisher.

All royalties and income generated from sales of the Book will be contributed to charitable cause. That cause is currently designated to support scholarships as part of the OnRamp program sponsored by The DevOps Collective.

markekraus / ExampleBracketFileUpload.ps1
Created Mar 6, 2019
Example of uploading a file with brackets in the name
View ExampleBracketFileUpload.ps1
New-Item -ItemType File -Path 'c:\temp\[a].txt' -value 'Test' -Force
Invoke-RestMethod -InFile 'c:\temp\`[a`].txt' -Method Post -Uri -ContentType 'text/plain'
args :
data : Test
files :
View BustedEnumerator.ps1
class MyEnumerator : System.Collections.IEnumerator {
hidden static [bool]$toggle = $true
hidden static [bool]$toggle2 = $true
MyEnumerator (){}
[bool] MoveNext()
if([MyEnumerator]::toggle) {
[MyEnumerator]::toggle = $false
markekraus / ARM-Logic.txt
Created Jan 8, 2019
Perform Conditional Operations on Parameters in Azure ARM templates
View ARM-Logic.txt
markekraus /
Last active Nov 9, 2021
Az to AzureRm Cmdlet Mappings

Az to AzureRM command Mappings



Az Command AzureRm Command
Get-AzAks Get-AzureRmAks
New-AzAks New-AzureRmAks
markekraus / Out-Default.ps1
Created Jun 15, 2018
Cheap Screen reader code for PowerShell
View Out-Default.ps1
Function Out-Default {
markekraus / Get-AADBitLockerRcoveryKey.ps1
Last active Jun 6, 2018
Get BitLocker Recovery Key from Azure AD
View Get-AADBitLockerRcoveryKey.ps1
#Requires -Modules AzureRM.Profile, AzureAD
$DeviceObjectId = '' # Set an objectID for a device
$SubScriptionID = '' # change with your subscription ID
$Subscription = Select-AzureRmSubscription -Subscription $SubScriptionID
$currentAzureContext = Get-AzureRmContext -Name $Subscription.Name
$TenantId = $currentAzureContext.Tenant.Id
$tokenCache = $currentAzureContext.TokenCache
$Cache = $tokenCache.ReadItems().Where({$_.ExpiresOn -gt (Get-Date) -and $_.TenantId -eq $TenantId })[0]