Skip to content

Instantly share code, notes, and snippets.

View HCRitter's full-sized avatar

Christian Ritter | MVP HCRitter

View GitHub Profile
@HCRitter
HCRitter / FullPathHashtable.ps1
Created January 21, 2025 12:05
This PowerShell script creates a hierarchical list of objects with DisplayName, ID, and ParentID properties, organized into three levels. It also builds a HashTable to store these objects and calculates a FullPath property for each object by recursively resolving the hierarchy using the ParentID. The FullPath represents the hierarchical path fro…
# Define the list of objects
$objects = @(
# Level 1
[PSCustomObject]@{ DisplayName = "Root1"; ID = 1; ParentID = $null }
[PSCustomObject]@{ DisplayName = "Root2"; ID = 2; ParentID = $null }
# Level 2
[PSCustomObject]@{ DisplayName = "Child1.1"; ID = 3; ParentID = 1 }
[PSCustomObject]@{ DisplayName = "Child1.2"; ID = 4; ParentID = 1 }
<#
.SYNOPSIS
Retrieves Microsoft Graph audit log sign-in events filtered by type.
.DESCRIPTION
The Get-MSGraphAuditLogSignInByType function queries Microsoft Graph to retrieve audit log sign-in events and filters them based on the specified type. This can be useful for monitoring and analyzing sign-in activities within an organization.
.PARAMETER Type
Specifies the type of sign-in events to retrieve. This parameter is required.
$TestSize = 500kb
$LargeArrayList = New-Object -TypeName "System.Collections.ArrayList"
$AllTests = foreach($i in (1..$TestSize)){
$Guid = ((New-Guid).ToString())
[PSCustomObject]@{
TestName = 'Out-Null'
@HCRitter
HCRitter / FirstLineFast.ps1
Created May 7, 2024 12:20
How to get the first line of a really large file in PowerShell? Adam Bertram adviced to use the Select-Object -first 1 instead of (Get-Content -Path "file.txt")[0] # Which is correct, but maybe Switch -file is even faster? test based on https://x.com/adbertram/status/1781642880769032196
# How to get the first line of a really large file in PowerShell?
# Adam Bertram adviced to use the Select-Object -first 1 instead of (Get-Content -Path "file.txt")[0]
# Which is correct, but maybe Switch -file is even faster?
# test based on https://x.com/adbertram/status/1781642880769032196
$longfile = 'HugeFileList.txt' # One million lines - 49MB
# retreive the first line of a file very fast
$firstline = switch -file ($Longfile){Default{$_;break}}
#How to migrate from AAP to RBAC
#region basic connects
$connectMgGraphSplat = @{
Scopes = @(
'AppRoleAssignment.ReadWrite.All',
'Application.ReadWrite.All',
'User.Read.All'
)
NoWelcome = $true
$GetValueOrDefault = {
param(
[string]$key,
$defaultValue
)
$this.ContainsKey($key) ? $this[$key] : $defaultValue
}
$etd = @{
TypeName = 'System.Collections.Hashtable'
MemberType = 'Scriptmethod'
@HCRitter
HCRitter / jobs.ps1
Last active June 26, 2023 12:37
Jobsandmore
function Write-MultiLineFeedback {
[CmdletBinding()]
param (
$Feedback
)
begin {
$CursorPosition = $Host.UI.RawUI.CursorPosition.Y
$Feedback.ForEach({
$PSItem.Line = $CursorPosition
$Attach = Get-ChildItem -Path "Path2Files" -Filter "*.Attach" | foreach{
$_.FullName
}
foreach($AttachFile in $Attach){
Do-Something
}