Skip to content

Instantly share code, notes, and snippets.

View markekraus's full-sized avatar
😀

Mark Kraus markekraus

😀
View GitHub Profile
@markekraus
markekraus / Test-StringExpansionScoping.ps1
Created April 18, 2018 18:14
String Expansion Scoping... Wat?
$MyObjGlobal = [PSCustomObject]@{
PSTypeName = 'MyObj'
Prop1 = 'Value1'
}
$MyObjFunction = [PSCustomObject]@{
PSTypeName = 'MyObj'
Prop1 = 'Value1'
}

Keybase proof

I hereby claim:

  • I am markekraus on github.
  • I am markekraus (https://keybase.io/markekraus) on keybase.
  • I have a public key ASAQRsY5KChGA8ePPV6gQ5ilSZ4KFmVciWsQL-ud4zZnGAo

To claim this, I am signing this object:

@markekraus
markekraus / Get-AADBitLockerRcoveryKey.ps1
Last active June 6, 2018 12:26
Get BitLocker Recovery Key from Azure AD
#Requires -Modules AzureRM.Profile, AzureAD
$DeviceObjectId = '' # Set an objectID for a device
$SubScriptionID = '' # change with your subscription ID
Add-AzureRmAccount
$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]
@markekraus
markekraus / Out-Default.ps1
Created June 15, 2018 19:05
Cheap Screen reader code for PowerShell
Function Out-Default {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline)]
[PSObject]
$InputObject,
[switch]
$Transcript
)
@markekraus
markekraus / ARM-Logic.txt
Created January 8, 2019 15:21
Perform Conditional Operations on Parameters in Azure ARM templates
[
if(
equals(
parameters('settings')[copyIndex('settings')].type,
'static'
),
parameters('settings')[copyIndex('settings')].value,
if(
equals(
parameters('settings')[copyIndex('settings')].type,
@markekraus
markekraus / BustedEnumerator.ps1
Created January 16, 2019 02:12
Busted Enumerator
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
markekraus / GetInboxRuleReport.ps1
Last active January 31, 2019 18:33
Generates Multi-Threaded Office 365 Inbox Rule Report That Scales with the Number of Service Accounts Provided
using namespace System.Collections.Concurrent
$StartDate = [datetime]::UtcNow
# can be generated with something like
# 1..10 | %{ Get-Credential} | Export-CliXml -path 'C:\reports\InboxRules\Creds.xml'
# Which will prompt for credentials 10 times and store them in the xml file
$CredentialFile = 'C:\reports\InboxRules\Creds.xml'
$RunDate = $StartDate.ToString('o') -replace ':'
# This is the path of the CSV file. It is imperative that this file not be
# access while the script is running
@markekraus
markekraus / ExampleBracketFileUpload.ps1
Created March 6, 2019 02:45
Example of uploading a file with brackets in the name
New-Item -ItemType File -Path 'c:\temp\[a].txt' -value 'Test' -Force
Invoke-RestMethod -InFile 'c:\temp\`[a`].txt' -Method Post -Uri https://httpbin.org/post -ContentType 'text/plain'
<#
Result:
args :
data : Test
files :
@markekraus
markekraus / README.md
Last active March 5, 2020 01:54
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
markekraus / README.md
Last active May 22, 2020 14:41
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.