Skip to content

Instantly share code, notes, and snippets.

View Manbearpiet's full-sized avatar
🏠
Working from home

Christian Piet Manbearpiet

🏠
Working from home
View GitHub Profile
@Manbearpiet
Manbearpiet / new-lighthouseroleassignmentexample.ps1
Last active March 20, 2025 09:46
Lighthouse role assignment example
$invokeAzRestMethodSplat = @{
Path = "/subscriptions/cceb1495-9940-4f29-abef-8fef7540161d/resourceGroups/DefaultResourceGroup-WEU/providers/Microsoft.Authorization/roleAssignments/$((New-Guid).Guid)?api-version=2022-04-01"
Method = 'PUT'
Payload = (
@{
properties = @{
roleDefinitionId = '/subscriptions/cceb1495-9940-4f29-abef-8fef7540161d/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7' # The only allowed roledefinitions are those under the lighthouse offer under delegatedRoleDefinitionIds
principalId = '3cb5e715-bb86-41b3-a240-1468814d0eb0' # Not the client ID but the OBJECT ID of the service principal
principalType = 'ServicePrincipal' # this must be a Service Principal else it won't work
delegatedManagedIdentityResourceId = '/subscriptions/cceb1495-9940-4f29-abef-8fef7540161d/resourceGroups/DefaultResourceGroup-WEU/providers/Microsoft.Managed
@Manbearpiet
Manbearpiet / nasa.md
Last active February 17, 2025 10:21
NASA video GPT suggestions

Here are PowerShell examples that align with NASA’s “Power of 10” coding principles:

  1. Avoid Complex Control Flow (No goto or Recursion)

PowerShell doesn’t support goto, but recursion should be avoided.

❌ Bad Example (Recursion)

function Get-Factorial {
 param ([int]$n)
@Manbearpiet
Manbearpiet / AuditAndHealthLogsSentinel.bicep
Last active January 16, 2025 12:20
Sentinel Audit and Health Logs Bicep
@description('The name of the diagnostic setting')
param diagnosticSettingName string = 'AuditAndHealthMonitoring'
@description('The Log Analytics workspace ID where diagnostics will be sent')
param workspaceResourceId string
resource reslogAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-10-01' existing = {
name: split(workspaceResourceId, '/')[8]
}
@Manbearpiet
Manbearpiet / parsemulticonfigdsc.ps1
Created January 9, 2025 16:30
Parse DSC Configuration File with multiple Configurations using the DSCParser module
$ast = [System.Management.Automation.Language.Parser]::ParseFile('C:\Temp\src\common\common.ps1', [ref]$null, [ref]$null)
$configurations = $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.ConfigurationDefinitionAst] }, $false)
$objectstable = $configurations.Extent.text | ForEach-Object {
ConvertTo-DSCObject -Content $_
}
$objectstable | Group-Object -Property ResourceName | ConvertTo-Json -Depth 10
@Manbearpiet
Manbearpiet / errors.md
Last active November 25, 2024 20:31
Errors.md

author: "Christian Piet" title: "How to work with error in PowerShell" date: 2024-11-20T20:00:00.0000000+01:00 draft: true description: "An basic course in PowerShell errors" tags: - errors series: powershell aliases:

@Manbearpiet
Manbearpiet / location.kql
Created November 21, 2024 07:45
Detect resources in other regions than resourcegroup location
resources
| where location != "global"
| join (
resourcecontainers
| where ['type'] =~ 'microsoft.resources/subscriptions/resourcegroups'
| project resourceGroup, location,subscriptionId
) on resourceGroup, subscriptionId
| where location != location1
@Manbearpiet
Manbearpiet / README.md
Created August 28, 2023 14:47 — forked from MichaelCurrin/README.md
GitHub GraphQL - Get Pull Requests using GH's GraphQL API

Get Pull Requests using GH's GraphQL API

How to get Pull Requests data using Github in the browser, or using the API to allow for automating reporting or building in values into a website.

Resources

@Manbearpiet
Manbearpiet / Trace-AICommand.ps1
Created August 9, 2023 19:52 — forked from JustinGrote/Trace-AICommand.ps1
Report the results and performance of any scriptblock to Azure Application Insights
#requires -version 7
#You can load this script with $(iwr https://tinyurl.com/TraceAICommand | iex)
using namespace Microsoft.ApplicationInsights
using namespace Microsoft.ApplicationInsights.Extensibility
using namespace Microsoft.ApplicationInsights.DataContracts
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Net
#Reference: https://docs.microsoft.com/en-us/azure/azure-monitor/app/console
@Manbearpiet
Manbearpiet / expirycheck.ps1
Created October 7, 2021 20:30
Quick certificate expiry check
[CmdletBinding()]
param (
[Parameter()]
[Int32]
$DaysToExpiration
)
$certs = Get-AzWebAppCertificate
$certs | Where-Object ExpirationDate -LE (get-date).AddDays($DaysToExpiration) | Select-Object name,Issuer,SubjectName,Thumbprint,ExpirationDate