Skip to content

Instantly share code, notes, and snippets.

View PanosGreg's full-sized avatar

Panos Grigoriadis PanosGreg

  • Dublin, Ireland
View GitHub Profile

Keybase proof

I hereby claim:

  • I am panosgreg on github.
  • I am panosg (https://keybase.io/panosg) on keybase.
  • I have a public key ASAx9YCaHV53FwOXOIl66R9htjStsTv4Y-DNHhnjU_uYMgo

To claim this, I am signing this object:

@PanosGreg
PanosGreg / Install-PowerShell.ps1
Last active October 15, 2021 15:26
Install-PowerShell
function Install-PowerShell {
<#
.SYNOPSIS
Installs latest PowerShell 7 via msi, from GitHub.
You need to:
a) run this from PS 5 (not PS 7) on windows (not linux)
b) have internet connectivity (and able to access github.com)
c) and have rights to install apps (usually local admin privileges)
.EXAMPLE
Install-PowerShell -Verbose
function New-UserProfile {
<#
.EXAMPLE
New-UserProfile -DomainName MyLab -UserName MyUser -Verbose
#>
[cmdletbinding()]
[OutputType([System.IO.DirectoryInfo])]
param(
[Parameter(Mandatory=$true)]
[String]$UserName,
function Get-ProcessHandle {
<#
.SYNOPSIS
Get all the currently open handles of a process
NOTE: requires the handle.exe tool from Sysinternals
.EXAMPLE
Get-ProcessHandle -PID 12000 -IncludeMode
#>
[cmdletbinding()]
@PanosGreg
PanosGreg / Encrypt-Decrypt-WithDotNet.ps1
Last active April 1, 2024 17:13
Encryption & Decryption using native .NET classes
## Encryption & Decryption using native .NET functions
## This is Symetrical encryption. Which means the same key is used to both encrypt and decrypt.
## The encryption method is based on AES 256bit.
## The major difference between this option and the ConvertFrom/To-SecureString functions
## is that this way produces much smaller encrypted files.
## I have not compared the 2 options in regards to performance though, as-in which one is faster.
@PanosGreg
PanosGreg / Encrypt-Decrypt-WithConvert.ps1
Last active March 24, 2022 11:59
Encryption & Decryption using native PowerShell Convert functions
## Encryption & Decryption via ConvertFrom-SecureString and ConvertTo-SecureString
## This is Symetrical encryption. Which means the same key is used to both encrypt and decrypt.
## The encryption method is based on AES 256bit.
$KeyFile = 'c:\temp\AWS.key'
$EncFile = 'c:\temp\AWS.aes'
@PanosGreg
PanosGreg / Sorting-OLD.ps1
Last active April 27, 2023 16:03
3 different options to Sort
# 3 different options to Sort:
# 1) via an IComparer class,
# using the Sort() method from List and ArrayList
# or just instantiate a SortedSet
# 2) via LINQ
# using the OrderBy() method
# 3) via Sort() method from [Array]
@PanosGreg
PanosGreg / Get-ReverseString.ps1
Created June 25, 2022 23:04
Exercise: Reverse any letters of the input string
function Get-ReversedString {
<#
.SYNOPSIS
Reverse any letters of the input string
.EXAMPLE
Get-ReversedString '!abc123def456!'
# returns: !cba123fed456!
#>
[OutputType([string])]
[CmdletBinding()]
function Test-TcpConnection {
<#
.SYNOPSIS
Check connectivity on a specific TCP port
.DESCRIPTION
Check connectivity on a specific TCP port
This function does not support Proxy settings. Which means if you are using a proxy
then you need to configure it beforehand on either the computer or user level.
.EXAMPLE
Test-TcpConnection 10.1.1.0 22 -Verbose
function Test-TrueForAll {
<#
.SYNOPSIS
Checks if all items in an array have the same value
.EXAMPLE
'a','a','b' | Test-TrueForAll -ShouldBe 'a'
# returns False
.EXAMPLE
$false,$false,$false | Test-TrueForAll -ShouldBe $false
# returns True