Skip to content

Instantly share code, notes, and snippets.

View JustinGrote's full-sized avatar

Justin Grote JustinGrote

View GitHub Profile
@JustinGrote
JustinGrote / Trace-AICommand.ps1
Last active April 9, 2024 22:25
Report the results and performance of any scriptblock to Azure Application Insights
#requires -version 7
#You can load this script with $(iwr https://tinyurl.com/TraceAICommand | iex)
using namespace Microsoft.ApplicationInsights
using namespace Microsoft.ApplicationInsights.Extensibility
using namespace Microsoft.ApplicationInsights.DataContracts
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Net
#Reference: https://docs.microsoft.com/en-us/azure/azure-monitor/app/console
@JustinGrote
JustinGrote / Select-StringMatch.ps1
Last active October 24, 2022 14:56
A companion to Select-String to more easily retrieve the results of capture groups, similar to $matches but pipeline friendly.
filter Select-StringMatch {
<#
.SYNOPSIS
A companion to select-string to quickly fetch the value of a capture group, named or indexed
.DESCRIPTION
With -replace or -match we have the simple $matches['group'] syntax, but this doesn't really exist for Select-String
and the typical options are not pipeline friendly. The default object returned from Select-String is not that friendly
either if all you want is the value(s) of a capture group to then pipe to another command. This is basically a pipeline
friendly version of $matches.
@jborean93
jborean93 / New-EXOPSSession.ps1
Last active September 20, 2022 19:05
Cross platform function that can connect to Exchange Online using modern auth
# Copyright: (c) 2020, Jordan Borean (@jborean93) <jborean93@gmail.com>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
#Requires -Module MSAL.PS
Function New-EXOPSSession {
<#
.SYNOPSIS
Will open a PSSession to Exchange Online.
@JustinGrote
JustinGrote / Get-WinEventXPathFilter.ps1
Last active October 4, 2023 14:55
Get-WinEventXPathFilter
Function Get-WinEventXPathFilter
{
<#
.SYNOPSIS
This function generates an xpath filter that can be used with the -FilterXPath
parameter of Get-WinEvent. It may also be used inside the <Select></Select tags
of a Custom View in Event Viewer.
.DESCRIPTION
This function generates an xpath filter that can be used with the -FilterXPath
parameter of Get-WinEvent. It may also be used inside the <Select></Select tags
@JustinGrote
JustinGrote / Word2013.css
Created December 16, 2015 21:54
Word/Excel 2013 CSS style for Powershell ConvertTo-HTML
*
{
font-family:Calibri,sans-serif;
font-size:11pt;
}
p
{
margin:0 0 8pt;
}
td p
@jstangroome
jstangroome / Get-RemoteSSLCertificate.ps1
Last active December 8, 2023 21:38
PowerShell script to retrieve the public X509 certificate from a remote TLS endpoint
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]
$ComputerName,
[int]
$Port = 443
)
@markembling
markembling / hosts.ps1
Created August 24, 2009 13:38
Powershell script for adding/removing/viewing entries to the hosts file.
#
# Powershell script for adding/removing/showing entries to the hosts file.
#
# Known limitations:
# - does not handle entries with comments afterwards ("<ip> <host> # comment")
#
$file = "C:\Windows\System32\drivers\etc\hosts"
function add-host([string]$filename, [string]$ip, [string]$hostname) {