Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
MatthewJDavis / main.tf
Last active July 8, 2021 18:20
Main terraform file to create service account
terraform {
required_providers {
okta = {
source = "okta/okta"
version = "~> 3.10"
}
}
}
# Configure the Okta Provider - API token set in env var.
@MatthewJDavis
MatthewJDavis / variables.tf
Created January 27, 2021 22:39
Terraform variables file for Okta
variable "org_name" {
default = "dev-123456"
}
variable "base_url" {
default = "okta.com"
}
variable "password" {
sensitive = true
@MatthewJDavis
MatthewJDavis / New-PSTimerAction.ps1
Last active January 23, 2021 15:07
Timed action with PowerShell
# Run a PowerShell command on a specific interval.
$Timer = [System.Timers.Timer]::new(3000)
Register-ObjectEvent -InputObject $Timer -EventName Elapsed -Action { Get-Item }
$Timer.Start()
<#
.DESCRIPTION
Get last login of Guest user in Azure AD
Adapted from https://cloudtech.nu/2020/05/03/export-azure-ad-last-logon-with-powershell-graph-api/#comments
.NOTES
Requries an Azure App registered with Add AuditLog.Read.All, Directory.Read.All, User.Read.All permissions.
Set clientID, tenantName, clientSecret in $env: vars.
#>
$clientID = $env:clientID
@MatthewJDavis
MatthewJDavis / Kill stuck ssh session
Created June 27, 2020 00:57
Escape sequence to get out of a terminal that is stuck after ssh has dropped.
enter ~ .
@MatthewJDavis
MatthewJDavis / nsg.yml
Created June 7, 2020 16:53
Azure nsg with public ip address of network
---
- name: Create security group that allows SSH
azure_rm_securitygroup:
resource_group: "{{ rg_name }}"
name: "{{ nsg_name }}"
rules:
- name: SSH
protocol: Tcp
destination_port_range: 22
access: Allow
@MatthewJDavis
MatthewJDavis / ip.yml
Created June 7, 2020 16:51
Get network public ip address
---
- hosts: localhost
gather_facts: false
tasks:
- name: Get the public IP address of the network.
uri:
url: https://api.ipify.org?format=json
method: Get
changed_when: false
register: public_ip
@MatthewJDavis
MatthewJDavis / ps-base64.ps1
Last active May 20, 2020 00:13
Convert a string to base64 with PowerShell
# Converts the string 'my-app' to base64
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('my-app'))
# Converts the string assigned to the variable 'theString' and assigns the base64 string to the variable 'convertedString'
$theString = 'hello'
$convertedString = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($theString))
#region Beginner
<#
The challenge is simple: get the sum of the even numbers between 1 and 100.
You should be able to do this in at least 3 different ways. Show all 3 ways. You don’t need to write any functions or scripts.
#>
# Method 1, foreach loop
$sum = 0
foreach ($n in 1..100) {
@MatthewJDavis
MatthewJDavis / dashboard.ps1
Last active May 10, 2020 19:17
Universal Dashboard For Azure DevOps build display
function Test-ForAccessToken {
if ($null -eq $env:PAT) {
throw 'No Personal Access Token environment variable set. Set with $env:pat = Read-Host'
}
}
function Start-BuildDashboard {
[CmdletBinding()]
param (
[Parameter()]