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
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. www.github.com> -Server 1.1.1.1 -Type A -ErrorAction SilentlyContinue -ErrorVariable procErr | |
#if there was an error then print a warning message | |
if($procErr){ | |
Write-Warning "Not resolved!" | |
} | |
#if the IP is not null, means it was resolved successfully |
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 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 | |
} |
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
#Make sure we are on the correct Azure Subscription | |
Get-AzContext | |
$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 |
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
Get-AzNetworkInterface | Select Name, ResourceGroupName,` | |
@{Name="NSG";Expression = {$_.NetworkSecurityGroup.Id.tostring().substring($_.NetworkSecurityGroup.Id.tostring().lastindexof('/')+1)}},` | |
@{Name="ASG";Expression={$_.IpConfigurations.ApplicationSecurityGroups.Id.tostring().substring($_.IpConfigurations.ApplicationSecurityGroups.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 "," |
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
# !!! 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 | |
$deleteUnattachedDisks=0 | |
$managedDisks = Get-AzDisk | |
$k=0 | |
$l=0 | |
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 |
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 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 | |
} |
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
# The "nsg-nointernet" Network Security Group must exist | |
$VMs = Get-AzVM | where Name -Like "APPSRV-*" | |
foreach ($VM in $VMs) { | |
$nic = Get-AzNetworkInterface -ResourceId $VM.NetworkProfile.NetworkInterfaces.id | |
$Nsg = Get-AzNetworkSecurityGroup -Name "nsg-nointernet" | |
Write-Output "Adding NSG: $Nsg to $VM" | |
$nic.NetworkSecurityGroup = $Nsg | |
$nic | Set-AzNetworkInterface |
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
# 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 $VM.NetworkProfile.NetworkInterfaces.id | |
$Asg = Get-AzApplicationSecurityGroup -Name "asg-appservers" | |
Write-Host Adding ASG: $Asg.Name to $VM.Name | |
$nic.IpConfigurations[0].ApplicationSecurityGroups = $Asg |
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
Get-AzNetworkInterface -ResourceGroupName your-resoure-group-name-here ` | |
| ForEach { ` | |
$Interface = $_.Name; $IPs = $_ ` | |
| Get-AzNetworkInterfaceIpConfig ` | |
| Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress ` | |
} |
NewerOlder