This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Replace with your Gist's raw URL | |
$gistUrl = "https://gist.githubusercontent.com/yourusername/raw/yourgistID/yourscript.ps1" | |
#Option 1 | |
Invoke-RestMethod -Uri $gistUrl | Invoke-Expression | |
#Option 2 | |
Invoke-Expression ((New-Object System.net.WebClient).DownloadString('$gistUrl')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SubscriptionName = "" | |
$RGName = "" | |
$NSGName = "" | |
$RuleName = "" | |
# Ensure Azure modules are installed | |
if (-not (Get-Module -ListAvailable -Name Az.Network)) { | |
Install-Module -Name Az.Network -AllowClobber -Scope CurrentUser | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SubscriptionId = "" | |
$RGName = "" | |
$NSGName = "" | |
$RuleName = "" | |
# Ensure Azure modules are installed | |
if (-not (Get-Module -ListAvailable -Name Az.Network)) { | |
Install-Module -Name Az.Network -AllowClobber -Scope CurrentUser | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Manage-AzureRoleAssignment { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true)] | |
[ValidateSet('Get', 'Set')] | |
[string]$Action, | |
[string]$Scope, | |
[string]$Role, | |
[string]$UserOrServicePrincipal, | |
[ValidateSet('User', 'ServicePrincipal')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
This script will collect all policy assignments in available subscriptions and list them as a table. | |
#> | |
# Log in to your Azure account | |
#Connect-AzAccount | |
function Get-ScopeName($scopeId) { | |
if ($scopeId -match "/providers/Microsoft.Management/managementGroups/") { | |
$mgId = $scopeId -replace "/providers/Microsoft.Management/managementGroups/", "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ResourceGroupCost { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true)] | |
[string]$ResourceGroupName, | |
[Parameter(Mandatory = $false)] | |
[int]$DaysBack = 30 | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To simplify this example, we can define hashtable with naming standard: | |
$ResourceNamesHash = @{} | |
$ResourceNamesHash.Add("Microsoft.Compute/virtualMachines", "VM-`$Subscription-`$Description") | |
$ResourceNamesHash.Add("Microsoft.KeyVault/vault", "kv-`$Environment-`$Description") | |
$ResourceNamesHash.Add("Microsoft.Network/vpnGateways", "vpng-`$VNetName-`$Description") | |
# Define a function to get the abbreviation for a given resource type | |
function Get-ResourceNamingConvention { | |
param( | |
[Parameter(Mandatory=$true)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ExistingResourceTypeAndAbbreviation { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$ResourceName | |
) | |
# Check if the resource exists | |
$resource = Get-AzResource -Name $ResourceName -ErrorAction SilentlyContinue | |
if (!$resource) { | |
Write-Error "Resource '$ResourceName' not found." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ResourceTypeAbbreviation { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$ResourceType | |
) | |
if ($tableData.Resource -contains $ResourceType) { | |
$Answer = $tableData | Where-Object Resource -like $ResourceType | Select-Object -ExpandProperty Abbreviation | |
Write-Host "Correct abbreviation for $ResourceType is: $Answer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify the URL of the website and the ID of the table we want to scrape | |
$url = "https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations" | |
# Use Invoke-WebRequest with -UseBasicParsing to download the webpage and extract the HTML code | |
$html = Invoke-WebRequest -Uri $url -UseBasicParsing | Select-Object -ExpandProperty Content | |
#If everything else fails user regex! | |
#Use regular expressions to extract the table data from the HTML code | |
$tableRegex = '<table>.*?<tbody>(.*?)</tbody>.*?</table>' | |
$rowRegex = '<tr>.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?</tr>' |
NewerOlder