This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Parameter Sets Examples | |
# Example #1 | |
# Choose 1 or 2 out of 2 | |
# order is not important | |
<# Combinations: 3 in total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-WindowsVersion { | |
<# | |
.SYNOPSIS | |
It provides the equivalent information to winver.exe | |
.EXAMPLE | |
Get-WindowsVersion | |
#> | |
[cmdletbinding()] | |
param () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder