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 |
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 ConvertTo-ClassDefinition { | |
<# | |
.EXAMPLE | |
$hash = @{name='aa';size=10} | |
$code = $hash | ConvertTo-ClassDefinition | |
Invoke-Expression $code | |
$h = [My_Hashtable]::new() | |
# create and load a class from a hashtable | |
.EXAMPLE | |
$obj = [pscustomobject]@{name='aa';size=10} |
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 Invoke-ForEachParallel { | |
<# | |
.SYNOPSIS | |
This is a wrapper around foreach-parallel from PS v7, but with progress bars. | |
.DESCRIPTION | |
This is a wrapper around foreach-parallel from PS v7, but with progress bars. | |
You can run a scriptblock against an array of objects, just like foreach, | |
but it also shows multi-threaded progress bars, one for every thread. |
NewerOlder