Skip to content

Instantly share code, notes, and snippets.

View paratz's full-sized avatar
🐶

Pablo Ratz paratz

🐶
View GitHub Profile
@paratz
paratz / Get-FolderReport
Created July 24, 2024 14:41
Powershell Script to export Folder Size and Number of Files within a Folder
param (
[string]$ParentFolder
)
# Get the list of child folders
$folders = Get-ChildItem -Path $ParentFolder -Directory
# Create a custom object to store the results
$results = @()
foreach ($folder in $folders) {
@paratz
paratz / gist:c42bc2b6e5fbd59f5452cf3c8de4872a
Created June 11, 2024 15:26
kql List all Resources with its tag values
//https://www.blueboxes.co.uk/working-with-tags-in-azure-resource-graph-explorer
ResourceContainers
| where type =~ 'microsoft.resources/subscriptions/resourcegroups'
| mvexpand tags
| extend tagKey = tostring(bag_keys(tags)[0])
| extend tagValue = tostring(tags[tagKey])
| project name, tags, tagKey, tagValue
@paratz
paratz / Get-ARSLearnedRoutes.ps1
Created January 10, 2024 12:12
Obtain learned routes from peer in Azure Route Server
$SubscriptionName = "subName"
$resourceGroupName = "rgName"
$routeServerName = "ARSName"
$peerName = "peerName"
Select-AzSubscription -SubscriptionName $SubscriptionName
$routerServerPeer = Get-AzRouteServerPeer -ResourceGroupName $resourceGroupName -RouteServerName $routeServerName -PeerName $peerName
Get-AzRouteServerPeerLearnedRoute -InputObject $routerServerPeer
#Get-AzRouteServerPeerLearnedRoute -ResourceGroupName $resourceGroupName -RouteServerName $routeServerName -PeerName $peerName
@paratz
paratz / AzFWDiagQueries.kql
Created March 24, 2023 13:29
Azure Firewall Diagnostics KQL
//Por ejemplo, para ver el tráfico de navegación de una IP en particular:
AzureDiagnostics
| where Category == "AzureFirewallApplicationRule"
| parse msg_s with Protocol " request from " SourceIP ":" SourcePortInt:int " " TempDetails
| parse TempDetails with "was " Action1 ". Reason: " Rule1
| parse TempDetails with "to " FQDN ":" TargetPortInt:int ". Action: " Action2 "." *
| parse TempDetails with * ". Rule Collection: " RuleCollection2a ". Rule:" Rule2a
| parse TempDetails with * "Deny." RuleCollection2b ". Proceeding with" Rule2b
| extend SourcePort = tostring(SourcePortInt)
| extend TargetPort = tostring(TargetPortInt)
@paratz
paratz / Export-AzBlobProperties.ps1
Last active February 21, 2024 16:44
PowerShell script that exports the list of blobs in all containers in an Azure storage account with its name, modified date, size, and container name to a CSV file
# Set the storage account context
$storageAccount = Get-AzStorageAccount -ResourceGroupName <resource-group-name> -Name <storage-account-name>
$ctx = $storageAccount.Context
# Get the list of containers
$containers = Get-AzStorageContainer -Context $ctx
# Create an empty array to store the list of blobs
$blobs = @()
@paratz
paratz / FindMissingHybridBenefit.ps1
Created November 10, 2022 23:43
FindMissingHybridBenefit.ps1
#region Runbook_Variables
$ErrorActionPreference = "Continue"
$filename = "AHUB.csv"
#endregion Runbook_Variables
#region Runbook_Collection_Logic
@paratz
paratz / StartStopVM-AAOrder
Created October 19, 2022 13:49
Powershell Automation Runbook to start/shutdown based on schedule and order
workflow ShutDownStartByTag
{
Param(
[Parameter(Mandatory=$true)]
[String]
$TagName,
[Parameter(Mandatory=$true)]
[String]
$TagValue,
[Parameter(Mandatory=$true)]
// VMs with the most on-prem traffic in the last hour (flows)
AzureNetworkAnalytics_CL
| where SubType_s == "FlowLog" and FlowType_s == "S2S"
| mvexpand vm = pack_array(VM1_s, VM2_s) to typeof(string)
| where isnotempty(vm)
| extend traffic = AllowedInFlows_d + DeniedInFlows_d + AllowedOutFlows_d + DeniedOutFlows_d // For bytes use: | extend traffic = InboundBytes_d + OutboundBytes_d
| make-series TotalTraffic = sum(traffic) default = 0 on FlowStartTime_t from ago(1h) to now() step 1m by vm
| render timechart
// VMs with the most on-prem traffic in the last hour (bytes)
## this script should be executed in poweershell, but previously you have to logon to az cli
# az login
$AllSubs = az account list | convertfrom-json | select-object Name, Id
$ObjectsOutput = @()
foreach ($sub in $AllSubs){
#Cambio de Suscripción
az account set --subscription $sub.Id
@paratz
paratz / rubook2.py
Created April 7, 2022 19:44
Python3 runbook to list subscription using azure.cli.core and managed identities (it doesn't work)
#!/usr/bin/env python3
import sys
import os
from azure.cli.core import get_default_cli
def main():
commnd = f'login --identity'
exAzCli(commnd, False) #login to azure cli using service principal credentials
subs = exAzCli('account list --all', False) #executing cli command