Skip to content

Instantly share code, notes, and snippets.

@srpomeroy
srpomeroy / azure_ea-ri_utilization.ps1
Created October 3, 2020 00:12
Microsoft Azure EA Legacy API - Reserved Instance Utilization Example
# Source: https://docs.microsoft.com/en-us/rest/api/billing/enterprise/billing-enterprise-api-reserved-instance-usage
$enrollmentId = ""
$apiToken = ""
$startDate = "" ## yyyy-mm-dd | Example: 2020-10-01
$endDate = "" ## yyyy-mm-dd | Example: 2020-10-01
$uri = "https://consumption.azure.com/v2/enrollments/${enrollmentId}/reservationdetails?startDate=${startDate}&endDate=${endDate}"
Invoke-RestMethod -Method Get -UseBasicParsing -Uri $uri -Headers @{"Authorization"="bearer ${apiToken}"}
@srpomeroy
srpomeroy / Manage Windows Firewall
Created May 7, 2019 19:49 — forked from pavank/Manage Windows Firewall
Manage Windows Advanced Firewall with PowerShell
Set-StrictMode -Version Latest
# Constants
if (!(Test-Path variable:\NET_FW_DISABLED)) { Set-Variable NET_FW_DISABLED -Option Constant $False }
if (!(Test-Path variable:\NET_FW_ENABLED)) { Set-Variable NET_FW_ENABLED -Option Constant $True }
if (!(Test-Path variable:\NET_FW_IP_PROTOCOL_TCP)) { Set-Variable NET_FW_IP_PROTOCOL_TCP -Option Constant 6 }
if (!(Test-Path variable:\NET_FW_IP_PROTOCOL_UDP)) { Set-Variable NET_FW_IP_PROTOCOL_UDP -Option Constant 17 }
if (!(Test-Path variable:\NET_FW_PROFILE_DOMAIN)) { Set-Variable NET_FW_PROFILE_DOMAIN -Option Constant 0x1 }
if (!(Test-Path variable:\NET_FW_PROFILE_PRIVATE)) { Set-Variable NET_FW_PROFILE_PRIVATE -Option Constant 0x2 }
if (!(Test-Path variable:\NET_FW_PROFILE_PUBLIC)) { Set-Variable NET_FW_PROFILE_PUBLIC -Option Constant 0x2 }
@srpomeroy
srpomeroy / Add-AzureRMResourceGroupNameTag.ps1
Created November 26, 2018 21:33
Example snippet that tags all AzureRM resources with the name of the resource group they are in.
$tagKey = "resourcegroup"
$resources = Get-AzureRmResource
foreach ($r in $resources)
{
$resourceGroupName = $r.ResourceGroupName
$resourceTags = $r.tags
if ($resourceTags) {
if($resourceTags.Keys -contains $tagKey) {
if($resourceTags[$tagKey] -ne $resourceGroupName) {
@srpomeroy
srpomeroy / Update-RigthScaleMCISettings.ps1
Created November 8, 2018 21:01
PowerShell script that maintains a RightScale MCI based on parameter inputs.
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
$rsRefreshToken,
[Parameter(Mandatory=$true)]
$rsAccount,
[Parameter(Mandatory=$true)]
$rsEndpoint,
[Parameter(Mandatory=$true)]
$rsMCIName,
@srpomeroy
srpomeroy / RightScale - Create MCI.sh
Created September 26, 2018 18:47
RightScale: Shell commands that use RSC to create an MCI, tag it, and add an image
# Create the MCI and capture the HREF via '--xh=location' flag
mciHref=$(rsc --account=XXXX --refreshToken=XXXX --host=us-X.rightscale.com --xh=Location cm15 create /api/multi_cloud_images \
"multi_cloud_image[description]=RHEL 7.5 GA" \
"multi_cloud_image[name]=RS Example RHEL MCI")
# Tag the MCI
rsc --account=XXXX --refreshToken=XXXX --host=us-X.rightscale.com cm15 multi_add /api/tags/multi_add \
"resource_hrefs[]=$mciHref" \
"tags[]=rs_agent:mime_include_url=https://rightlink.rightscale.com/rll/10.6.0/rightlink.boot.sh" \
"tags[]=rs_agent:type=right_link_lite"
@srpomeroy
srpomeroy / common_functions.rb
Created July 6, 2018 03:23
Commonly used functions in RightScale CATs
# Required prolog
name 'LIB - Common functions'
rs_ca_ver 20160622
short_description "Common functions"
package "common/functions"
# Checks if the account supports the selected cloud
define checkCloudSupport($cloud_name, $param_location) do
# Gather up the list of clouds supported in this account.
@srpomeroy
srpomeroy / Backup-RightScaleAssets.ps1
Created July 5, 2018 17:37
Utilizes RSC and RIGHTST to download RightScripts and ServerTemplates from a RightScale Account
# Requires
# rsc - https://github.com/rightscale/rsc
# rightst - https://github.com/rightscale/right_st
# assumes they are stored in c:\rightscale\rsc\ and c:\rightscale\rightst\
# Variables
$basepath = "$env:SystemDrive\rightscale"
$outputpath = "path-to-backup-location"
$rightstaccount = "Account Name"
$account = "12345" #Account Number
@srpomeroy
srpomeroy / RightScale-Get_Account_Audit_Entries.ps1
Created April 3, 2018 15:11
Get RightScale account audit entries for the past hour
# Gets Audit Entries from a RightScale account for the past hour.
# Relies on Instance Auth for API access
# Currently just adds all audits to an object to allow for manipulation or forwarding
$tz = "-0000"
$now = Get-Date
$endDate = Get-Date $now -Format "yyyy/MM/dd HH:mm:ss"
$startDate = Get-Date (Get-Date $now).AddHours(-1) -Format "yyyy/MM/dd HH:mm:ss"
# Audit Entries - Index: http://reference.rightscale.com/api1.5/resources/ResourceAuditEntries.html#index
@srpomeroy
srpomeroy / RightScale - List Child Accounts
Last active September 12, 2018 20:24
Return list of accounts and their shards
# RightScale API Client(rsc): https://github.com/rightscale/rsc
# PowerShell: https://github.com/PowerShell/PowerShell
# jq: https://stedolan.github.io/jq/
# Output All Child Account Names, Numbers, and Shards
# PowerShell
# Requires: RSC and PowerShell
#
# Input:
@srpomeroy
srpomeroy / Get-MSNESeasonData.ps1
Last active February 7, 2018 05:50
PowerShell script to parse MSNE event data
# Based on 2017 results: http://www.motorsportsne.com/
$urls = 'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2003%2026%20a-x_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2004%2002%20a-x_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2004%2030%20a-x%20removed%20a1%20a4%20no%20work_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2006%2004%20a-x_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2007%2028%20a-x_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2008%2006%20A-X_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2008%2018%20a-x_fin.htm',
'https://axwaresystems.com/axorm/files/MotorSportsNE/2017%2008%2020%20a-x_fin.htm',