Skip to content

Instantly share code, notes, and snippets.

View SQLtattoo's full-sized avatar

Vassilis Ioannidis - MTT [MSFT] SQLtattoo

View GitHub Profile
SQLtattoo / resolveDomain.ps1
Last active November 2, 2021 08:33
PowerShell loop for DNS name lookup until resolved.
while(1 -eq 1) {
#get the IP of the domain assigned, by using the Cloudflare DNS server or replace with any other
$ip = Resolve-DnsName -Name <domain_name_here e.g.> -Server -Type A -ErrorAction SilentlyContinue -ErrorVariable procErr
#if there was an error then print a warning message
Write-Warning "Not resolved!"
#if the IP is not null, means it was resolved successfully
SQLtattoo / ListRGVMsizes.ps1
Last active January 18, 2021 14:13
Retrieve a list of Azure VM and their VM Size in a specific Resource Group
function ListRGVMsizes($Rg, $VmSize)
if($Rg.Length -gt 0){
$VMs = Get-AzVM -ResourceGroupName $Rg
foreach($vm in $VMs){
if ($vm.HardwareProfile.VmSize -like "*"+$VmSize+"*"){
Write-host $vm.Name ": " $vm.HardwareProfile.VmSize
SQLtattoo / add-azure-load-balancer-rule.ps1
Last active June 26, 2020 06:26
Add a TCP rule to an existing Azure Load Balancer
#Make sure we are on the correct Azure Subscription
$lbName = "your-lb-name-here"
$rgName = "your-resource-group-name"
$probName = "the-lb-probe-name"
$bepName = "backend-pool" ### the backend pool that has the VMs
$port = 10000 ### the port to load balance on the backend pool servers
$ruleName = "rule-name" ###the name of the new rule
SQLtattoo / get-nics-nsg-asgs.ps1
Created June 12, 2020 10:09
Get a list of Network Interface Cards attached on NSGs and ASGs
Get-AzNetworkInterface | Select Name, ResourceGroupName,`
@{Name="NSG";Expression = {$_.NetworkSecurityGroup.Id.tostring().substring($_.NetworkSecurityGroup.Id.tostring().lastindexof('/')+1)}},`
# optional if you want to add the below line for exporting to file
# | Export-Csv "nsg and asg info.csv" -Delimiter ","
# !!! Make sure you don't delete unintentionally disks you might need
# Set deleteUnattachedDisks=1 if you want to delete unattached Managed Disks
# Set deleteUnattachedDisks=0 if you want to see the Id of the unattached Managed Disks
$managedDisks = Get-AzDisk
foreach ($md in $managedDisks) {
# ManagedBy property stores the Id of the VM to which Managed Disk is attached to
# If ManagedBy property is $null then it means that the Managed Disk is not attached to a VM
SQLtattoo / Disable-Multiple-WSvcs.ps1
Last active May 8, 2020 14:53
Disabling multiple Windows services
# this populates a variable with all Windows Services starting with 'Microsoft Dynamics'
$svcs = Get-Service | where DisplayName -Like "Microsoft Dynamics*"
foreach($svc in $svcs)
Write-Host "Disabling service $($svc.Name)"
Set-Service -ServiceName $svc.Name -StartupType Disabled
SQLtattoo / assign network security group to vms.ps1
Created May 6, 2020 09:17
Assign Network Security Group to Azure VMs
# The "nsg-nointernet" Network Security Group must exist
$VMs = Get-AzVM | where Name -Like "APPSRV-*"
foreach ($VM in $VMs) {
$nic = Get-AzNetworkInterface -ResourceId $
$Nsg = Get-AzNetworkSecurityGroup -Name "nsg-nointernet"
Write-Output "Adding NSG: $Nsg to $VM"
$nic.NetworkSecurityGroup = $Nsg
$nic | Set-AzNetworkInterface
SQLtattoo / assign application security group to vms.ps1
Last active June 15, 2020 12:07
Assign Application Security Group to Azure VMs
# The "asg-appservers" Application Security Group must exist
#Get all the VMs that their name start with APPSRV-
$VMs = Get-AzVM | where Name -Like "APPSRV-*"
foreach ($VM in $VMs) {
$nic = Get-AzNetworkInterface -ResourceId $
$Asg = Get-AzApplicationSecurityGroup -Name "asg-appservers"
Write-Host Adding ASG: $Asg.Name to $VM.Name
$nic.IpConfigurations[0].ApplicationSecurityGroups = $Asg
SQLtattoo / Start-Stop-Restart-NAV-NST-instances.ps1
Last active May 5, 2020 14:39
Manage NAV Application Server instances service state
function StartStopNSTs($action)
Import-Module "${env:ProgramFiles(x86)}\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1" -WarningAction SilentlyContinue | out-null
Import-Module "$env:ProgramFiles\Microsoft Dynamics NAV\100\Service\NavAdminTool.ps1" -WarningAction SilentlyContinue | Out-Null
Import-Module "${env:ProgramFiles(x86)}\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Apps.Tools.psd1" -WarningAction SilentlyContinue | Out-Null
$NSTs = Get-NAVServerInstance | Where-Object -Property 'State' -eq 'Running'
SQLtattoo / get-NIC-private-ips.ps1
Created April 30, 2020 06:59
Get the private IPs of all network interfaces in an Azure resource group
Get-AzNetworkInterface -ResourceGroupName your-resoure-group-name-here `
| ForEach { `
$Interface = $_.Name; $IPs = $_ `
| Get-AzNetworkInterfaceIpConfig `
| Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress `