Skip to content

Instantly share code, notes, and snippets.

@mmckechney
mmckechney / kubectl_ubuntu_wsl.sh
Created May 27, 2022 17:18 — forked from cmendible/kubectl_ubuntu_wsl.sh
Install kubectl on ubuntu (WSL) and use kubectl config from Windows
#!/bin/bash
# Receives your Windows username as only parameter.
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
windowsUser=$1
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Help;
using System.CommandLine.NamingConventionBinder;
namespace SysCmdLine
{
class Program
{
public static void Main(string[] args)
@mmckechney
mmckechney / Get-AllVMPowerState.ps1
Created May 1, 2020 20:13
Display Power State for all VMs
$vmInfo = @()
class vmdata {
[string]$subscription
[string]$resourceGroupName
[string]$Name
[string]$Location
[string]$Size
[string]$OS
[string]$PowerState
@mmckechney
mmckechney / Readme.md
Last active April 10, 2020 12:26
Collect Storage Account Usage Metrics

Intro:

This PowerShell script will collect usage information on all of the storage accounts you have access to as well as getting their location and SKU. It will output in a table format

How to use

First, you will need to install the ARMClient.exe application. This is what makes the REST calls to the the metrics APIs.

@mmckechney
mmckechney / Manage-App-Service-Plan.md
Last active October 17, 2023 23:16
PowerShell and CLI to manage App Service Plan sizing

Manage App Service Plan count and SKU

Get the number of worker nodes serving the app service plan

(Get-AzAppServicePlan -ResourceGroupName "<resource group name>" -Name "<app service plan name>").Sku.Capacity
@mmckechney
mmckechney / TagManagerRole.json
Last active December 3, 2019 19:32
Tag Manager - Custom Azure RBAC role
{
"Name": "Tag Manager Role",
"Description": "Can only add/edit/delete resource tags",
"Id": null,
"IsCustom": true,
"Actions": [
"*/read",
"Microsoft.Resources/tags/write",
"Microsoft.Resources/tags/delete"
],
@mmckechney
mmckechney / ActivityLog_EventHubArchiving.ps1
Created September 25, 2019 11:33
Archive Azure Activity Logs for multiple subscriptions
<#
.SYNOPSIS
This script will configure EventHub logging for all Azure Activity logs in multiple subscriptions so that you can then archive the logs to another system
See: https://docs.microsoft.com/en-us/powershell/module/az.monitor/add-azlogprofile
.DESCRIPTION
Using an AAD account that has access to all of the subscriptions that you need to configure, this will loop through all of those
subscriptions, find all of the EventHub namespaces in those subscriptions and then find an EventHub that meets a specific naming format.
Once the proper EventHub is found, it will set the log profile for you
The naming format of the EventHub is up to you and can be edited on the "if($eventHub.Name ..." line #45
@mmckechney
mmckechney / ApplyNSGIfMIssing.json
Created June 20, 2019 19:34
Azure Policy to add a specified Network Security Group to a Subnet if none is specified at creation time
{
"properties": {
"displayName": "Append NSG if missing",
"description": "Sets default NSG if none is specified",
"policyType": "Custom",
"mode": "All",
"parameters": {
"nsgResourceId": {
"type": "String",
"metadata": {
@mmckechney
mmckechney / ManagedDiskCopy.ps1
Last active June 20, 2019 13:02
Copy a managed disk to another region
<#
.SYNOPSIS
Managed disks in Azure have no direct facilitites to access the underlying URL/path the disk resides in since
they are placed into storage accounts under the hood by Azure. Often times there's a desire to take a disk from a single
VM and move to another region where you can create a new VM and attach to the disk that's copied. This script
provides a means to do that and has been tested as working using the new AZ PowerShell cmdlets.
If this is run in a PowerShell context without the new AZ cmdlets installed; simply do a search and replace of Az to AzureRM.
Note: The SOURCE VM needs to be powered off to create the SAS URL and to ensure no writes are occuring to the disk during the copy.
.DESCRIPTION
This script will require you to populate the source resource group and source managed disk name as well as the destination resource group,
@mmckechney
mmckechney / Get-ApplicationGateway-Skus.ps1
Created June 12, 2019 14:27
Get Application Gateway Sku's for all gateways
$properties = @{Name = ""; ResourceGroupName =""; Location = ""; SkuName = ""; SkuTier = ""; Subscription = ""}
$gwTemplate = New-Object -TypeName PSObject -Property $properties
$qwCollection = @()
$subs = Get-AzSubscription
foreach($sub in $subs)
{
Select-AzSubscription -Subscription $sub.Name