Skip to content

Instantly share code, notes, and snippets.

View PanosGreg's full-sized avatar

Panos Grigoriadis PanosGreg

  • Dublin, Ireland
View GitHub Profile
@PanosGreg
PanosGreg / Split-ByGroup.ps1
Created March 18, 2025 22:23
Split an array into chunks and return a number of arrays based on a group size.
function Split-ByGroup {
<#
.SYNOPSIS
It will split an array into chunks and return a number of arrays based on a group size
.EXAMPLE
# first create a sample array (I'm using the RNG class here to do that)
$ArraySize = 160
$Array = [byte[]]::new($ArraySize)
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($Array)
@PanosGreg
PanosGreg / Disable-WingetPinning.ps1
Last active March 18, 2025 09:41
Disable WinGet certificate pinning for the MS Store source
function Disable-WingetPinning {
<#
.SYNOPSIS
It disables the Certificate Pinning option in WinGet for the MS Store source.
This is usually required when there is a firewall on your network that inspects SSL traffic,
where you might get an error 0x8a15005e back from WinGet, as it cannot access the msstore endpoint URL.
.DESCRIPTION
If you are behind a firewall that inspects SSL traffic,
that means it decrypts & re-encrypts traffic on the fly in order to inspect it.
@PanosGreg
PanosGreg / Sorting-IComparer.ps1
Created February 24, 2025 13:27
How to make a custom type sortable in PowerShell (with IComparer)
# How to make a custom type sortable
# There are 2 ways to make a type sortable
#
# 1) you can inherit from the IComparable interface [System.IComparable]
# where you will compare based on a predefined property of the object
# and you need to implement the CompareTo() method
#
# 2) you can create a custom Comparer type that will inherit from the IComparer interface [System.Collections.Generic.IComparer[T]]
@PanosGreg
PanosGreg / NewRelic.ps1
Last active February 11, 2025 18:58
New Relic functions for Synthetic Monitors (enable/disable, get) and API Keys (get)
# change this Enum with your actual accounts and their IDs
enum NewRelicAccountName {
NRAcc1 = 300000
NRAcc2 = 400000
NRAcc3 = 500000
NRAcc4 = 600000
}
function Get-NRMonitor {
@PanosGreg
PanosGreg / Get-DurationText.ps1
Created December 26, 2024 12:05
Get the elapsed duration as a string
function Get-DurationText {
<#
.SYNOPSIS
Get the elapsed duration as a string, in a number of different formats
.EXAMPLE
Get-DurationText -Duration ([timespan]::FromDays(2))
2d 0hr
#>
[CmdletBinding(DefaultParameterSetName='Timespan')]
[OutputType([string])]
@PanosGreg
PanosGreg / Encryption-Decryption_AES128-AES256.ps1
Last active December 10, 2024 16:14
Encryption-Decryption with and without .NET streams & Key Generation with PBKDF
# I wrote these notes in Sep-2024
# AES 128 and 256 bits
# Without using .NET Streams
## Initial Input
[string]$PlainText = 'this is a test message'
[string]$Password = 'SampleSecret'
@PanosGreg
PanosGreg / Get-ArgumentCompleter.ps1
Last active October 22, 2024 20:32
Get the argument completers that are registered in the current session (if any)
function Get-ArgumentCompleter {
<#
.SYNOPSIS
Get the argument completers that are registered in the current session (if any)
.EXAMPLE
Import-Module PowerShellGet
Get-ArgumentCompleter
shows the argument completers that are registered from the PowerShellGet module
.EXAMPLE
@PanosGreg
PanosGreg / Get-AzRequestInfo.ps1
Created October 13, 2024 15:50
Get the web request details from an azure command
function Get-AzRequestInfo {
<#
.SYNOPSIS
It gets the web request details from an azure command.
IMPORTANT:
The azure command must be run with the -Debug switch AND you need to collect the debug stream
.EXAMPLE
$ResGrp = Get-AzResourceGroup -Name mysub -Location eastus2 -Debug 5>&1
Get-AzRequestInfo $ResGrp
@PanosGreg
PanosGreg / Hex_Conversions.ps1
Created September 1, 2024 19:36
Hex Conversions (from/to Hex)
# Convert to/from Hex
### From Byte array to Hex String
$bytes = [byte[]](10,20,30,40)
# a) via .ToString() method
$bytes.ForEach({$_.ToString('x2')}) -join ''
@PanosGreg
PanosGreg / Get-TaskManager.ps1
Last active September 1, 2024 17:38
Get a result like task-manager on the console
function Get-TaskManager {
<#
.SYNOPSIS
Gets the CPU, memory and disk utilization of the top X processes (by default 10)
The command can also query remote computers.
Sorting works based on the processes with the highest CPU utilization.
.DESCRIPTION
Very briefly, these are the steps taken by this command as part of its process workflow:
- Load an internal function, the Get-TaskUsage
- Remote to one or more computers with Invoke-Command and pass in the internal function