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 / Get-ImageFromHub.ps1
Created October 4, 2025 15:57
Find the docker image from Docker Hub, for the current Windows Server OS
function Get-ImageFromHub {
<#
.SYNOPSIS
Find the docker image for the current Windows Server OS from Docker Hub.
Additionally it can also inspect the image and get its size (from all of its layers)
NOTE: This function does not download the docker image, just its metadata.
The -ShowSize switch requires the docker tool.
.EXAMPLE
Get-ImageFromHub -ShowSize
@PanosGreg
PanosGreg / Get-ProcessWithService.ps1
Last active October 5, 2025 18:00
Get the processes along with their relevant service (if any), just like "tasklist /svc"
function Get-ProcessWithService {
<#
.SYNOPSIS
Get the processes along with the relevant service associated to each process (if any)
This is the equivalent to "tasklist /svc" cmd command.
.EXAMPLE
Get-ProcessWithService | where Service | select ProcessId,Name,Service
.NOTES
WMI Query Language (WQL) WHERE Clause
https://learn.microsoft.com/en-us/windows/win32/wmisdk/where-clause
@PanosGreg
PanosGreg / Install-VscodeExtension.ps1
Created September 11, 2025 00:47
Install VS Code extension. I had an issue due to proxy and certs, this function has a workaround for that.
# this hashtable is used on the extension name validation for the input
# it is also used to get the extension id
$script:VSCodeExtensions = @{
'vscode-icons' = 'vscode-icons-team.vscode-icons'
powershell = 'ms-vscode.powershell'
csharp = 'ms-dotnettools.csdevkit'
terraform = 'hashicorp.terraform'
}
# Note: if this was a module, we could have this in a .psd1 file
@PanosGreg
PanosGreg / GetComputerName.ps1
Created August 27, 2025 11:58
All the different ways to get the Computer Name
# ENV variable
$env:COMPUTERNAME
# Note: this is limited to 15 characters
# native C++
hostname.exe
# Note: this shows the full name <<=====
# environment class
@PanosGreg
PanosGreg / Test-ADCredential.ps1
Last active August 26, 2025 08:01
Verify Active Directory credentials
function Test-ADCredential {
<#
.Synopsis
Verify Active Directory credentials
.EXAMPLE
Test-ADCredential -Username user1 -Password Secret01
#>
[CmdletBinding(DefaultParameterSetName = 'PSCreds')]
[OutputType([Boolean])]
@PanosGreg
PanosGreg / Resolve-AmazonARN.ps1
Last active July 18, 2025 15:52
Parse an Amazon Resource Name (ARN) into its individual parts
function Resolve-AmazonArn {
<#
.SYNOPSIS
Parse an Amazon Resource Name (ARN) into its individual parts.
.EXAMPLE
'arn:aws:iam::111222333444:role/MyRole' | Resolve-AmazonArn
.EXAMPLE
Resolve-AmazonArn arn:aws:s3:::MyBucket/MyFolder/*
.EXAMPLE
Resolve-AmazonArn s3://MyBucket/MyFolder/MyFile.json
@PanosGreg
PanosGreg / Start-RunspaceJob.ps1
Last active May 27, 2025 07:41
Run a scriptblock in a timer using a runspace
function Start-RunspaceJob {
<#
.SYNOPSIS
It runs a command on a timer, so it can abort the command if the timeout expires.
It can also run the command as a different user.
It allows the end-user to pass input parameters to the command.
.EXAMPLE
Start-RunspaceJob -Scriptblock {
$p1 = ' ' * 9 ; $p2 = ' ' * 18
Write-Verbose "$p1 1 [V] Will do A" -Verbose
@PanosGreg
PanosGreg / Get-AmazonApiOperation.ps1
Created May 9, 2025 08:45
Get the relevant AWS API Operation for a given PowerShell command
function Get-AmazonApiOperation {
<#
.SYNOPSIS
Show the relevant AWS API Operation for a given PowerShell command
.DESCRIPTION
This function comes handy when writing permissions for IAM roles.
Because you need to know the actions (as-in API operations) that you want to allow in the IAM policy.
.EXAMPLE
Get-Command -Noun EC2Tag | Get-AmazonApiOperation
@PanosGreg
PanosGreg / Test-PasswordComplexity.ps1
Last active April 24, 2025 17:08
Check if a password meets a minimum required complexity
function Test-PasswordComplexity {
<#
.SYNOPSIS
It checks if a password meets the minimum required password complexity
.EXAMPLE
Test-PasswordComplexity -Password 123asdASD -MinComplex 2 -MinLength 6 -MinUpper 2 -MinLower 2 -MinDigits 2 -MinSpecial 2
Returns True. Because the password is more than 6 characters long. It is actually 9 characters long.
And it has more than 2 different character types. Namely it has lower, upper and numbers which are 3 different types.
And out of those character types is has the minimum number of characters required for each type.
@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)