Skip to content

Instantly share code, notes, and snippets.

@LeeHolmes
LeeHolmes / Get-TwitterThread.ps1
Created Nov 15, 2022
Recover your Twitter threads from your Twitter export data
View Get-TwitterThread.ps1
$tweetJson = (Get-Content .\tweets.js -Raw).Substring("window.YTD.tweets.part0 =".Length)
$tweets = $tweetJson | ConvertFrom-Json
$currentThread = ""
foreach($currentTweetJson in $tweets)
{
$currentTweet = $currentTweetJson.tweet
if($currentTweet.in_reply_to_screen_name -eq "Lee_Holmes")
{
@LeeHolmes
LeeHolmes / Watch-EventLogTail.ps1
Created Sep 10, 2022
Tail an event log through PowerShell
View Watch-EventLogTail.ps1
## PowerShell Eventing lets you tail an event log:
## http://powershellcookbook.com/recipe/IMyz/respond-to-automatically-generated-events
$watcher = New-Object System.Diagnostics.Eventing.Reader.EventLogWatcher "Microsoft-Windows-PowerShell/Operational"
Register-ObjectEvent $watcher EventRecordWritten -Action {
$event = $eventArgs.EventRecord
if($event.ProcessId -ne $pid)
{
## Save the last event into a variable in the PowerShell sesssion if you want to explore its properties,
## as the eventing actions run in their own runspace
# $GLOBAL:lastEvent = $event
View PowerShell Script Block Merge in Kusto
Event
| where EventID == "4104"
| extend ParsedEvent = parse_xml(strcat("<root>", ParameterXml, "</root>"))
| extend MessageNumber = tolong(ParsedEvent.root.Param[0])
| extend MessageTotal = tolong(ParsedEvent.root.Param[1])
| extend ScriptBlockElement = iff(
strlen(tostring(ParsedEvent.root.Param[2]["#text"])) > 0,
ParsedEvent.root.Param[2]["#text"],
ParsedEvent.root.Param[2])
| extend ScriptBlockId = tostring(ParsedEvent.root.Param[3])
View OutlookHeaders.txt
Received: from CY4PR21MB0742.namprd21.prod.outlook.com (2603:10b6:a03:12b::16)
by BYAPR21MB1208.namprd21.prod.outlook.com with HTTPS via
BYAPR07CA0075.NAMPRD07.PROD.OUTLOOK.COM; Fri, 3 Apr 2020 13:36:47 +0000
ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass;
b=FJkBxtEkCsT4VnSRJQ8yfPQ/lxlpLgu8AkfnnaMgnYyapQUH46RbVqXvhcoQO2eCvbpDf3Y855zQ9tmjmYqAuXauEDYFwuTuGzpTTl4k50TeFFwUUoY+3ZprT9HHM5xL/XpwIep31XSVu8hdRbTfysbONe3B18Who0HBUY6flZOqRcGt0qtWqumhwR93tfyrhKfvG7QWE4etvnIZx4ngs29usfjUjTPNJqD98Y4JaeNfBneEhE61x1wLzEaIQ12AJ6MtZn+lbJGBPfgaVAQ0zhpyIsXMi9KkXVaFN1sh9PzNWLatNJ1Ersx06d5dqlA98pPUJgeFb0kTfam7BHgGow==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=/HplSl9WQXo7X7X+V7lZVdH9hhQ5Nxt3DDHJ7t8uVwE=;
b=cRE9xpH8u43eExuoXIZpSVVxkANS5xx91mlgh2vvW79uHBM41YrCoLJjNMl3nJIpaItvnl41D7nbbQoVUMNz32TIWfXp5w9vSZOePvKeAqIeAXy/o6mj5XNZSjEN7k2zxx+qh3hDVlwwSVtGGMK5Al64N
View aparamecium.ps1
param(
[ScriptBlock] $ScriptBlock
)
function Invoke-Expression
{
param(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[String] $__InputObject
)
@LeeHolmes
LeeHolmes / profile.ps1
Created Mar 16, 2019
My PowerShell Profile
View profile.ps1
$historyItem = Get-History -Count 1
$id = 1
if($historyItem)
{
$id = $historyItem.Id + 1
## Check if the last command took a long time
if(($historyItem.EndExecutionTime - $historyItem.StartExecutionTime).TotalSeconds -gt 3)
{
@LeeHolmes
LeeHolmes / Get-Entropy.ps1
Created Mar 25, 2015
Get-Entropy with hotspot implemented via Add-Type
View Get-Entropy.ps1
## Not measurably faster. Doing this via Add-Type or direct PowerShell still takes about 4 seconds per megabyte.
function Get-Entropy
{
<#
.SYNOPSIS
Calculate the entropy of a byte array.
Derived from Get-Entropy by Matthew Graeber (@mattifestation)