Techno Chat|Tech Blog!! Chat with style.. :P Wed, 05 Sep 2018 05:04:27 +0000 en-US hourly 1 Techno Chat|Tech Blog!! 32 32 125923132 Powerful AWS Bot for automation using Telegram Bot API written in PowerShell Wed, 08 Nov 2017 02:51:32 +0000 Continue reading ]]>

Sometimes back I was working on a free notification system using Telegram Bot (, and I wrote a simple function in PowerShell, which could be use in various ways for sending instant notification to any smartphone for free (

I thought what else we could do with it, and I have got an idea to use it as AWS Automation Bot to perform simple tasks. I have created a set of instructions for a Bot using PowerShell script which we could use to perform the following tasks instantly instead of doing it from AWS console.

  1. Getting instance details using instance name.
  2. Getting attached volume details using instance name.
  3. Getting list of the available snapshots for a instances using instance name.
  4. Getting the console screenshot for troubleshooting using instance name.
  5. Getting the console log for troubleshooting using instance name.
  6. Start an instance using instance name.
  7. Stop an instance using instance name.
  8. Restart an instance using instance name.

Note: Start/Stop/Restart option will not be available for all, this Bot will be part of a Telegram Group, and only existing user who already have the permission for this can grant these permission to someone else. This is additional layer security control I have created to avoid unauthorized system state modification.

If you really interested to give it a try, please follow the steps bellow.

  1. Download Telegram on your mobile from marketplace (available on all the platform)
  2. Visit the following link to join the Demo Group.

  1. As soon as you are in the group, use /help to get what are the instruction you can give to the bot.
  2. Please provide feedback here.

Tips: Since I am using free AWS environment, I am limited to use 30 GB of volume, so, I have created three AWS Linux instances in three different regions (Sydney/Virginia/Oregon), name of them are TELTSTSYD for Sydney, TELTSTVIR for Virginia and TELTSTORE for Oregon. All the instructions are applicable against instance name, not the instance ID, e.g. /info=TELTSTSYD to know the instance details. Currently there is no snapshot available for any of the instances as it will be beyond my free limit. Always make sure your executing the commands on correct region. Additionally, this demo environment currently available during 8:00 AM AEST to 10:00 PM AEST to avoid unnecessary changes on my Azure Subscription.

Note: This bot is running from my own server hosted on my personal Azure Subscription, also the AWS environment where the demo configured is my personal AWS Account. Only purpose I have created this environment is to demonstrate this feature and usability of this bot and the automation process.

If you are interested further, then please do let me know here in the comments, I will share my code and configuration details if I see the demand.

UPDATE 1: Added a new video demo.
UPDATE 2: This project now open source, and available under GitHub :

Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.

]]> 3 3096
Add new Admin Account to AWS Windows Instances to rescue the system Wed, 01 Nov 2017 04:57:10 +0000 Continue reading ]]> As mentioned earlier, we could reset the local admin password of windows instances via registry, but unfortunately that will not going to help us if we forget the user id details or we renamed the user id. And the good news is, we still will be able to logon into the system by creating one new Admin Account using AWS User Data. This process is very simple as described bellow.

  • You have to re-attached the root volume of faulty system to a working AWS instances.
  • Now, you have to use EC2Rescue to enable user data (Ec2HandelUserData), which will execute a script on next boot. (*This could be done by editing config.xml file of EC2Config)

  • Once done, you have to re-attach the volume to the original system as root (/dev/sda1) volume.
  • Now, from AWS EC2 Console, you have to select the server and edit the User Data before starting the server and add the following PowerShell script. This script will create a Admin Account called “MyAdminX” with the password “!!4SJKAHGYWMd4!!” on first boot and you will be able to logon to the server using this new account.

$Computer = [ADSI]"WinNT://$Env:COMPUTERNAME,Computer"
$LocalAdmin = $Computer.Create("User", $Name)
$LocalAdmin.FullName = $Name
$LocalAdmin.Description = "Admin Account created using User Data"
$AdminGroup = [ADSI]"WinNT://$Env:COMPUTERNAME/Administrators,group"
$User = [ADSI]"WinNT://$Env:COMPUTERNAME/$Name,User"


I hope this will be helpful for you.

]]> 1 3085
How to use Telegram Bot as Event Notifier to send instant notification on your Smartphone using PowerShell Mon, 27 Mar 2017 07:03:58 +0000 Continue reading ]]> Since we are working in IT industry & proving support to our clients, we are always dependent on various form of notification such as emails, sms, voice etc, and none of them are free, especially when the you are sending those traditional notifications across the globe. Currently almost everyone using smartphone, and mostly those are connected to the internet for 24×7, so I guess, it’s time to send those notifications smartly. Try using Telegram Bot for sending personal notification for free to any of the Smartphones.

To start with, you should create your own Bot on Telegram. You should ask the BotFather (father of all the Bots) to create a boot for you.

Install Telegram, register yourself and search for BotFather.

Once you find it, select it and tap on START button (I had already created this, so, I am getting RESTART button).

Once you tap START button, you will be greeted with the following message.

Now send /newbot and it will ask you to provide the name of your bot.

I gave it NotificationPS, and after that it will ask to provide thee name of your bot, I gave it PSNotificationXBot.
Note: Your name should end with Bot.

Once you gave it a unique name, BotFathar will share the APT Token to manage your Bot.

Now, again search for newly created bot and once you find it, select it.

Now, tap START button. (I had already selected this, so, I am getting RESTART button)

Now you must have the Chat ID to send the notification to yourself and to do it, please execute following in your PowerShell.

$BotKey = "Your APT Token"
$GetChatID = Invoke-WebRequest -Uri "$BotKey/getUpdates"
(ConvertFrom-Json $GetChatID.Content)

Once you get the Chat ID, execute the following code (function) to your PowerShell, this will help you later to send Telegram messages easily.

function Send-TeleMessage([string] $BotKey , [array] $ChatIDs , [string] $Message)
    $sendMsgLink = "$BotKey/sendMessage"
    foreach ($ID in $ChatIDs)
            $ExecuteInvokeWeb = Invoke-WebRequest -Uri "$sendMsgLink" -Method Post -ContentType "application/json;charset=utf-8" -Body (ConvertTo-Json -Compress -InputObject @{chat_id=$ID; text="$Message"}) -ErrorAction SilentlyContinue
            $Status = (ConvertFrom-Json -InputObject $ExecuteInvokeWeb.Content)
            if($Status.ok){Write-Host "Message successfully sent to Chat ID : $ID (Type : $($" -ForegroundColor Green}
        catch [Exception]
            $exception = $_.Exception.ToString().Split(".")[2]
            Write-Host "Message failed to send at Chat ID : $ID ($exception)" -ForegroundColor Red

Now use the function we created earlier to send the message yourself. You can send message to multiple target at once.

Send-TeleMessage -BotKey "Your Bot API Key" -ChatIDs "CHAT-ID-01","CHAT-IS-02" -Message "Testing Tele"

This is how the messages will look like.

How this PS function help you?

  • This is just a sample function to let you know how telegram works with Bot.
  • You can use this to send notification of a critical service.
  • You can use this to send notification of a critical server outage.
  • You can use this function to any of the existing scripts those are already sending traditional notifications.
  • You also will be able send notification to a Telegram groups as well.
  • Technically there is no limitation.
  • Feel free to use this PowerShell function in your script.
  • Sharing some more ideas in the comments bellow.

Thanks for Reading, happy Scripting!!

]]> 6 3046
How to use AWS PowerShell cmdlets with Filter Thu, 23 Mar 2017 08:09:07 +0000 Continue reading ]]> I personally can’t imagine supporting a big infrastructure without introducing automation and to automate something you have to use command line. If you are more into Windows and started working on AWS for your clients, then I assume that you would love to start managing AWS using AWS PowerShell Module like I do. AWS Console is really good and informative but when it comes to bulk activity I am always depending on PowerShell.

There is a very good documentation created by Amazon for AWS PowerShell, you will get the basic help for all the available PowerShell cmdlet from here. It will be very much helpful for you to start working on AWS PowerShell, but unfortunately when it comes to using filter available for those cmdlet, you won’t be able to find any good example. Using filter on a AWS cmdlet will be a smart move and it also reduce the total execution time. Initially I also struggled to get this working due to lack of examples, but later I figured it out, and now I always try to utilize filter and I am writing this to you help you understand how easily we could use this.

Some of the sample, hope this will help you.

Extract the list of the snapshots under your ownership.

$Filter.Name = "owner-id"
$Filter.Value = "XXXXXXXXXXXX"
Get-EC2Snapshot -Filter $Filter -Region AWS-REGION

This script, I am using filter to identify the snapshots mapping with instance

$GetAllRegions = (Get-AWSRegion).Region
#or Specific Region
#$GetAllRegions = "us-east-1","us-west-2","ap-southeast-2"
$GetAllRegions | % {
    $getSnaps = $null
    $RG = $_
    $SFilter = new-object Amazon.EC2.Model.Filter
    $SFilter.Name = "owner-id"
    $SFilter.Value = "XXXXXXXXXXXX "    
    $getSnaps = Get-EC2Snapshot -Filter $SFilter -Region $RG
    foreach ($getSnap in $getSnaps){  
        $IFilter = new-object Amazon.EC2.Model.Filter
        $IFilter.Name = "block-device-mapping.volume-id"
        $IFilter.Value = "$($getSnap.VolumeId)"
        $getInstanceID = (Get-EC2Instance -Filter $IFilter -Region $RG).Instances.InstanceID        
        if ($getInstanceID){
            $getSnap | Add-Member @{LinkedInstanceID=$getInstanceID}
            $getSnap | Add-Member @{LinkedInstanceID="Missing"}
        $getSnap | select Description, SnapshotID, VolumeID, LinkedInstanceID
        $GetAllSnapshots += $getSnap
$GetAllSnapshots | select Description, SnapshotID, VolumeID, VolumeSize, LinkedInstanceID | Export-Csv $env:USERPROFILE\Desktop\SnapR.csv -NoTypeInformation

Use multiple filter to extract attached root volumes

$Filter0 = New-Object Amazon.EC2.Model.Filter
$Filter0.Name = 'attachment.status'
$Filter0.Value = 'attached'
$Filter1 = New-Object Amazon.EC2.Model.Filter
$Filter1.Name = 'attachment.device'
$Filter1.Value = '/dev/sda1'
Get-EC2Volume -Filter $Filter0, $Filter1 -Region AWS-REGION

Extracting instances details from name. [ Use: GetInstanceFromName NAME-OF-THE-INSTANCE ]

function GetInstanceFromName([string] $fInstanceName,[string] $fRegion)
        $fFilter = new-object Amazon.EC2.Model.Filter
        $fFilter.Name = "tag:Name"
        $fFilter.Value = "$fInstanceName"
        if ($fRegion){ $fCmdOutput = Get-EC2Instance -Filter $fFilter -Region $fRegion }
        if (!$fRegion){ $fCmdOutput = Get-EC2Instance -Filter $fFilter }
            return $fCmdOutput
            return Write-Host "Please make sure you are using correct name in and correct case" -ForegroundColor Yellow

You can use filter in almost every cmdlet, and to get all the available options for filter, use this.

Help cmdlet -Parameter filter

Help Get-EC2Snapshot -Parameter filter

I hope this will help you as well to boost up your AWS Administration tasks via PowerShell.

]]> 0 2997
Migrated this blog to Amazon LightSail from GoDaddy Mon, 20 Feb 2017 02:56:50 +0000 Continue reading ]]>
Finally, I managed to migrate my blog from GoDaddy to Amazon Lightsail, and everything looks good so far. Thanks to Amazon Lightsail for providing a static public IP (

It’s really simple to migrate your blogs from any other hosting Amazon Lightsail, details information can be found here.

They have very attractive pricing, which is one of the reason I moved from GoDaddy to Amazon (recently GoDaddy started charging additional TAX). I am currently using $5 plan which is also free for first month.

Amazon Lightsail not using AWS Console, it’s very user friendly and less complex for beginners.

They also have very powerful monitoring system in place.

Happy Browsing.

**In case if you have any query or need any help for migrating your blog to Amazon Lightsail, please post your queries here, I will try my best to help you. J

]]> 0 2952
Cleanup disabled users from AD Group/s Tue, 03 Jan 2017 07:38:20 +0000 Continue reading ]]> Cleanup disabled accounts from groups is one of the most boring job, and also take lots of time. Manually it’s almost impossible to maintain. Recently I had a request to perform such task for many groups, so, I wrote a script to do it automatically on behalf of me. I am now sharing this script, hoping this might help you as well.

This script will do following task automatically.

  • Get the members of a group.
  • Identify only users.
  • Identify disabled users.
  • Check every disabled users group memberships.
  • Remove the disabled users from that group.
  • Generate a report with status (success / failure).
  • Keep the report on your desktop.

$GroupSamName = "You-AD-Group-Name"
foreach ($member in (Get-ADObject -Filter {(SamAccountName -eq $GroupSamName)} -Properties *).Member)
    $DServer = $null
    $DServer=$(($member.Split(",") | Select-String DC= | % {$_.ToString()}).Replace("DC=","") -join ".")
    if ($(Get-ADObject -Filter {(DistinguishedName -eq $member)} -Server $DServer | ? {$_.ObjectClass -ne "group" -AND $_.ObjectClass -ne "computer"}).DistinguishedName){$GetADUser = Get-ADUser $member -Properties Enabled -Server $DServer}
    if (($GetADUser).Enabled -eq $false) {
        $GetUserGroups = (Get-ADObject -Filter {(DistinguishedName -eq $member)} -Properties Memberof).Memberof
        foreach($Group in $GetUserGroups)
                Remove-ADGroupMember -Identity $Group -Members $GetADUser -Server $(($Group.Split(",") | Select-String DC= |% {$_.ToString()}).Replace("DC=","") -join ".") -Confirm:$false
                $MyObject = New-Object PSObject -Property @{ 
                RemovalStatus = "Removed"
                $ErrorReport += $MyObject
                $MyObject = New-Object PSObject -Property @{ 
                RemovalStatus = "$($_.Exception.ToString().Split("-")[0].Split(":")[1].Trim())"
                $ErrorReport += $MyObject
$ErrorReport | Export-Csv -NoTypeInformation $env:USERPROFILE\Desktop\Report.csv

]]> 0 2928 Re-enabling Network Adapter in Azure VM (Resource Manager) Mon, 02 Jan 2017 03:56:29 +0000 Continue reading ]]> It is very common that sometimes we disabled the network adapter from VM to trouble shoot some network related issue, and after doing so we suddenly realize that we made a big mistake, especially if we do it on Azure VMs. Suddenly we lost all the communication to the VM, no RDP, no PowerShell, and VM got completely isolated from the network. If AWS, we could fix this very easily by adding one additional network adapter (ENI), but in Azure, it will be little bit tricky, coz currently Azure VM does NOT support adding or removing NICs after a VM is created, Multi-NIC can only be applied when a VM is created. So, fixing this will be bit trickier for Azure VMs. If you search “Disabled network card on Azure VM“, you will get multiple solution, but unfortunately those are not working with newer Azure VM (Resource Manager).

To fix this issue, you have to follow the steps bellow, and you will be able to re-enable the adapter.

  • Select VM from
  • Select Network interfaces
  • Select IP configurations
  • Change the Static IP to Dynamic and Save the settings
  • Wait till configuration gets updated.
  • Now again change it from Dynamic to Static and also change the IP Address to a new one for the same VNET and Save.
  • This will reboot the instance and after some time you will get the ping response from the new IP.
  • Now you have to follow the exact same steps to change the IP back to old one.
  • And finally you will able to get the VM with old IP.
  • If you wish, buy me a cup of coffee.

]]> 17 2917
Multi-Thread Super-Fast Software Inventory Scan using WSMan (PowerShell Remoting) Mon, 18 Jul 2016 05:04:23 +0000 Continue reading ]]> Recently I was asked to pull the software inventory report from multiple severs hosted in Azure, but unfortunately pulling data from WMI not allowed, only PS Remoting was enabled, so I made some changes on my previous script and used Invoke-command to pull the date for all the servers. It was easy and the most effective way to extract that report and only took 5 minute to get the data. 🙂

Here is the modified script, I hope you might find this useful

$Credential = Get-Credential
$ExportFileLocation = "$env:userprofile\desktop\InvTory.csv"  
$Servers = Get-Content "$env:userprofile\desktop\servers.txt"
Get-Job "Inv*" | Stop-Job  
Get-Job "Inv*" | Remove-Job  
$MAXJOB = "20"  
foreach ($Server in $Servers)  
    Write-Progress -Activity "Creating job for Inventory Report.." -Status $Server -PercentComplete (100*$i/($Servers.count))  
    Invoke-command -Credential $Credential -AsJob -JobName "Inv.$Server" -ComputerName $Server -ScriptBlock {#SB-Start  
        $GetInvs = gwmi win32_product 
        $LocalReport = @()  
        foreach ($GetInv in $GetInvs) {  
            $CName = $args[0] 
            $PName = $GetInv | % {$_.Name} 
            $Version = $GetInv | % {$_.Version}  
            $MyObject = New-Object PSObject -Property @{ 
            $LocalReport += $MyObject  
        return $LocalReport  
    } -ArgumentList $Server | Out-Null  
    $getRunningJobsCount = (Get-Job "Inv*" | ? {$_.State -eq "Running"}).count  
    while ($getRunningJobsCount -gt $MAXJOB)  
        Write-Progress -Activity "Reached maximum number of threads ($($MAXJOB))..." -Status "Wait till it gets reduced.." -PercentComplete (100*$i/($Servers.count))  
        Start-Sleep 10  
        $getRunningJobsCount = (Get-Job "Inv*" | ? {$_.State -eq "Running"}).count  
$JobStatus = "Please wait"  
While (Get-Job "Inv*" | ? {$_.State -eq "Running"}) {  
    $CurrentRunningJobs = (Get-Job "Inv*" | ? {$_.State -eq "Running"}).count  
    Write-Progress -Activity "Jobs are running, please wait." -Status "$($CurrentRunningJobs) jobs running" -PercentComplete (100*($i-$CurrentRunningJobs)/$i)  
    #Get-Job | Get-Member  
    $c ="."  
    $JobStatus = "$JobStatus $c"  
    Start-Sleep 1   
foreach ($Job in (Get-Job | ? { $_.Name -like "Inv*"})) {  
    $JobResult = $null  
    $JobResult = Receive-Job $Job  
    $Result +=$JobResult  
    Remove-Job $Job  
$Result = $Result | select ServerName, AppName, Version  
$Result | Export-Csv $ExportFileLocation -NoTypeInformation

Please do let me know in case of any query, happy scripting 🙂

]]> 1 2885
AWS Region now in India – AWS Asia Pacific (Mumbai) Region Sun, 10 Jul 2016 14:45:28 +0000 Continue reading ]]> AWS expanding their footprint again, this time with a new region in Mumbai, India. AWS customers in the area can use the new Asia Pacific (Mumbai) Region to better serve end users in India.

New Region
The new Mumbai region has two Availability Zones, raising the global total to 35. It supports Amazon Elastic Compute Cloud (EC2) (C4, M4, T2, D2, I2, and R3 instances are available) and related services including Amazon Elastic Block Store (EBS), Amazon Virtual Private Cloud, Auto Scaling, and  Elastic Load Balancing.

It also supports the following services:

  • AWS Certificate Manager (ACM)
  • AWS CloudFormation
  • Amazon CloudFront
  • AWS CloudTrail
  • Amazon CloudWatch
  • AWS CodeDeploy
  • AWS Config
  • AWS Direct Connect
  • Amazon DynamoDB
  • AWS Elastic Beanstalk
  • Amazon ElastiCache
  • Amazon Elasticsearch Service
  • Amazon EMR
  • Amazon Glacier
  • AWS Identity and Access Management (IAM)
  • AWS Import/Export Snowball
  • AWS Key Management Service (KMS)
  • Amazon Kinesis
  • AWS Marketplace
  • AWS OpsWorks
  • Amazon Redshift
  • Amazon Relational Database Service (RDS) – all database engines including Amazon Aurora
  • Amazon Route 53
  • Amazon Simple Notification Service (SNS)
  • Amazon Simple Queue Service (SQS)
  • Amazon Simple Storage Service (S3)
  • Amazon Simple Workflow Service (SWF)
  • AWS Support
  • AWS Trusted Advisor
  • VM Import/Export

There are now three edge locations (Mumbai, Chennai, and New Delhi) in India. The locations support Amazon Route 53, Amazon CloudFront, and S3 Transfer Acceleration. AWS Direct Connect support is available via our Direct Connect Partners (listed below).

This is our thirteenth region (see the AWS Global Infrastructure map for more information). As usual, you can see the list of regions in the region menu of the Console:

To read more, visit following source link.

]]> 0 2872
New Feature : EC2 Instance Console Screenshot for Boot Troubleshooting Fri, 27 May 2016 18:09:29 +0000 Continue reading ]]> Finally a great feature add to AWS EC2 instances (HVM virtualization only), which was requested by almost everyone. Now we can take a console screenshot of any EC2 Instances. This is now available publicly. Earlier we had to log a case with AWS Support to get the AWS Console screenshot. This is a similar feature like Boot Diagnostics for Azure Virtual Machines v2.

This new feature will be very much helpful for every AWS Administrators, especially for those who providing support to Windows instances.

In past I had few experience of EC2 Instance getting stuck during boot and we had to request for the console screenshot from AWS Support for troubleshooting. This process was time lengthy during crisis situation. I guess this feature will be welcomed by everyone.

Here is how you generate a screenshot from the AWS console.

Screenshot of Linux Instance.

Screenshot of Windows Instance.

This feature availability:
This feature is available in the US East (Northern Virginia), US West (Oregon), US West (Northern California), Europe (Ireland), Europe (Frankfurt), Asia Pacific (Tokyo), Asia Pacific (Seoul), Asia Pacific (Singapore), Asia Pacific (Sydney), and South America (Brazil) Regions.

To Grant Permission for accessing Console Screenshot use this:

    "Version": "2012-10-17",
    "Statement": [
            "Action": [
            "Effect": "Allow",
            "Resource": "*"

Note: Screenshots are taken from

]]> 0 2805