Skip to content

Instantly share code, notes, and snippets.

param (
[Parameter(Mandatory = $true)]
[string]$sourceAadGroupName,
[Parameter(Mandatory = $true)]
[string]$destinationAdGRoupName,
[Parameter(Mandatory = $false)]
[bool]$RemoveUnmatched = $true
)
#region Azure Automations connect as RunAs
$policyName = "DDoS"
$roleToNotify = "Owner"
$policy = Get-AzPolicyDefinition | Where-Object { $_.Properties.displayname -eq $policyName }
$nonCompliantNetworks = Get-AzPolicyState | Where-Object { $_.ComplianceState -eq "NonCompliant" -and $_.PolicyDefinitionName -eq $policy.Name } | Group-Object SubscriptionId
foreach($group in $nonCompliantNetworks) {
$subscriptionId = $group.Name
$networks = $group.Group
{
"properties": {
"displayName": "Enabled DDoS protection",
"policyType": "Custom",
"mode": "All",
"metadata": {
"category": "Network"
},
"parameters": {},
"policyRule": {
function Get-RrasRoutes {
$config = netsh routing dump
$config | ? { $_.StartsWith("add persistentroute") } | ForEach-Object {
$line = $config | ? { $_.StartsWith("add persistentroute") } | Select -First 1
$line = $_
$fields = $line -split " "
$route = @{}
foreach($item in $fields) {
#$item = $fields | Select -First 1 -Skip 2
$f = $item -split "="
$ps1Content = @'
$vpnProfiles = "Litware VPN Auto"
function Set-VpnStrategy {
[cmdletbinding()]
param(
[Parameter(Mandatory = $true, ParameterSetName = "Connection", ValueFromPipeline = $true)]
$VpnConnection,
[Parameter(Mandatory = $true, ParameterSetName = "Name")]
[string]$ProfileName,
@machv
machv / Sync-RouteTableDns.ps1
Created September 3, 2020 17:30
Azure Automation to Sync DNS resolution to Route Table
Param(
[Parameter (Mandatory = $true)]
[sring]$DnsName,
[string]$RouteName
)
if($RouteName -eq "") {
$RouteName = $DnsName
}
@machv
machv / sync.ps1
Created September 1, 2020 15:09
Synchronize Routing Table with Azure Service Tag Listing
#region Azure Automation bootstrap
try
{
$servicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
"Logging in to Azure..."
Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
@machv
machv / example.gif
Last active August 24, 2020 15:27
Remove App permission to Azure AD Enterprise Application
example.gif
@machv
machv / temp.ps1
Last active August 6, 2020 09:18
temp
#region Functions
function ConvertFrom-Timestamp {
param(
[Parameter(Mandatory = $true)]
[int]$Timestamp
)
$utc = (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($Timestamp))
$datetime = [datetime]::SpecifyKind($utc, 'Utc').ToLocalTime()
@machv
machv / README.md
Last active July 31, 2020 13:35
Synchronize Private DNS Zones in Azure between each other

Synchronize Azure Private DNS Zone records

Prerequisities

Make sure that in addition to Az PowerShell module you also have Az.PrivateDns module installed.

About

Function Sync-DnsZone synchronizes resource records from source DNS zone to destination DNS zone, if you want to achive two-way sync you need to execute the same function twice with switched source and destination.

Customization