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 / 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
@PanosGreg
PanosGreg / ParamSet.ps1
Created June 24, 2024 08:41
PowerShell Parameter Sets
## Parameter Sets Examples
# Example #1
# Choose 1 or 2 out of 2
# order is not important
<# Combinations: 3 in total
@PanosGreg
PanosGreg / Get-WindowsVersion.ps1
Last active April 15, 2024 10:18
It provides the equivalent information to winver.exe
function Get-WindowsVersion {
<#
.SYNOPSIS
It provides the equivalent information to winver.exe
.EXAMPLE
Get-WindowsVersion
#>
[cmdletbinding()]
param ()
@PanosGreg
PanosGreg / Get-WinUpdate.ps1
Last active March 26, 2024 14:46
Get a list of the windows updates with a KB ID using the COM Microsoft.Update.Searcher
function Get-WinUpdate {
<#
.SYNOPSIS
Get a list of all the windows updates on the system
Note: This function will only show the updates that have a KB ID
Any hotfixes without an update ID won't be included in the results
.EXAMPLE
Get-WinUpdate | where Title -like '*cumulative update for windows*'
.EXAMPLE
@PanosGreg
PanosGreg / Get-RuntimeDiagnostics.ps1
Last active February 22, 2024 21:50
Collect the count and memory size of the .NET objects used by a process
function Get-RuntimeDiagnostics {
<#
.SYNOPSIS
Collect the count and memory size of the .net objects used by a process
.DESCRIPTION
Collect the count and memory size of the .net objects used by a process
This function is using the Microsoft.Diagnostics.Runtime .NET library from nuget:
https://www.nuget.org/packages/Microsoft.Diagnostics.Runtime
@PanosGreg
PanosGreg / Get-ADPrincipal.ps1
Last active April 24, 2024 08:37
Function that finds AD Principals, namely Users, Computers or Groups
function Get-ADPrincipal {
<#
.SYNOPSIS
Get users,computers or groups from Active Directory, without the need of the ActiveDirectory module.
The examples show the use of the .Members property, the .GetGroups() method and also
the .Add() and .Remove() methods from the group members list along with the .Save() method.
.EXAMPLE
Get-ADPrincipal *test*
@PanosGreg
PanosGreg / Get-AwsTempCredential.ps1
Last active April 24, 2024 08:46
Get AWS Credentials (access,secret,token) by assuming the IAM Role attached to the instance
function Get-AwsTempCredential {
<#
.SYNOPSIS
This function gets the AWS Access,Secret and Token by assuming the IAM Role that is attached to the current EC2 instance.
This should be used on EC2 instances only, not on any other VMs. (like Azure,GCP,Hyper-V or VMWare)
There should be an IAM Role attached to the instance, otherwise it won't work.
Once you get the temporary credentials, you can then login to AWS with "Set-AWSCredential"
or alternatively you can use the .LoginAWS() method from this object.
@PanosGreg
PanosGreg / Microsoft.Extensions.Configuration.ps1
Created December 2, 2023 14:14
Microsoft.Extensions.Configuration in PowerShell
## Drilling down into the Microsoft.Extensions.Configuration namespace from a PowerShell point-of-view
## Note: the inspiration for this came up by watching a .net video about configuration from Chris Ayers
# [.NET Configuration In Depth | .NET Conf 2023](https://www.youtube.com/watch?v=aOXaBZFB0-0)
## How to load a .dll which has some dependencies
## you just have to get the package from nuget which will also retrieve all of the dependencies
@PanosGreg
PanosGreg / Uniques.ps1
Created November 16, 2023 16:50
From a string array get the uniques and retain the order
# from a string array get the uniques and retain the order
# get the unique items from a string array with case-insensitive and also retain the current order
# this approach is to work-around the gap from Select-Object -Unique, which compares the object and not the property
# in the case of string arrays.
# and also to retain the order, whereas the Sort-Object -Unique would change the order
# source string array