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)
                             }
                     }
    }
     
}

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
       }

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
        }
    }

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)

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

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...