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
# 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 } |
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
<# | |
.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. |
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
$TestSize = 500kb | |
$LargeArrayList = New-Object -TypeName "System.Collections.ArrayList" | |
$AllTests = foreach($i in (1..$TestSize)){ | |
$Guid = ((New-Guid).ToString()) | |
[PSCustomObject]@{ | |
TestName = 'Out-Null' |
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
# 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}} |
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
#How to migrate from AAP to RBAC | |
#region basic connects | |
$connectMgGraphSplat = @{ | |
Scopes = @( | |
'AppRoleAssignment.ReadWrite.All', | |
'Application.ReadWrite.All', | |
'User.Read.All' | |
) | |
NoWelcome = $true |
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
$GetValueOrDefault = { | |
param( | |
[string]$key, | |
$defaultValue | |
) | |
$this.ContainsKey($key) ? $this[$key] : $defaultValue | |
} | |
$etd = @{ | |
TypeName = 'System.Collections.Hashtable' | |
MemberType = 'Scriptmethod' |
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 Write-MultiLineFeedback { | |
[CmdletBinding()] | |
param ( | |
$Feedback | |
) | |
begin { | |
$CursorPosition = $Host.UI.RawUI.CursorPosition.Y | |
$Feedback.ForEach({ | |
$PSItem.Line = $CursorPosition |
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
$Attach = Get-ChildItem -Path "Path2Files" -Filter "*.Attach" | foreach{ | |
$_.FullName | |
} | |
foreach($AttachFile in $Attach){ | |
Do-Something | |
} |