Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogspot.com to GITHUB.
From now onward all the contents will be shared in the GITHUB only.
Github links:
VMware scripts
PowerShell scripts
Azure-ARM-scripts
Welcome to tech-jockey IT Forum.
Welcome to tech-jockey!
This blog is designed to built tech solutions with collaboration of members who believe in sharing.
Guests inputs are most welcome.
Comment, like and share.
You can also help tech-jockey to grow
Please Click here to help.
Team Tech-Jockey !!
Sunday, August 6, 2023
Wednesday, April 24, 2019
Azure List of vNets, Address space and subnets under each vNet
#Author : Neeraj Kumar Jha
#SCRIPT_START
clear
$rsname = Get-AzureRmResourceGroup | select ResourceGroupName
foreach($rsitem in $rsname)
{
$rs_name=Get-AzureRmResourceGroup -Name $rsitem.ResourceGroupName | Get-AzureRmVirtualNetwork -WarningAction Ignore | select name -WarningAction Ignore
foreach($IN_RS_item in $rs_name)
{
$vnets = Get-AzureRmVirtualNetwork -Name $IN_RS_item.name -ResourceGroupName $rsitem.ResourceGroupName -WarningAction Ignore
foreach($vnet in $vnets)
{
$add_count= $vnet.AddressSpace.AddressPrefixes.count
if($add_count -gt 0)
{
$addr_list=$vnet.AddressSpace.AddressPrefixes
$addrcnt=0
echo "........................................................................................."
write-host "Resource group name: " $rsitem.ResourceGroupName " vNet Name: " $vnet.name
foreach($add_pref in $addr_list)
{
#echo $add_pref
write-host " Address range: "$vnet.AddressSpace.AddressPrefixes.Item($addrcnt)
$addrcnt=$addrcnt+1
}
}
else
{
echo ""
write-host "Resource group name: " $rsitem.ResourceGroupName " vNet Name: " $vnet.name
write-host " Address range: "$vnet.AddressSpace.AddressPrefixes.Item($addrcnt)
}
}
}
}
#SCRIPT_START
clear
$rsname = Get-AzureRmResourceGroup | select ResourceGroupName
foreach($rsitem in $rsname)
{
$rs_name=Get-AzureRmResourceGroup -Name $rsitem.ResourceGroupName | Get-AzureRmVirtualNetwork -WarningAction Ignore | select name -WarningAction Ignore
foreach($IN_RS_item in $rs_name)
{
$vnets = Get-AzureRmVirtualNetwork -Name $IN_RS_item.name -ResourceGroupName $rsitem.ResourceGroupName -WarningAction Ignore
foreach($vnet in $vnets)
{
$add_count= $vnet.AddressSpace.AddressPrefixes.count
if($add_count -gt 0)
{
$addr_list=$vnet.AddressSpace.AddressPrefixes
$addrcnt=0
echo "........................................................................................."
write-host "Resource group name: " $rsitem.ResourceGroupName " vNet Name: " $vnet.name
foreach($add_pref in $addr_list)
{
#echo $add_pref
write-host " Address range: "$vnet.AddressSpace.AddressPrefixes.Item($addrcnt)
$addrcnt=$addrcnt+1
}
}
else
{
echo ""
write-host "Resource group name: " $rsitem.ResourceGroupName " vNet Name: " $vnet.name
write-host " Address range: "$vnet.AddressSpace.AddressPrefixes.Item($addrcnt)
}
}
}
}
Friday, April 19, 2019
Create Azure Resource group and prevent any duplicate object creation
#Author : Neeraj
clear
$RsGrp_name=read-host "Enter resource group name:"
write-host "select location like" -BackgroundColor yellow -ForegroundColor blue
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host "East US" -BackgroundColor yellow -ForegroundColor black
write-host "Central US" -BackgroundColor yellow -ForegroundColor black
write-host "Central India" -BackgroundColor yellow -ForegroundColor black
write-host "etc..." -BackgroundColor yellow -ForegroundColor black
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host ""
$RsGrp_location =read-host "Enter resource group location:"
$rsn=Get-AzureRmResourceGroup |select ResourceGroupName
$flag=0
foreach($rsname in $rsn)
{
if($RsGrp_name -eq $rsname.ResourceGroupName)
{
$flag=1
break
}
else
{
$flag=0
}
}
if($flag -eq 1)
{
write-host "This Resource group already exist, please select another name" -BackgroundColor red -ForegroundColor yellow
}
else
{
write-host "Creating ResourceGroup..." $RsGrp_name -BackgroundColor green -ForegroundColor white
echo "Please wait..."
New-AzureRmResourceGroup -name $RsGrp_name -location $RsGrp_location -Confirm:$false
sleep 10
echo "Generating output"
Get-AzureRmResourceGroup -Name $RsGrp_name
}
clear
$RsGrp_name=read-host "Enter resource group name:"
write-host "select location like" -BackgroundColor yellow -ForegroundColor blue
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host "East US" -BackgroundColor yellow -ForegroundColor black
write-host "Central US" -BackgroundColor yellow -ForegroundColor black
write-host "Central India" -BackgroundColor yellow -ForegroundColor black
write-host "etc..." -BackgroundColor yellow -ForegroundColor black
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host ""
$RsGrp_location =read-host "Enter resource group location:"
$rsn=Get-AzureRmResourceGroup |select ResourceGroupName
$flag=0
foreach($rsname in $rsn)
{
if($RsGrp_name -eq $rsname.ResourceGroupName)
{
$flag=1
break
}
else
{
$flag=0
}
}
if($flag -eq 1)
{
write-host "This Resource group already exist, please select another name" -BackgroundColor red -ForegroundColor yellow
}
else
{
write-host "Creating ResourceGroup..." $RsGrp_name -BackgroundColor green -ForegroundColor white
echo "Please wait..."
New-AzureRmResourceGroup -name $RsGrp_name -location $RsGrp_location -Confirm:$false
sleep 10
echo "Generating output"
Get-AzureRmResourceGroup -Name $RsGrp_name
}
Azure VM listing, start , stop, wild card search
#Author: Neeraj
clear
echo "1.List VMs " "2.Stop VM" "3.Start vm" "4.Wildcard Search"
$VMMch=read-host "Enter your choice:"
if($VMMch -eq 1)
{
$vmlst=Get-AzureRmResource -ResourceType microsoft.compute/virtualmachines | select name |Sort-Object -Property name
$ct=1
foreach($item in $vmlst)
{
write-host $ct "."$item.name
$ct++
}
$cp= Read-Host "Enter VM number"
$ct=1
$chh = $cp
foreach($item in $vmlst)
{
if($ct -eq $chh)
{
$vname=$item.name
Get-AzureRmResource -Name $vname
}
$ct++
}
}
if($VMMch -eq 2)
{
$VMMn=Read-Host "Enter VM name"
$VMMRSGRP = Get-AzureRmResource -name $vMMn -ResourceType microsoft.compute/virtualmachines | select name, resourcegroupname
foreach($item in $VMMRSGRP)
{
echo $item.Name
echo $item.resourcegroupname
get-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
$vmstop=Read-host "Press 'Y' to shutdown the vm"
if($vmstop -eq 'Y')
{
echo "Stopping the vm"
stop-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
}
}
}
if($VMMch -eq 3)
{
$VMMn=Read-Host "Enter VM name"
$VMMRSGRP = Get-AzureRmResource -name $vMMn -ResourceType microsoft.compute/virtualmachines | select name, resourcegroupname
foreach($item in $VMMRSGRP)
{
echo $item.Name
echo $item.resourcegroupname
get-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
$vmstop=Read-host "Press 'Y' to Start the vm"
if($vmstop -eq 'Y')
{
echo "Starting the vm"
start-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
}
}
}
if($VMMch -eq 4)
{
$objname = Read-Host "Enter part of the vm name you want to search"
$wcard = "*"+$objname+"*"
$vmlst=Get-AzureRmResource -name $wcard -ResourceType microsoft.compute/virtualmachines
foreach($obj in $vmlst)
{
echo "" "............................................................................." ""
Write-Host " Name :" $obj.name
Write-Host "Resource Group Name :" $obj.ResourceGroupName
Write-Host " ResourceT ype :" $obj.ResourceType
Write-Host " Location :" $obj.Location
Write-Host " Resource Id :" $obj.ResourceId
}
}
clear
echo "1.List VMs " "2.Stop VM" "3.Start vm" "4.Wildcard Search"
$VMMch=read-host "Enter your choice:"
if($VMMch -eq 1)
{
$vmlst=Get-AzureRmResource -ResourceType microsoft.compute/virtualmachines | select name |Sort-Object -Property name
$ct=1
foreach($item in $vmlst)
{
write-host $ct "."$item.name
$ct++
}
$cp= Read-Host "Enter VM number"
$ct=1
$chh = $cp
foreach($item in $vmlst)
{
if($ct -eq $chh)
{
$vname=$item.name
Get-AzureRmResource -Name $vname
}
$ct++
}
}
if($VMMch -eq 2)
{
$VMMn=Read-Host "Enter VM name"
$VMMRSGRP = Get-AzureRmResource -name $vMMn -ResourceType microsoft.compute/virtualmachines | select name, resourcegroupname
foreach($item in $VMMRSGRP)
{
echo $item.Name
echo $item.resourcegroupname
get-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
$vmstop=Read-host "Press 'Y' to shutdown the vm"
if($vmstop -eq 'Y')
{
echo "Stopping the vm"
stop-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
}
}
}
if($VMMch -eq 3)
{
$VMMn=Read-Host "Enter VM name"
$VMMRSGRP = Get-AzureRmResource -name $vMMn -ResourceType microsoft.compute/virtualmachines | select name, resourcegroupname
foreach($item in $VMMRSGRP)
{
echo $item.Name
echo $item.resourcegroupname
get-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
$vmstop=Read-host "Press 'Y' to Start the vm"
if($vmstop -eq 'Y')
{
echo "Starting the vm"
start-azurermvm -Name $item.Name -ResourceGroupName $item.resourcegroupname
}
}
}
if($VMMch -eq 4)
{
$objname = Read-Host "Enter part of the vm name you want to search"
$wcard = "*"+$objname+"*"
$vmlst=Get-AzureRmResource -name $wcard -ResourceType microsoft.compute/virtualmachines
foreach($obj in $vmlst)
{
echo "" "............................................................................." ""
Write-Host " Name :" $obj.name
Write-Host "Resource Group Name :" $obj.ResourceGroupName
Write-Host " ResourceT ype :" $obj.ResourceType
Write-Host " Location :" $obj.Location
Write-Host " Resource Id :" $obj.ResourceId
}
}
Wednesday, February 20, 2019
Azure Storage Account report for BLOB and files | complete list
#Author : Neeraj Jha
#Get-AzureRMStorageAccount -name neerajtest -ResourceGroupName autorsgroup
$all_storage=Get-AzureRMStorageAccount |select StorageAccountName,ResourceGroupName
$tol_st_size=0
foreach($item in $all_storage)
{
Write-host "For storage account $item.StorageAccountName and Resource group $item.ResourceGroupName"
$sac=Get-AzureRMStorageAccount -name $item.StorageAccountName -ResourceGroupName $item.ResourceGroupName
$Blob_container=Get-AzureStorageContainer -Context $sac.Context
$tot_cont_size=0
foreach($blob_cont in $Blob_container)
{
$Blob_name=Get-AzureStorageBlob -Container $blob_cont.name -Context $sac.Context
$ln=0
write-host "Blob Container Name:" $Blob_cont.name
foreach($file in $Blob_name)
{
$lnt=$file.Length
Write-Host "File name -" $file.name -NoNewline
Write-Host " | File size in Byte -" $file.Length
$ln=$ln+$lnt
}
write-host "Total size in Byte :" $ln
write-host "Total size in KB :" ($ln/1024)
write-host "Total size in MB :" ($ln/1024/1024)
write-host "Total size of BLOB container $Blob_cont.name in GB :" ($ln/1024/1024/1024)
#write-host "Total size in TB :" ($ln/1024/1024/1024/1024)
$tot_cont_size = $tot_cont_size+$ln
echo "------------------------------------------------------------------------"
}
Write-Host "Total size of the Storage account in GB" ($tot_cont_size/1024/1024/1024)
$tol_st_size = $tol_st_size +$tot_cont_size
}
write-host "Tota size of entire storage account BLOB in GB" ($tol_st_size/1024/1024/1024)
#Get-AzureRMStorageAccount -name neerajtest -ResourceGroupName autorsgroup
$all_storage=Get-AzureRMStorageAccount |select StorageAccountName,ResourceGroupName
$tol_st_size=0
foreach($item in $all_storage)
{
Write-host "For storage account $item.StorageAccountName and Resource group $item.ResourceGroupName"
$sac=Get-AzureRMStorageAccount -name $item.StorageAccountName -ResourceGroupName $item.ResourceGroupName
$Blob_container=Get-AzureStorageContainer -Context $sac.Context
$tot_cont_size=0
foreach($blob_cont in $Blob_container)
{
$Blob_name=Get-AzureStorageBlob -Container $blob_cont.name -Context $sac.Context
$ln=0
write-host "Blob Container Name:" $Blob_cont.name
foreach($file in $Blob_name)
{
$lnt=$file.Length
Write-Host "File name -" $file.name -NoNewline
Write-Host " | File size in Byte -" $file.Length
$ln=$ln+$lnt
}
write-host "Total size in Byte :" $ln
write-host "Total size in KB :" ($ln/1024)
write-host "Total size in MB :" ($ln/1024/1024)
write-host "Total size of BLOB container $Blob_cont.name in GB :" ($ln/1024/1024/1024)
#write-host "Total size in TB :" ($ln/1024/1024/1024/1024)
$tot_cont_size = $tot_cont_size+$ln
echo "------------------------------------------------------------------------"
}
Write-Host "Total size of the Storage account in GB" ($tot_cont_size/1024/1024/1024)
$tol_st_size = $tol_st_size +$tot_cont_size
}
write-host "Tota size of entire storage account BLOB in GB" ($tol_st_size/1024/1024/1024)
Tuesday, January 8, 2019
Get Zerto analytics report
#########################################################################################################
###### Disclaimer:This tool will give you basic status of Zerto environment #############################
###### Author:Neeraj Jha ################################################################################
###### Date:28-Dec-2018 ################################################################################
###### Version:1.2.0.0 ################################################################################
#########################################################################################################
clear
function schoice()
{
echo ""
echo " Press 1 to see report on Screen"
echo " Press 2 to get report in Excel Sheet"
echo ""
$sch=read-host " Enter Your Choice"
if($sch -eq 1)
{
renderscr
}
elseif($sch -eq 2)
{
objectexl
}
else
{
echo "You have choosen wrong item"
cont_nu
Read-Host "Press Enter key to Exit"
}
}
function cont_nu()
{
echo ""
echo "========================================================================="
$sch=read-host " Press [ Y/N ] to continue..."
if($sch -eq 'y')
{
schoice
}
}
function renderscr()
{
clear
echo ""
write-host "Welcome to tech-jockey anlytics report for Zerto"
echo ""
write-host " Welcome " $TJUsername " " -ForegroundColor DarkRed -BackgroundColor Green
echo ""
write-host ""
echo ""
echo ""
write-host " "-ForegroundColor DarkRed -BackgroundColor Magenta
write-host " Zerto Status Report " -ForegroundColor DarkRed -BackgroundColor Green
write-host " "-ForegroundColor DarkRed -BackgroundColor Magenta
write-host ""
write-host " Healthy VPGs count: " $web_json.healthyVpgsCount
write-host " Alerted VPGs count: " $web_json.alertedVpgsCount
write-host " Faulted VPGs count: " $web_json.faultedVpgsCount
write-host " Average Actual RPO: " $web_json.averageActualRpo
write-host "Average Configured RPO: " $web_json.averageConfiguredRpo
write-host " No of Sites: " $web_json.sitesCount
write-host " No of VPGs: " $web_json.vpgsCount
write-host " No of protected VMs: " $web_json.vmsCount
write-host " No of Alerts: " $web_json.alertsCount
write-host " No of Tasks: " $web_json.tasksCount
write-host " Total Protected data: " $f_tot_size "TB"
echo ""
echo ""
echo ""
echo ""
echo " Tool Developed by Neeraj, tech-jockey"
echo ""
echo ""
echo ""
echo ""
cont_nu
}
function objectexl()
{
if(!(Test-Path -Path "c:\zerto_rep" ))
{
echo "Creating C:\Zerto_rep directory..."
New-Item -ItemType directory -Path c:\zerto_rep
}
$Excel = New-Object -Com Excel.Application
$Excel.visible = $False
$Excel = $Excel.Workbooks.Add()
$Addsheet = $Excel.sheets.Add()
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(2,1) = “Healthy VPGs count”
$Sheet.Cells.Item(3,1) = “Alerted VPGs count”
$Sheet.Cells.Item(4,1) = “Faulted VPGs count”
$Sheet.Cells.Item(5,1) = “Average Actual RPO”
$Sheet.Cells.Item(6,1) = “Average Configured RPO”
$Sheet.Cells.Item(7,1) = “No of Sites”
$Sheet.Cells.Item(8,1) = “No of VPGs”
$Sheet.Cells.Item(9,1) = “No of protected VMs”
$Sheet.Cells.Item(10,1) = “No of Alerts”
$Sheet.Cells.Item(11,1) = “No of Tasks”
$Sheet.Cells.Item(12,1) = “Total Protected data [TB]”
$Sheet.Cells.Item(1,1) = “Zerto Item Name”
$Sheet.Cells.Item(1,2) = “Item Value”
$Sheet.Cells(1,1).Interior.ColorIndex = 50
$Sheet.Cells(1,2).Interior.ColorIndex = 22
$dash="$healthyVpgsCount","$alertedVpgsCount","$faultedVpgsCount","$averageActualRpo","$averageConfiguredRpo","$sitesCount","$vpgsCount","$vmsCount","$alertsCount","$tasksCount","$tpsize"
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True
$WorkBook.Borders.ColorIndex =40
$R = 2
$C = 2
foreach($D in $dash)
{
$Sheet.Cells.Item($R,$C) = $D
$R = $R + 1
}
$WorkBook.EntireColumn.AutoFit()
$dt=get-date
$day=$dt.Day.ToString()
$hour=$dt.Hour.ToString()
$min=$dt.Minute.ToString()
$month=$dt.Month.ToString()
$sec=$dt.Second.ToString()
$yr=$dt.Year.ToString()
$filename="Zerto_Report_"+$day+"_"+$month+"_"+$yr+"_"+$hour+"_"+$min+"_"+$sec
$filepath="c:\zerto_rep\"+$filename+".xlsx"
echo $filepath
#echo "1"
$Excel.SaveAs($filepath)
$excel.Close()
cont_nu
}
function rend()
{
clear
echo ""
write-host "Welcome to tech-jockey anlytics report for Zerto"
echo ""
write-host " Welcome " $TJUsername " " -ForegroundColor DarkRed -BackgroundColor Green
echo ""
write-host "Please wait while we establishing session with tech-jockey Zerto host"
echo ""
write-host "Establishing connection" -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . "
echo ""
write-host "Rendering content............................................" -NoNewline
write-host "[100% Done]"-NoNewline -ForegroundColor DarkRed -BackgroundColor Yellow
write-host ""
}
#Connection cred start=========
write-host "Welcome to tech-jockey anlytics report for Zerto"
echo ""
$TJUsername = Read-Host "Enter your username:"
$TJSpass = Read-Host "Enter your password:" -AsSecureString
$TJbstr = [System.Runtime.InteropServices.Marshal]::SecureStringToTJbstr($TJSpass)
$TJPASS = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($TJbstr)
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11
#Getting Zerto Analytics Token
$body = ‘{“username”: “‘ + $TJUsername + ‘”,”password”:”‘ + $TJPASS + ‘”}’
$contentType = “application/json”
$xZertoAnalyticsToken = Invoke-RestMethod -Uri “https://analytics.api.zerto.com/v2/auth/token” -Method POST -Body $body -ContentType $contentType
#Build authorization header
$authHeaders = @{“Authorization” = “Bearer ” + $xZertoAnalyticsToken.token}
#skipping tls cert check
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
$web_data=curl -Uri 'https://analytics.api.zerto.com/v2/monitoring' -Headers $authHeaders
$web_json =$web_data.Content | Out-String | ConvertFrom-Json
$tot_size=$web_json.protectedDataSize/1024/1024
$f_tot_size= [math]::Round($tot_size)
$tpsize = $f_tot_size.ToString()
rend
#Connection cred end=========
#calling the gateway
schoice
###### Disclaimer:This tool will give you basic status of Zerto environment #############################
###### Author:Neeraj Jha ################################################################################
###### Date:28-Dec-2018 ################################################################################
###### Version:1.2.0.0 ################################################################################
#########################################################################################################
clear
function schoice()
{
echo ""
echo " Press 1 to see report on Screen"
echo " Press 2 to get report in Excel Sheet"
echo ""
$sch=read-host " Enter Your Choice"
if($sch -eq 1)
{
renderscr
}
elseif($sch -eq 2)
{
objectexl
}
else
{
echo "You have choosen wrong item"
cont_nu
Read-Host "Press Enter key to Exit"
}
}
function cont_nu()
{
echo ""
echo "========================================================================="
$sch=read-host " Press [ Y/N ] to continue..."
if($sch -eq 'y')
{
schoice
}
}
function renderscr()
{
clear
echo ""
write-host "Welcome to tech-jockey anlytics report for Zerto"
echo ""
write-host " Welcome " $TJUsername " " -ForegroundColor DarkRed -BackgroundColor Green
echo ""
write-host ""
echo ""
echo ""
write-host " "-ForegroundColor DarkRed -BackgroundColor Magenta
write-host " Zerto Status Report " -ForegroundColor DarkRed -BackgroundColor Green
write-host " "-ForegroundColor DarkRed -BackgroundColor Magenta
write-host ""
write-host " Healthy VPGs count: " $web_json.healthyVpgsCount
write-host " Alerted VPGs count: " $web_json.alertedVpgsCount
write-host " Faulted VPGs count: " $web_json.faultedVpgsCount
write-host " Average Actual RPO: " $web_json.averageActualRpo
write-host "Average Configured RPO: " $web_json.averageConfiguredRpo
write-host " No of Sites: " $web_json.sitesCount
write-host " No of VPGs: " $web_json.vpgsCount
write-host " No of protected VMs: " $web_json.vmsCount
write-host " No of Alerts: " $web_json.alertsCount
write-host " No of Tasks: " $web_json.tasksCount
write-host " Total Protected data: " $f_tot_size "TB"
echo ""
echo ""
echo ""
echo ""
echo " Tool Developed by Neeraj, tech-jockey"
echo ""
echo ""
echo ""
echo ""
cont_nu
}
function objectexl()
{
if(!(Test-Path -Path "c:\zerto_rep" ))
{
echo "Creating C:\Zerto_rep directory..."
New-Item -ItemType directory -Path c:\zerto_rep
}
$Excel = New-Object -Com Excel.Application
$Excel.visible = $False
$Excel = $Excel.Workbooks.Add()
$Addsheet = $Excel.sheets.Add()
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(2,1) = “Healthy VPGs count”
$Sheet.Cells.Item(3,1) = “Alerted VPGs count”
$Sheet.Cells.Item(4,1) = “Faulted VPGs count”
$Sheet.Cells.Item(5,1) = “Average Actual RPO”
$Sheet.Cells.Item(6,1) = “Average Configured RPO”
$Sheet.Cells.Item(7,1) = “No of Sites”
$Sheet.Cells.Item(8,1) = “No of VPGs”
$Sheet.Cells.Item(9,1) = “No of protected VMs”
$Sheet.Cells.Item(10,1) = “No of Alerts”
$Sheet.Cells.Item(11,1) = “No of Tasks”
$Sheet.Cells.Item(12,1) = “Total Protected data [TB]”
$Sheet.Cells.Item(1,1) = “Zerto Item Name”
$Sheet.Cells.Item(1,2) = “Item Value”
$Sheet.Cells(1,1).Interior.ColorIndex = 50
$Sheet.Cells(1,2).Interior.ColorIndex = 22
$dash="$healthyVpgsCount","$alertedVpgsCount","$faultedVpgsCount","$averageActualRpo","$averageConfiguredRpo","$sitesCount","$vpgsCount","$vmsCount","$alertsCount","$tasksCount","$tpsize"
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True
$WorkBook.Borders.ColorIndex =40
$R = 2
$C = 2
foreach($D in $dash)
{
$Sheet.Cells.Item($R,$C) = $D
$R = $R + 1
}
$WorkBook.EntireColumn.AutoFit()
$dt=get-date
$day=$dt.Day.ToString()
$hour=$dt.Hour.ToString()
$min=$dt.Minute.ToString()
$month=$dt.Month.ToString()
$sec=$dt.Second.ToString()
$yr=$dt.Year.ToString()
$filename="Zerto_Report_"+$day+"_"+$month+"_"+$yr+"_"+$hour+"_"+$min+"_"+$sec
$filepath="c:\zerto_rep\"+$filename+".xlsx"
echo $filepath
#echo "1"
$Excel.SaveAs($filepath)
$excel.Close()
cont_nu
}
function rend()
{
clear
echo ""
write-host "Welcome to tech-jockey anlytics report for Zerto"
echo ""
write-host " Welcome " $TJUsername " " -ForegroundColor DarkRed -BackgroundColor Green
echo ""
write-host "Please wait while we establishing session with tech-jockey Zerto host"
echo ""
write-host "Establishing connection" -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . " -NoNewline
sleep 1
write-host " . "
echo ""
write-host "Rendering content............................................" -NoNewline
write-host "[100% Done]"-NoNewline -ForegroundColor DarkRed -BackgroundColor Yellow
write-host ""
}
#Connection cred start=========
write-host "Welcome to tech-jockey anlytics report for Zerto"
echo ""
$TJUsername = Read-Host "Enter your username:"
$TJSpass = Read-Host "Enter your password:" -AsSecureString
$TJbstr = [System.Runtime.InteropServices.Marshal]::SecureStringToTJbstr($TJSpass)
$TJPASS = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($TJbstr)
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11
#Getting Zerto Analytics Token
$body = ‘{“username”: “‘ + $TJUsername + ‘”,”password”:”‘ + $TJPASS + ‘”}’
$contentType = “application/json”
$xZertoAnalyticsToken = Invoke-RestMethod -Uri “https://analytics.api.zerto.com/v2/auth/token” -Method POST -Body $body -ContentType $contentType
#Build authorization header
$authHeaders = @{“Authorization” = “Bearer ” + $xZertoAnalyticsToken.token}
#skipping tls cert check
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
$web_data=curl -Uri 'https://analytics.api.zerto.com/v2/monitoring' -Headers $authHeaders
$web_json =$web_data.Content | Out-String | ConvertFrom-Json
$tot_size=$web_json.protectedDataSize/1024/1024
$f_tot_size= [math]::Round($tot_size)
$tpsize = $f_tot_size.ToString()
rend
#Connection cred end=========
#calling the gateway
schoice
Tuesday, December 25, 2018
VMware vCloud - Search vm from multiple vCLouds
clear
echo "Welcome to tech_jockey VM search Tool"
echo "====================================="
$cred=get-credential
clear
echo "Welcome to tech_jockey VM search Tool"
echo "====================================="
#Putting multiple vCloud names in the array
$Server = "https://cloud1.tech-jockey.com","https://cloud1.tech-jockey.com","https://cloud1.tech-jockey.com","cloud1.tech-jockey.com"
echo "Connecting please wait..."
#connecting all the vCloud at a time so that later on we can fire command
foreach($_ in $Server)
{
Connect-CIServer $_ -credential $cred
}
$vmn=read-host "Enter VM name"
$vmm=Get-CIVM $vmn.tostring()
write-host "Name: " $vmm.Name -ForegroundColor blue -BackgroundColor yellow
write-host "Org: " $vmm.Org -ForegroundColor blue -BackgroundColor yellow
write-host "OrgVDC: "$vmm.OrgvDC -ForegroundColor blue -BackgroundColor yellow
write-host "Status: "$vmm.status -ForegroundColor blue -BackgroundColor yellow
write-host "OS name: "$vmm.guestOSFullName -ForegroundColor blue -BackgroundColor yellow
Write-Host "vAPP Name: "$vmm.VApp -ForegroundColor blue -BackgroundColor yellow
write-host "vCD Name: "$vmm.Client.ServiceUri -ForegroundColor blue -BackgroundColor yellow
echo "Thanks for using VM search tool"
echo "Author : Neeraj Jha And Gautam Johar"
echo "Welcome to tech_jockey VM search Tool"
echo "====================================="
$cred=get-credential
clear
echo "Welcome to tech_jockey VM search Tool"
echo "====================================="
#Putting multiple vCloud names in the array
$Server = "https://cloud1.tech-jockey.com","https://cloud1.tech-jockey.com","https://cloud1.tech-jockey.com","cloud1.tech-jockey.com"
echo "Connecting please wait..."
#connecting all the vCloud at a time so that later on we can fire command
foreach($_ in $Server)
{
Connect-CIServer $_ -credential $cred
}
$vmn=read-host "Enter VM name"
$vmm=Get-CIVM $vmn.tostring()
write-host "Name: " $vmm.Name -ForegroundColor blue -BackgroundColor yellow
write-host "Org: " $vmm.Org -ForegroundColor blue -BackgroundColor yellow
write-host "OrgVDC: "$vmm.OrgvDC -ForegroundColor blue -BackgroundColor yellow
write-host "Status: "$vmm.status -ForegroundColor blue -BackgroundColor yellow
write-host "OS name: "$vmm.guestOSFullName -ForegroundColor blue -BackgroundColor yellow
Write-Host "vAPP Name: "$vmm.VApp -ForegroundColor blue -BackgroundColor yellow
write-host "vCD Name: "$vmm.Client.ServiceUri -ForegroundColor blue -BackgroundColor yellow
echo "Thanks for using VM search tool"
echo "Author : Neeraj Jha And Gautam Johar"
Monday, May 21, 2018
AzureRM Powershell script to list down all the resource group
function listresourcegroup
{
Wtite-host " Fetching resource group details, please wait for few seconds...."
echo ""
$rsgrp=Get-AzureRmResourceGroup | select ResourceGroupName
$rscount=$rsgrp.count
write-host "Available Resource groups" -BackgroundColor yellow -ForegroundColor blue
write-host "========================"
foreach($item in $rsgrp)
{
write-host " Resource Group Name -- " $item.ResourceGroupName -BackgroundColor yellow -ForegroundColor black
}
echo ""
Write-host "No of Resource group : " $rscount -BackgroundColor yellow -ForegroundColor red
$RsGrp_choice = read-host "Enter resource group Name to see details, Press '1' to return to main menu:"
if($RsGrp_choice -eq 1)
{
menu
}
else
{
get-AzureRmResourceGroup -name $RsGrp_choice
$rsch= read-host "Want to continue [y/n]"
if($rsch -eq "y")
{ RSgrp_item }
elseif($rsch -eq "n")
{ RsGrp }
else { main }
}
}
{
Wtite-host " Fetching resource group details, please wait for few seconds...."
echo ""
$rsgrp=Get-AzureRmResourceGroup | select ResourceGroupName
$rscount=$rsgrp.count
write-host "Available Resource groups" -BackgroundColor yellow -ForegroundColor blue
write-host "========================"
foreach($item in $rsgrp)
{
write-host " Resource Group Name -- " $item.ResourceGroupName -BackgroundColor yellow -ForegroundColor black
}
echo ""
Write-host "No of Resource group : " $rscount -BackgroundColor yellow -ForegroundColor red
$RsGrp_choice = read-host "Enter resource group Name to see details, Press '1' to return to main menu:"
if($RsGrp_choice -eq 1)
{
menu
}
else
{
get-AzureRmResourceGroup -name $RsGrp_choice
$rsch= read-host "Want to continue [y/n]"
if($rsch -eq "y")
{ RSgrp_item }
elseif($rsch -eq "n")
{ RsGrp }
else { main }
}
}
Thursday, May 3, 2018
Azure Resource Group/Virtual Network - Powershell
#Author : Neeraj
New-AzureRmResourceGroup -Name MyRSGroup -Location EastUS
$sub1=New-AzureRmVirtualNetworkSubnetConfig -name 'subnet1' -AddressPrefix 192.168.1.0/24
$vnet1=new-azurermvirtualnetwork -name 'myvnet' -ResourceGroupName MyRSGroup -AddressPrefix 192.168.0.0/16 -Subnet $sub1 -Location eastus
$sub2=Add-AzureRmVirtualNetworkSubnetConfig -name 'subnet2' -AddressPrefix 192.168.2.0/24 -VirtualNetwork $vnet1
set-azurermvirtualnetwork -VirtualNetwork $vnet1
set-azurermvirtualnetwork -VirtualNetwork $vnet1
Azure RM |Powershell Menu driven Resource Group to automate complete IAAS objects Version-1
#Author : Neeraj (neerajvayu123@gmail.com), please share your feedback that's the only thing i want in return of this script
##################################################################################
#As of now only creation of unique resource group is possible but in later version I will add menu driven VM, VNET, VPN creations, more things to come, keep on sharing this and please give your feedback and suggestions because that is more important for me to make such scripts
#Author : Neeraj Kumar Jha
#Date : 20-March-2018, Time : 10:54 PM IST
#Version : 1.2 #Date modified : 28th May
#Added feature : You can see resource of resource group
#Upcoming feature in pipeline : List resource by TYPE in the resource group
##################################################################################
function menu
{
clear
write-host "Select your working unit:"
echo "1.Resource Group" "2.Virtual Machine" "3.vNet" "4.Exit"
$ch=read-host "Enter Action no:"
if($ch -eq 1)
{
RsGrp #calling function to manage resource group
}
if($ch -eq 2)
{
VMM #calling function to manage VM
}
if($ch -eq 3)
{
Vnet #calling function to manage virtual network
}
if($ch -eq 4)
{
write-host "Thanks for using NeerajVayu Azure code" -BackgroundColor yellow -ForegroundColor blue
break
}
}
function RsGrp
{
clear
write-host "Select your choice"
echo "1.View Resource Group" "2.Create Resource Group" "3.View Resources in Group" "4.View Resource by Type" "5.Back to main menu"
$ch=read-host "Enter your choice no"
if($ch -eq 1)
{
RsGrp_view
}
if($ch -eq 2)
{
RsGrp_create
}
if($ch -eq 3)
{
RsGrp_item
}
#function Compute_list($compute_name)
if($ch -eq 4)
{
Compute_list
}
if($ch -eq 5)
{
menu
}
}
function VMM
{
}
function Vnet
{
}
#region Resource Group [****]
########## Compute_list Function to see resources by type ########
function Compute_list
{
write-host "Select resource type to list" -BackgroundColor yellow -ForegroundColor blue
echo ""
write-host "===========================" -BackgroundColor yellow -ForegroundColor red
write-host "1.Availability Sets" -BackgroundColor yellow -ForegroundColor black
write-host "2.Disks" -BackgroundColor yellow -ForegroundColor black
write-host "3.Virtual Machines" -BackgroundColor yellow -ForegroundColor black
write-host "4.Network Interfaces" -BackgroundColor yellow -ForegroundColor black
write-host "5.Network Security Groups" -BackgroundColor yellow -ForegroundColor black
write-host "6.Public IP Addresses" -BackgroundColor yellow -ForegroundColor black
write-host "7.Virtual Networks" -BackgroundColor yellow -ForegroundColor black
write-host "8.Back to main menu" -BackgroundColor yellow -ForegroundColor black
write-host "===========================" -BackgroundColor yellow -ForegroundColor red
echo ""
$ch=read-host "Enter your choice"
#Future enhancement
#Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/virtualMachines" | where-object -Property location -eq "centralus"
#Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/virtualMachines" | where-object -Property ResourceGroupName -eq "LinuxRsGrp"
#end Future enhancement
switch($ch)
{
1 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/availabilitySets" }
2 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/disks" }
3 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/virtualMachines" }
4 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/virtualNetworks" }
5 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/networkInterfaces" }
6 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/networkSecurityGroups" }
7 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/publicIPAddresses" }
8 { menu }
default {"Invalid entry"}
}
echo ""
echo ""
read-host "Press Enter key to continue"
echo ""
echo ""
echo "Back to previous menu..."
echo ". . . . . . . . . . . . . . . . . . . . . . . . . %100"
RsGrp
}
######### End function Compute_list ##########
function RsGrp_view # function RsGrp_view Start
{
clear
Get-AzureRmResourceGroup
echo ""
read-host "Press ENTER to continue"
RsGrp
} # function RsGrp_view end
function RsGrp_create # function RsGrp_create Start
{
echo ""
echo ""
$RsGrp_name=read-host "Enter resource group name:"
clear
write-host "select location like" -BackgroundColor yellow -ForegroundColor blue
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host "East US" -BackgroundColor yellow -ForegroundColor black
write-host "Central US" -BackgroundColor yellow -ForegroundColor black
write-host "Central India" -BackgroundColor yellow -ForegroundColor black
write-host "etc..." -BackgroundColor yellow -ForegroundColor black
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host ""
$RsGrp_location =read-host "Enter resource group location:"
$rsn=Get-AzureRmResourceGroup |select ResourceGroupName
$flag=0
#comparing the resource group :
#$RsGrp_name="RS2"
foreach($rsname in $rsn)
{
if($RsGrp_name -eq $rsname.ResourceGroupName)
{
$flag=1
break
}
else
{
$flag=0
}
}
if($flag -eq 1)
{
write-host "This Resource group already exist, please select another name" -BackgroundColor red -ForegroundColor yellow
echo ""
write-host -NoNewline "Going to main menu in 5 seconds..." -BackgroundColor green -ForegroundColor white
progress
menu
}
else
{
write-host "Creating ResourceGroup..." $RsGrp_name -BackgroundColor green -ForegroundColor white
New-AzureRmResourceGroup -name $RsGrp_name -location $RsGrp_location -Confirm:$false
write-host "Please view RG status to check" -BackgroundColor green -ForegroundColor white
}
echo ""
echo ""
write-host -NoNewline "Loading resource group list"
progress
echo ""
echo ""
read-host "Press ENTER KEY to continue"
RsGrp_view
}
##################### function RsGrp_create End
function RsGrp_item #############function RsGrp_item start - this is to list down resource by specific resource grp name
{
Write-host " Fetching resource group details, please wait for few seconds...."
echo ""
$rsgrp=Get-AzureRmResourceGroup | select ResourceGroupName
$rscount=$rsgrp.count
write-host "Available Resource groups" -BackgroundColor yellow -ForegroundColor blue
write-host "========================"
foreach($item in $rsgrp)
{
write-host " Resource Group Name -- " $item.ResourceGroupName -BackgroundColor yellow -ForegroundColor black
}
echo ""
Write-host "No of Resource group : " $rscount -BackgroundColor yellow -ForegroundColor red
$RsGrp_choice = read-host "Enter resource group Name to see details, Press '1' to return to main menu:"
if($RsGrp_choice -eq 1)
{
menu
}
else
{
get-AzureRmResourceGroup -name $RsGrp_choice
$rsch= read-host "Want to continue [y/n]"
if($rsch -eq "y")
{ RSgrp_item }
elseif($rsch -eq "n")
{ RsGrp }
else { main }
}
read-host "Press Enter key to go back to Resource Group menu"
RsGrp
}
#endregion Resource Group [****]
function progress # function progress Start
{
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". Done"
sleep 1
write-host ""
echo ""
} # function progress End
##################################
##################################################################################
#As of now only creation of unique resource group is possible but in later version I will add menu driven VM, VNET, VPN creations, more things to come, keep on sharing this and please give your feedback and suggestions because that is more important for me to make such scripts
#Author : Neeraj Kumar Jha
#Date : 20-March-2018, Time : 10:54 PM IST
#Version : 1.2 #Date modified : 28th May
#Added feature : You can see resource of resource group
#Upcoming feature in pipeline : List resource by TYPE in the resource group
##################################################################################
function menu
{
clear
write-host "Select your working unit:"
echo "1.Resource Group" "2.Virtual Machine" "3.vNet" "4.Exit"
$ch=read-host "Enter Action no:"
if($ch -eq 1)
{
RsGrp #calling function to manage resource group
}
if($ch -eq 2)
{
VMM #calling function to manage VM
}
if($ch -eq 3)
{
Vnet #calling function to manage virtual network
}
if($ch -eq 4)
{
write-host "Thanks for using NeerajVayu Azure code" -BackgroundColor yellow -ForegroundColor blue
break
}
}
function RsGrp
{
clear
write-host "Select your choice"
echo "1.View Resource Group" "2.Create Resource Group" "3.View Resources in Group" "4.View Resource by Type" "5.Back to main menu"
$ch=read-host "Enter your choice no"
if($ch -eq 1)
{
RsGrp_view
}
if($ch -eq 2)
{
RsGrp_create
}
if($ch -eq 3)
{
RsGrp_item
}
#function Compute_list($compute_name)
if($ch -eq 4)
{
Compute_list
}
if($ch -eq 5)
{
menu
}
}
function VMM
{
}
function Vnet
{
}
#region Resource Group [****]
########## Compute_list Function to see resources by type ########
function Compute_list
{
write-host "Select resource type to list" -BackgroundColor yellow -ForegroundColor blue
echo ""
write-host "===========================" -BackgroundColor yellow -ForegroundColor red
write-host "1.Availability Sets" -BackgroundColor yellow -ForegroundColor black
write-host "2.Disks" -BackgroundColor yellow -ForegroundColor black
write-host "3.Virtual Machines" -BackgroundColor yellow -ForegroundColor black
write-host "4.Network Interfaces" -BackgroundColor yellow -ForegroundColor black
write-host "5.Network Security Groups" -BackgroundColor yellow -ForegroundColor black
write-host "6.Public IP Addresses" -BackgroundColor yellow -ForegroundColor black
write-host "7.Virtual Networks" -BackgroundColor yellow -ForegroundColor black
write-host "8.Back to main menu" -BackgroundColor yellow -ForegroundColor black
write-host "===========================" -BackgroundColor yellow -ForegroundColor red
echo ""
$ch=read-host "Enter your choice"
#Future enhancement
#Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/virtualMachines" | where-object -Property location -eq "centralus"
#Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/virtualMachines" | where-object -Property ResourceGroupName -eq "LinuxRsGrp"
#end Future enhancement
switch($ch)
{
1 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/availabilitySets" }
2 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/disks" }
3 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Compute/virtualMachines" }
4 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/virtualNetworks" }
5 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/networkInterfaces" }
6 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/networkSecurityGroups" }
7 { Get-AzureRmResource |where-object -Property ResourceType -eq "Microsoft.Network/publicIPAddresses" }
8 { menu }
default {"Invalid entry"}
}
echo ""
echo ""
read-host "Press Enter key to continue"
echo ""
echo ""
echo "Back to previous menu..."
echo ". . . . . . . . . . . . . . . . . . . . . . . . . %100"
RsGrp
}
######### End function Compute_list ##########
function RsGrp_view # function RsGrp_view Start
{
clear
Get-AzureRmResourceGroup
echo ""
read-host "Press ENTER to continue"
RsGrp
} # function RsGrp_view end
function RsGrp_create # function RsGrp_create Start
{
echo ""
echo ""
$RsGrp_name=read-host "Enter resource group name:"
clear
write-host "select location like" -BackgroundColor yellow -ForegroundColor blue
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host "East US" -BackgroundColor yellow -ForegroundColor black
write-host "Central US" -BackgroundColor yellow -ForegroundColor black
write-host "Central India" -BackgroundColor yellow -ForegroundColor black
write-host "etc..." -BackgroundColor yellow -ForegroundColor black
write-host "==============" -BackgroundColor yellow -ForegroundColor red
write-host ""
$RsGrp_location =read-host "Enter resource group location:"
$rsn=Get-AzureRmResourceGroup |select ResourceGroupName
$flag=0
#comparing the resource group :
#$RsGrp_name="RS2"
foreach($rsname in $rsn)
{
if($RsGrp_name -eq $rsname.ResourceGroupName)
{
$flag=1
break
}
else
{
$flag=0
}
}
if($flag -eq 1)
{
write-host "This Resource group already exist, please select another name" -BackgroundColor red -ForegroundColor yellow
echo ""
write-host -NoNewline "Going to main menu in 5 seconds..." -BackgroundColor green -ForegroundColor white
progress
menu
}
else
{
write-host "Creating ResourceGroup..." $RsGrp_name -BackgroundColor green -ForegroundColor white
New-AzureRmResourceGroup -name $RsGrp_name -location $RsGrp_location -Confirm:$false
write-host "Please view RG status to check" -BackgroundColor green -ForegroundColor white
}
echo ""
echo ""
write-host -NoNewline "Loading resource group list"
progress
echo ""
echo ""
read-host "Press ENTER KEY to continue"
RsGrp_view
}
##################### function RsGrp_create End
function RsGrp_item #############function RsGrp_item start - this is to list down resource by specific resource grp name
{
Write-host " Fetching resource group details, please wait for few seconds...."
echo ""
$rsgrp=Get-AzureRmResourceGroup | select ResourceGroupName
$rscount=$rsgrp.count
write-host "Available Resource groups" -BackgroundColor yellow -ForegroundColor blue
write-host "========================"
foreach($item in $rsgrp)
{
write-host " Resource Group Name -- " $item.ResourceGroupName -BackgroundColor yellow -ForegroundColor black
}
echo ""
Write-host "No of Resource group : " $rscount -BackgroundColor yellow -ForegroundColor red
$RsGrp_choice = read-host "Enter resource group Name to see details, Press '1' to return to main menu:"
if($RsGrp_choice -eq 1)
{
menu
}
else
{
get-AzureRmResourceGroup -name $RsGrp_choice
$rsch= read-host "Want to continue [y/n]"
if($rsch -eq "y")
{ RSgrp_item }
elseif($rsch -eq "n")
{ RsGrp }
else { main }
}
read-host "Press Enter key to go back to Resource Group menu"
RsGrp
}
#endregion Resource Group [****]
function progress # function progress Start
{
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". "
sleep 1
write-host -NoNewline ". Done"
sleep 1
write-host ""
echo ""
} # function progress End
##################################
Azure site-to-site VPN through powershell script
#Author : Neeraj (neerajvayu123@gmail.com)- please give credit to the author if it helped you
Please carefully go through the code and run part by part like i did
1.PartA, 2.PartB, 3.PartC, 4.PartD
If you will not run like this you may face some other issue, let me know if you face any issue at any step
This script is tested and fully working , after a lot of failed attempt finally i made a working version
Note: I have not included login steps in this script so pls take care of that
#PART A
#create a gateway subnet for myvnet
$rsgrp=Get-AzureRmResourceGroup -name 'MyRSGroup'
$GWIPName1 = "myvnetIP"
#gateway public ip
$gwpip1 = New-AzureRmPublicIpAddress -Name $GWIPName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location EastUS -AllocationMethod Dynamic
$GWSubName1 = "GatewaySubnet"
$GWSubPrefix1 = "https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e3%2e0%2F24"
#gateway configuration
$vnet1 = Get-AzureRmVirtualNetwork -Name myvnet -ResourceGroupName $rsgrp.ResourceGroupName
Add-AzureRmVirtualNetworkSubnetConfig -name $GWSubName1 -AddressPrefix $GWSubPrefix1 -VirtualNetwork $vnet1
set-azurermvirtualnetwork -VirtualNetwork $vnet1
#assigning newer value to the vnet1 is mandatory else it will take old subnets
$vnet1 = Get-AzureRmVirtualNetwork -Name myvnet -ResourceGroupName $rsgrp.ResourceGroupName
$subnet1 = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet1
$GWIPconfName1 = "gwipconf1-myvnet"
$gwipconf1 = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName1 `
-Subnet $subnet1 -PublicIpAddress $gwpip1
#create gateway
$GWName1 = "myvnetGW"
New-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location EastUS -IpConfigurations $gwipconf1 -GatewayType Vpn `
-VpnType RouteBased -GatewaySku VpnGw1
#PART C
$GWName1 = "myvnetGW"
$rsgrp=Get-AzureRmResourceGroup -name 'MyRSGroup'
$vnet1gw = Get-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName
$Connection14="myvnet-to-vpn3net"
$rsgrp=Get-AzureRmResourceGroup -name 'MyRSGroup'
New-AzureRmVirtualNetworkGatewayConnection -Name $Connection14 -ResourceGroupName $rsgrp.ResourceGroupName `
-VirtualNetworkGateway1 $vnet1gw -VirtualNetworkGateway2 $vnet4gw -Location 'East Us' `
-ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'
#######################################################
#PART B
#create a gateway subnet for vpn3net
$rsgrp=Get-AzureRmResourceGroup -name 'vpn-3'
$GWIPName1 = "vpn3netIP"
#gateway public ip
$gwpip1 = New-AzureRmPublicIpAddress -Name $GWIPName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location 'Central US' -AllocationMethod Dynamic
$GWSubName1 = "GatewaySubnet"
$GWSubPrefix1 = "https://www.linkedin.com/redir/invalid-link-page?url=172%2e16%2e2%2e0%2F24"
#gateway configuration
$vnet1 = Get-AzureRmVirtualNetwork -Name vpn3net -ResourceGroupName $rsgrp.ResourceGroupName
echo "adding subnet"
Add-AzureRmVirtualNetworkSubnetConfig -name $GWSubName1 -AddressPrefix $GWSubPrefix1 -VirtualNetwork $vnet1
echo "setting vnet"
set-azurermvirtualnetwork -VirtualNetwork $vnet1
#assigning newer value to the vnet1 is mandatory else it will take old subnets
$vnet1 = Get-AzureRmVirtualNetwork -Name vpn3net -ResourceGroupName $rsgrp.ResourceGroupName
$subnet1 = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet1
$GWIPconfName1 = "gwipconf1-vpn3net"
echo "creating gateway ip config"
$gwipconf1 = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName1 `
-Subnet $subnet1 -PublicIpAddress $gwpip1
echo "creating gateway device"
#create gateway
$GWName1 = "vpn3netGW"
New-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location 'Central US' -IpConfigurations $gwipconf1 -GatewayType Vpn `
-VpnType RouteBased -GatewaySku VpnGw1 -Verbose
#PART D
$GWName1 = "vpn3netGW"
$rsgrp=Get-AzureRmResourceGroup -name 'vpn-3'
$vnet4gw = Get-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName
$Connection41="vpn3net-to-myvnet"
$rsgrp=Get-AzureRmResourceGroup -name 'vpn-3'
New-AzureRmVirtualNetworkGatewayConnection -Name $Connection41 -ResourceGroupName $rsgrp.ResourceGroupName `
-VirtualNetworkGateway1 $vnet4gw -VirtualNetworkGateway2 $vnet1gw -Location 'Central US' `
-ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'
Please carefully go through the code and run part by part like i did
1.PartA, 2.PartB, 3.PartC, 4.PartD
If you will not run like this you may face some other issue, let me know if you face any issue at any step
This script is tested and fully working , after a lot of failed attempt finally i made a working version
Note: I have not included login steps in this script so pls take care of that
#PART A
#create a gateway subnet for myvnet
$rsgrp=Get-AzureRmResourceGroup -name 'MyRSGroup'
$GWIPName1 = "myvnetIP"
#gateway public ip
$gwpip1 = New-AzureRmPublicIpAddress -Name $GWIPName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location EastUS -AllocationMethod Dynamic
$GWSubName1 = "GatewaySubnet"
$GWSubPrefix1 = "https://www.linkedin.com/redir/invalid-link-page?url=192%2e168%2e3%2e0%2F24"
#gateway configuration
$vnet1 = Get-AzureRmVirtualNetwork -Name myvnet -ResourceGroupName $rsgrp.ResourceGroupName
Add-AzureRmVirtualNetworkSubnetConfig -name $GWSubName1 -AddressPrefix $GWSubPrefix1 -VirtualNetwork $vnet1
set-azurermvirtualnetwork -VirtualNetwork $vnet1
#assigning newer value to the vnet1 is mandatory else it will take old subnets
$vnet1 = Get-AzureRmVirtualNetwork -Name myvnet -ResourceGroupName $rsgrp.ResourceGroupName
$subnet1 = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet1
$GWIPconfName1 = "gwipconf1-myvnet"
$gwipconf1 = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName1 `
-Subnet $subnet1 -PublicIpAddress $gwpip1
#create gateway
$GWName1 = "myvnetGW"
New-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location EastUS -IpConfigurations $gwipconf1 -GatewayType Vpn `
-VpnType RouteBased -GatewaySku VpnGw1
#PART C
$GWName1 = "myvnetGW"
$rsgrp=Get-AzureRmResourceGroup -name 'MyRSGroup'
$vnet1gw = Get-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName
$Connection14="myvnet-to-vpn3net"
$rsgrp=Get-AzureRmResourceGroup -name 'MyRSGroup'
New-AzureRmVirtualNetworkGatewayConnection -Name $Connection14 -ResourceGroupName $rsgrp.ResourceGroupName `
-VirtualNetworkGateway1 $vnet1gw -VirtualNetworkGateway2 $vnet4gw -Location 'East Us' `
-ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'
#######################################################
#PART B
#create a gateway subnet for vpn3net
$rsgrp=Get-AzureRmResourceGroup -name 'vpn-3'
$GWIPName1 = "vpn3netIP"
#gateway public ip
$gwpip1 = New-AzureRmPublicIpAddress -Name $GWIPName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location 'Central US' -AllocationMethod Dynamic
$GWSubName1 = "GatewaySubnet"
$GWSubPrefix1 = "https://www.linkedin.com/redir/invalid-link-page?url=172%2e16%2e2%2e0%2F24"
#gateway configuration
$vnet1 = Get-AzureRmVirtualNetwork -Name vpn3net -ResourceGroupName $rsgrp.ResourceGroupName
echo "adding subnet"
Add-AzureRmVirtualNetworkSubnetConfig -name $GWSubName1 -AddressPrefix $GWSubPrefix1 -VirtualNetwork $vnet1
echo "setting vnet"
set-azurermvirtualnetwork -VirtualNetwork $vnet1
#assigning newer value to the vnet1 is mandatory else it will take old subnets
$vnet1 = Get-AzureRmVirtualNetwork -Name vpn3net -ResourceGroupName $rsgrp.ResourceGroupName
$subnet1 = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet1
$GWIPconfName1 = "gwipconf1-vpn3net"
echo "creating gateway ip config"
$gwipconf1 = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName1 `
-Subnet $subnet1 -PublicIpAddress $gwpip1
echo "creating gateway device"
#create gateway
$GWName1 = "vpn3netGW"
New-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName `
-Location 'Central US' -IpConfigurations $gwipconf1 -GatewayType Vpn `
-VpnType RouteBased -GatewaySku VpnGw1 -Verbose
#PART D
$GWName1 = "vpn3netGW"
$rsgrp=Get-AzureRmResourceGroup -name 'vpn-3'
$vnet4gw = Get-AzureRmVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $rsgrp.ResourceGroupName
$Connection41="vpn3net-to-myvnet"
$rsgrp=Get-AzureRmResourceGroup -name 'vpn-3'
New-AzureRmVirtualNetworkGatewayConnection -Name $Connection41 -ResourceGroupName $rsgrp.ResourceGroupName `
-VirtualNetworkGateway1 $vnet4gw -VirtualNetworkGateway2 $vnet1gw -Location 'Central US' `
-ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'
Subscribe to:
Posts (Atom)
Content of this blog has been moved to GITHUB
Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...
-
(gwmi -Namespace root\wmi -Class mpio_disk_info).driveinfo | % {Write-host "Name: $($_.name) Paths: $($_.numberpaths)"}
-
Here is what you need to do: Step 1: Restart your machine. Its always good to go for the ‘when-nothing-works-try-this’ solution Step 2:...