Skip to content

Instantly share code, notes, and snippets.

View JeffBrownTech's full-sized avatar

Jeff Brown JeffBrownTech

View GitHub Profile
@JeffBrownTech
JeffBrownTech / azure-pipeline.yaml
Last active April 20, 2024 16:13
Example Azure DevOps Multi-Stage Pipeline utilizing OIDC with Terraform Deployment
# Separates each Terraform action into separate steps in the pipeline.
# Authorization token is exported in the first steps after logging into Azure using Az CLI.
# Script then exports information into environment variables.
trigger:
- main
pool:
vmImage: ubuntu-latest
@JeffBrownTech
JeffBrownTech / Set-TerraformAzureRmOIDCVariables.ps1
Created April 20, 2024 15:54
PowerShell script for verifying and setting pipeline variables for Terraform OIDC authentication
#!/usr/bin/env pwsh
#Requires -Version 7.2
if ($env:SYSTEM_DEBUG -eq "true") {
$InformationPreference = "Continue"
$VerbosePreference = "Continue"
$DebugPreference = "Continue"
Get-ChildItem -Path Env: -Force -Recurse -Include * | Sort-Object -Property Name | Format-Table -AutoSize | Out-String
}
@JeffBrownTech
JeffBrownTech / azure-pipeline.yaml
Created April 18, 2024 12:31
Azure DevOps Pipeline: Use TerraformTask with Workload Identity federation / OIDC
trigger:
- main
pool:
vmImage: ubuntu-latest
variables:
- name: workingDirectory
value: '<folder containing terraform code>'
@JeffBrownTech
JeffBrownTech / main.tf
Last active April 16, 2024 12:56
Terraform Configuration for OIDC Example
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.7"
}
azuredevops = {
source = "microsoft/azuredevops"
version = ">= 1.0"
@JeffBrownTech
JeffBrownTech / GraphAPIManagedIdentity.ps1
Created January 1, 2024 16:49
Use PowerShell to with Graph API
# Build information for access token
# Reference: https://learn.microsoft.com/graph/auth-v2-service#token-request
$credential = Get-Credential
$tenantId = "<tenant guid>"
$oauthUri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
$tokenRequestBody = @{
client_id = $credential.UserName
client_secret = $credential.GetNetworkCredential().Password
@JeffBrownTech
JeffBrownTech / EnforceDoNotDeleteLock.json
Created November 10, 2021 03:39
Deploy CanNotDelete Resource Lock on Resource Groups
{
"properties": {
"displayName": "Deploy CanNotDelete Resource Lock on Resource Groups",
"description": "Creates a resource lock at the resource group level for preventing resource deletion.",
"mode": "all",
"metadata": {
"version": "1.0.0",
"category": "General"
},
"parameters": {},
@JeffBrownTech
JeffBrownTech / linux-vm-multiple-data-disks.json
Created May 17, 2021 20:39
ARM Template - Use Copy Loop to Deploy Multiple Data Disks on a Virtual Machine
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dataDiskCount": {
"type": "int",
"metadata": {
"description": "Number of data disks to add to the VM."
}
}
@JeffBrownTech
JeffBrownTech / vnet-and-snet.psarm.ps1
Last active April 25, 2021 17:30
PSArm Vnet and Snet Example
# Define variables for the virtual network and subnet properties
$location = "westus2"
$name = 'prod'
$vnetName = "vnet-$name-$location-001"
$vnetPrefix = '10.20.0.0/16'
# Include as many subnets as you want to create as hashtables in the array
$subnets = @(
[PsCustomObject]@{Name = 'mgmt'; Prefix = '10.20.2.0/24'},
[PsCustomObject]@{Name = 'web'; Prefix = '10.20.4.0/24'},
@JeffBrownTech
JeffBrownTech / PowerShellDynamicBlock.ps1
Last active February 9, 2021 03:51
PowerShell Dynamic Block Example
DynamicParam {
if ($ChannelType -eq 'Private') {
# Define parameter attributes
$paramAttributes = New-Object -Type System.Management.Automation.ParameterAttribute
$paramAttributes.Mandatory = $true
# Create collection of the attributes
$paramAttributesCollect = New-Object -Type `
System.Collections.ObjectModel.Collection[System.Attribute]
$paramAttributesCollect.Add($paramAttributes)
@JeffBrownTech
JeffBrownTech / Get-TeamsVoiceUserInfo.ps1
Last active October 2, 2023 14:55
Get Teams Voice User Information
$userPhoneNumbers = Get-CsPhoneNumberAssignment -CapabilitiesContain UserAssignment -Top ([int]::MaxValue)
foreach ($number in $userPhoneNumbers) {
if ($null -ne $number.AssignedPstnTargetId) {
$user = Get-CsOnlineUser -Identity $number.AssignedPstnTargetId
}
else {
$user = [PSCustomObject]@{
DisplayName = "Not Assigned"
UserPrincipalName = $null