Skip to content

Instantly share code, notes, and snippets.

View techdecline's full-sized avatar

Cornelius Schuchardt techdecline

View GitHub Profile
@techdecline
techdecline / Get-AzPimAssignments.ps1
Last active January 10, 2024 14:19
Manage Azure Privileged Identity Management using Powershell and Azure Resource Manager. Docs available at https://techdecline.bearblog.dev/remove-azure-privileged-identity-management-assignments-using-powershell-and-azure-resource-manager/
function Get-AzPimAssignment {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string]$Scope
)
# Checking Azure Context
try {
$ctx = Get-AzContext
@techdecline
techdecline / Sync-KeyVaultSecret.ps1
Last active December 11, 2023 13:54
Sync-KeyVaultSecret.ps1
param(
$FilterString,
$SourceSubscriptionId,
$SourceVaultName,
$DestinationVaultName,
$DestinationSubscriptionId
)
# Change Context to source Subscription
Set-AzContext -Subscription $SourceSubscriptionId
@techdecline
techdecline / Import-AzJsonSecrets.ps1
Created October 13, 2023 08:41
Create/Update Azure Key Vault Secrets from JSON File using regex, whatif
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Mandatory=$false)]
[String]
$KeyVaultName = "kv-share-pw-gwc-c-0",
[Parameter(Mandatory=$false)]
[String]
$ResourceGroupName = "rg-share-pw-gwc-c-0",
@techdecline
techdecline / Get-AzTopMonitors.ps1
Last active September 4, 2023 08:57
Get Most-Triggered Azure Monitor Alerts for a subscription
function Get-AzTopMonitors {
<#
.Description
This function returns the top-most triggered Azure Monitor Alerts for a given Subscription. Requires existing Azure PowerShell Sign-In.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$SubscriptionId,
# Download Oh my posh
sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
sudo chmod +x /usr/local/bin/oh-my-posh
# Download themes
mkdir ~/.poshthemes
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
chmod u+rw ~/.poshthemes/*.omp.*
rm ~/.poshthemes/themes.zip
@techdecline
techdecline / Get-GitLabVariables
Last active November 29, 2022 08:34
Extract GitLab Variables from Projects and Groups to declare Environment Variables in Bash and PowerShell
[cmdletbinding()]
param (
[String]$GitLabUrl,
[String]$GitLabAccessToken,
[String]$GroupId,
[String]$ProjectId,
[switch]$Pwsh
)
@techdecline
techdecline / Get-GitlabInternalTFDependencies.ps1
Last active September 9, 2022 10:25
Get all internal Terraform dependencies from GitLab Projects
$env:GITLAB_URL = "<git address>"
$env:GITLAB_ACCESS_TOKEN = "<Gitlab PAT>"
$GLOBAL:filterStr = "(\.tf|\.hcl|\.gitlab-ci\.yml)$"
$GLOBAL:GroupId = "<root group id>"
$GLOBAL:refArr = [System.Collections.ArrayList]@()
function GetGitLinks {
param (
$ProjectId
)
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string[]]$ManagementGroupName = @("mg-prd-core", "mg-prd-lz"),
[Parameter(Mandatory = $false)]
[switch]$OutputMarkdown
)
function GetNonCompliantResource {
param (
[String]$TenantId = "ed2da482-854d-467a-a6c5-a56a9c91be6d"
)
$clusterArr = Get-AzSubscription -TenantId $TenantId | ForEach-Object { $null = Set-AzContext -Subscription $_.SubscriptionId -Tenant $TenantId ; Get-AzAksCluster }
$resultArr = [System.Collections.ArrayList]@()
function GetNodePoolMaxIp {
param (
[Microsoft.Azure.Commands.Aks.Models.PSContainerServiceAgentPoolProfile]$AgentPoolProfile
@techdecline
techdecline / New-GcmPlaintextConfig.ps1
Last active June 27, 2022 06:48
Create Git Credential Manager Plaintext Credential File (for Azure Devops)
param (
[String]$OrganizationName = $($Env:SYSTEM_COLLECTIONURI -replace ".$") ,
[String]$UserName = "serviceuser@organization.com", # this is just a dummy value
[String]$PAT = $Env:SYSTEM_ACCESSTOKEN,
[String]$StorePath = $PWD
)
# git config
. git config --global credential.interactive false
. git config --global credential.credentialStore plaintext