<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Taskal Samal on Medium]]></title>
        <description><![CDATA[Stories by Taskal Samal on Medium]]></description>
        <link>https://medium.com/@taskal-samal?source=rss-37ad74083dcf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XoWLgn5nc3Wey2EHbTKaDg.png</url>
            <title>Stories by Taskal Samal on Medium</title>
            <link>https://medium.com/@taskal-samal?source=rss-37ad74083dcf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:12:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taskal-samal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Get Azure Virtual Machine Inventory along last X days of CPU, Memory & Cost Data using Azure…]]></title>
            <link>https://taskal-samal.medium.com/get-azure-virtual-machine-inventory-along-last-x-days-of-cpu-memory-cost-data-using-azure-677ea586bc2b?source=rss-37ad74083dcf------2</link>
            <guid isPermaLink="false">https://medium.com/p/677ea586bc2b</guid>
            <category><![CDATA[azure-automation]]></category>
            <dc:creator><![CDATA[Taskal Samal]]></dc:creator>
            <pubDate>Tue, 23 Nov 2021 01:29:02 GMT</pubDate>
            <atom:updated>2021-11-23T01:29:02.178Z</atom:updated>
            <content:encoded><![CDATA[<h3>Get Azure Virtual Machine Inventory along last X days of CPU, Memory &amp; Cost Data using Azure PowerShell</h3><p>$azureServicePrincipalId= “”</p><p>$azureServicePrincipalSecret=””</p><p>$tenandId=””</p><p>$dataForLastXDays = “”</p><p>$azureServicePrincipalSecretSecureString=ConvertTo-SecureString $azureServicePrincipalSecret -AsPlainText -Force -Verbose</p><p>$azureCredentail= New-Object System.Management.Automation.PSCredential ($azureServicePrincipalId, $azureServicePrincipalSecretSecureString)</p><p>Connect-AzAccount -ServicePrincipal -Tenant $tenandId -Credential $azureCredentail -verbose</p><p>$subscriptionList = Get-AzSubscription -TenantId $tenantid</p><p>“ResourceName, ResourceGroupName, location, PricingTier, ResourceCost , UsageMonth, ApplicationName, EnvironmentName, subscriptionName,DiskType,OsType,NumberOfCores,MemoryInMB,AverageCpuUtilization,AverageMemoryUtilization,ResourceId” | Out-File -FilePath “$env:HOMEPATH\Documents\AzureVirtualMachineCost.csv” -Append -Encoding utf8</p><p>foreach ($subscription in $subscriptionList) {</p><p>$SelectSubscription = Select-AzSubscription -Subscription $subscription</p><p>$subscriptionName = $SelectSubscription.Subscription.Name</p><p>$azureVirtualMachineList = Get-AzVM | Select-Object Name, ResourceGroupName, Location, id, @{“Name” = “Size”; Expression = { $_.HardwareProfile.VmSize } }, @{“Name” = “DiskType”; Expression = { $_.storageProfile.osDisk.managedDisk.storageAccountType } },@{“Name” = “OSType”; Expression = { $_.storageProfile.osDisk.osType } }, @{“Name” = “ApplicationName”; Expression = { $_.Tags.’APPLICATION NAME’ } }, @{“Name” = “EnvironmentName”; Expression = { $_.Tags.’ENVIRONMENT NAME’ } }</p><p>foreach ($azureVirtualMachine in $azureVirtualMachineList) {</p><p>$ResourceName = $azureVirtualMachine.Name</p><p>$ResourceGroupName = $azureVirtualMachine.ResourceGroupName</p><p>$location = $azureVirtualMachine.Location</p><p>$PricingTier = $azureVirtualMachine.Size</p><p>$ApplicationName = $azureVirtualMachine.ApplicationName</p><p>$EnvironmentName = $azureVirtualMachine.EnvironmentName</p><p>$DiskType = $azureVirtualMachine.DiskType</p><p>$OSType = $azureVirtualMachine.OSType</p><p>$ResourceId = $azureVirtualMachine.id</p><p>$GetVMSizeDetails = Get-AzVMSize -VMName $ResourceName -ResourceGroupName $ResourceGroupName | where { $_.Name -eq $PricingTier }</p><p>$NumberOfCores = $GetVMSizeDetails.NumberOfCores</p><p>$MemoryInMB = $GetVMSizeDetails.MemoryInMB</p><p>$days = “$dataForLastXDays”</p><p>$startDate = [datetime]::Today.AddDays($days)</p><p>$endDate = [datetime]::Today</p><p>$cpuUtilization_Average = 0.0</p><p>$cpuUtilization = Get-AzMetric -ResourceId $ResourceId -MetricName “Percentage CPU” -DetailedOutput -StartTime $startDate -EndTime $endDate -TimeGrain 12:00:00 -WarningAction SilentlyContinue</p><p>$cpuUtilization_Average = [System.Math]::Round($(($cpuUtilization.Data.Average | Measure-Object -Average).Average), 2)</p><p>$memoryUtilization_Average = 0.0</p><p>$memoryUtilization = Get-AzMetric -ResourceId $ResourceId -MetricName “Available Memory Bytes” -DetailedOutput -StartTime $startDate -EndTime $endDate -TimeGrain 12:00:00 -WarningAction SilentlyContinue</p><p>$memoryUtilization_Average = [System.Math]::Round($(($MemoryInMB — (($memoryUtilization.Data.Average | Measure-Object -Average).Average / 1MB)) / $MemoryInMB * 100), 2)</p><p>$month = “-1”</p><p>$UsageMonth = [datetime]::Today.AddMonths($month).ToString(‘MMM-yyyy’)</p><p>$CurrentBillPeriod = [datetime]::Today.AddMonths($month).ToString(‘yyyyMM’)</p><p>$ResourceUsage = Get-AzConsumptionUsageDetail -InstanceName $ResourceName -Expand MeterDetails -BillingPeriodName $CurrentBillPeriod</p><p>$ResourceCost = 0</p><p>foreach ($Usage in $ResourceUsage) {</p><p>$ResourceCost += $Usage.PretaxCost</p><p>}</p><p>Write-Host “$ResourceName, $ResourceGroupName, $location, $PricingTier, $ResourceCost , $UsageMonth, $ApplicationName,$EnvironmentName,$subscriptionName,$DiskType,$OSType,$NumberOfCores,$MemoryInMB,$cpuUtilization_Average,$memoryUtilization_Average,$ResourceId” -f Green</p><p>“$ResourceName, $ResourceGroupName, $location, $PricingTier, $ResourceCost , $UsageMonth, $ApplicationName,$EnvironmentName,$subscriptionName,$DiskType,$OSType,$NumberOfCores,$MemoryInMB,$cpuUtilization_Average,$memoryUtilization_Average,$ResourceId” | Out-File -FilePath “$env:HOMEPATH\Documents\AzureVirtualMachineCost.csv” -Append -Encoding utf8</p><p>}</p><p>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=677ea586bc2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get-AzureVMBackupReport]]></title>
            <link>https://taskal-samal.medium.com/get-azurevmbackupreport-3fab9af4cbdc?source=rss-37ad74083dcf------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fab9af4cbdc</guid>
            <category><![CDATA[recovery-service-vault]]></category>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[azure-backup]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Taskal Samal]]></dc:creator>
            <pubDate>Wed, 02 Dec 2020 04:45:12 GMT</pubDate>
            <atom:updated>2020-12-13T10:53:24.406Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>Azure Backup Report for both Snapshot &amp; FilesFolder Backup Type from Azure Recovery Services Vault.</em></h3><blockquote><strong>Challenges</strong></blockquote><p>Unable to retrive FilesFolder Backup Job Reports from AzurePowerShell.</p><blockquote><strong>Mitigation</strong></blockquote><p>Used AzurePowerShell &amp; Azure CLI to get Snaphot &amp; FilesFolder Backup Job Reports.</p><blockquote><strong>Purpose</strong></blockquote><p>This is regarding the getting the Azure Backup Report for both Snapshot &amp; FilesFolder Backup Type from Azure Recovery Services Vault and send it to email using SengGrid account for all the subscriptions that you have access to.</p><p>The report will be in excel sheet along with inbuilt Pivot Table.</p><blockquote><strong>Below are the information that the script is retriveing from Azure Recovery Services vault.</strong></blockquote><ol><li>Subscription</li><li>ResouceGroup</li><li>Vault</li><li>JobID</li><li>ServerName</li><li>JobType</li><li>Status</li><li>Task</li><li>BackupSize</li><li>StartTime</li><li>Duration</li><li>ErrorDetails</li><li>Recommendations</li></ol><blockquote><strong>Prerequisites</strong></blockquote><ol><li>Install Azure PowerShell (Install-Module -Name Az -AllowClobber -Scope CurrentUser).</li><li>Install Azure CLI (<a href="https://aka.ms/installazurecliwindows">https://aka.ms/installazurecliwindows</a>).</li><li>Install ImportExcel (Install-Module -Name ImportExcel -RequiredVersion 5.4.0).</li><li>Azure Account.</li><li>SendGrid Account.</li></ol><blockquote><strong>Script :</strong></blockquote><p><strong><em># Recording Script Start Date &amp; Time.</em></strong></p><p>$Script_Start_Time = Get-date</p><p><strong><em># Disable the Suppress Azure PowerShell Breaking Change Warnings<br>Set-Item Env:\SuppressAzurePowerShellBreakingChangeWarnings “true”</em></strong></p><p>Write-Host “VERBOSE: Script Execution Start Date &amp; Time : $Script_Start_Time” -ForegroundColor Cyan</p><p><strong><em># Function to Get Folder using Windows Forms.</em></strong></p><p>unction Get-Folder($Initial_Directory)<br>{<br> [System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”)|Out-Null</p><p>$Folder_Name = New-Object System.Windows.Forms.FolderBrowserDialog<br> $Folder_Name.Description = “Select Output Folder”<br> $Folder_Name.rootfolder = “MyComputer”</p><p>if($Folder_Name.ShowDialog() -eq “OK”)<br> {<br> $Folder += $Folder_Name.SelectedPath<br> }<br> return $Folder<br>}</p><p><strong><em>#Input Section.</em></strong></p><p>[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null</p><p>$To_Email_ID = [Microsoft.VisualBasic.Interaction]::InputBox(“Enter the Email ID on which you wish to get the Azure Backup Report”)<br>$SendGrid_Username = [Microsoft.VisualBasic.Interaction]::InputBox(“Enter the Sendgrid Account Username”)<br>$SendGrid_Password = [Microsoft.VisualBasic.Interaction]::InputBox(“Enter the Sendgrid Account Password”)</p><p>$DateTime = Get-Date -Format ddMMyyyy-HHmm</p><p><strong><em># Final Output Path.</em></strong></p><p>$Output_Folder_Path = Get-Folder<br>$Output_Path_CSV = $Output_Folder_Path + “AzureBackupJobListReport” +”-” + “$DateTime” + “.csv”<br>$Output_Path_XLSX = $Output_Folder_Path + “AzureBackupJobListReport” +”-” + “$DateTime” + “.xlsx”</p><p>Write-Host “VERBOSE: CSV Output File Path : $Output_Path_CSV” -ForegroundColor Cyan<br>Write-Host “VERBOSE: XLSX Output File Path : $Output_Path_XLSX” -ForegroundColor Cyan</p><p><strong><em># Connect to Azure using Azure CLI.</em></strong></p><p>az login</p><p><strong><em># Connect to Azure using Azure PowerShell.</em></strong></p><p>Connect-AzAccount</p><p><strong><em># Getting List of Subscriptions.</em></strong></p><p>$Subscription_List = Get-AzSubscription | Select-Object -ExpandProperty id<br>(Get-AzSubscription).Name</p><p>foreach ($Subscription in $Subscription_List){<br> <br> $x++<br> $Subscription_Name = Get-AzSubscription -SubscriptionId $Subscription | Select-Object -ExpandProperty Name<br> <br> Write-Progress -activity $Subscription_Name -PercentComplete ($x/$Subscription_List.Count*100) -Status $Subscription_Name</p><p>$Current_Subscription_CLI= az account set — subscription $Subscription<br> $Current_Subscription_PS = Select-AzSubscription -Subscription $Subscription<br> <br> Write-Host “VERBOSE: Working on $Subscription_Name Subcription “ -ForegroundColor Cyan</p><p># Getting Vault list from Recovery Services vault.</p><p>$Vault_List = (Get-AzRecoveryServicesVault).Name</p><p>(Get-AzRecoveryServicesVault).Name<br> <br> Foreach ($Vault in $Vault_List){<br> <br><strong><em> # Getting Vault Resource Group Name.</em></strong></p><p>$Vault_ResourecGroup = (Get-AzRecoveryServicesVault -Name $Vault).ResourceGroupName<br> <br> Write-Host “VERBOSE: Working on Vault: $Vault” -ForegroundColor Cyan<br> Write-Host “VERBOSE: Vault ResourceGroup Name: $Vault_ResourecGroup” -ForegroundColor Cyan<br> <br><strong><em> # Setting Vault Context.</em></strong><br> <br> Get-AzRecoveryServicesVault -Name $Vault | Set-AzRecoveryServicesVaultContext</p><p>Write-Progress -activity $Subscription_Name -PercentComplete ($x/$Subscription_List.Count*100) -Status $Vault<br> <br> $obj = @()<br> $results = @()<br> <br> $Backup_JOb_List = az backup job list -g “$Vault_ResourecGroup” -v “$Vault” | ConvertFrom-Json</p><p><strong><em># Get only last day backup report. Use below commands and comment above</em></strong></p><p>$Backup_JOb_List.<br> # $Time_Range = (Get-Date).AddDays(-1).ToString(‘dd-MM-yyyy’)<br> #$Backup_JOb_List = az backup job list -g “$Vault_ResourecGroup” -v “$Vault” — start-time “$Time_Range” | ConvertFrom-Json<br> <br> Foreach ($Backup_Job in $Backup_JOb_List){</p><p>$Backup_Job_ID = $Backup_Job.name <br> $Backup_Job_Detail = az backup job show -n “$Backup_Job_ID” -g “$Vault_ResourecGroup” -v “$Vault” | ConvertFrom-Json<br> $Backup_Job_Task = $Backup_Job_Detail.properties.extendedInfo.tasksList.taskId</p><p>$obj = New-Object -TypeName PSobject<br> $obj | Add-Member -MemberType NoteProperty -Name Subscription -Value $Subscription_Name<br> $obj | Add-Member -MemberType NoteProperty -Name ResouceGroup -Value $Vault_ResourecGroup<br> $obj | Add-Member -MemberType NoteProperty -Name Vault -Value $Vault<br> $obj | Add-Member -MemberType NoteProperty -Name JobID -Value $Backup_Job.name<br> $obj | Add-Member -MemberType NoteProperty -Name ServerName -Value $Backup_Job.properties.entityFriendlyName<br> $obj | Add-Member -MemberType NoteProperty -Name JobType -Value $(if($Backup_Job.properties.jobtype -eq “MabJob”) { ‘File and Folder’ } else{ ‘Snapshot’})<br> $obj | Add-Member -MemberType NoteProperty -Name Status -Value $Backup_Job.properties.status<br> $obj | Add-Member -MemberType NoteProperty -Name Task -Value $(“$Backup_Job_Task”)<br> $obj | Add-Member -MemberType NoteProperty -Name BackupSize -Value $Backup_Job_Detail.properties.extendedInfo.propertyBag.’Backup Size’<br> $obj | Add-Member -MemberType NoteProperty -Name StartTime -Value $Backup_Job.properties.starttime.Split(“.”)[0]<br> $obj | Add-Member -MemberType NoteProperty -Name Duration -Value $Backup_Job.properties.duration.Split(“.”)[0]<br> $obj | Add-Member -MemberType NoteProperty -Name ErrorDetails -Value $(if($Backup_Job.properties.errordetails.errorstring -ne $null){$Backup_Job.properties.errordetails.errorstring.Split(“.”)[1]}else{‘No Error found’})<br> $obj | Add-Member -MemberType NoteProperty -Name Recommendations -Value $(if($Backup_Job.properties.errordetails.recommendations -ne $null){$Backup_Job.properties.errordetails.Recommendations.Split(“.”)[0]}else{‘No Recommendations’})<br> <br> $results +=$obj</p><p>} $results | Export-csv “$Output_Path_CSV” -Append -NoTypeInformation -Verbose<br> }<br>}</p><p><strong><em># Exporting report to Excel.</em></strong></p><p>$Export_To_Excel = Import-csv -Path “$Output_Path_CSV” | Export-Excel “$Output_Path_XLSX” -IncludePivotTable -PivotRows Subscription -PivotColumns Status,Jobtype -PivotData Status -Verbose</p><p><strong><em># Sending Email.</em></strong></p><p>Write-Host “VERBOSE: Sending Email To : $To_Email_ID” -ForegroundColor Cyan</p><p>$From = “<a href="/service/mailto:AzureBackupReport@automation.com">AzureBackupReport@automation.com</a>”<br>Write-Host “VERBOSE: Sending Email From : $From” -ForegroundColor Cyan</p><p>$Attachment = “$Output_Path_XLSX”<br>Write-Host “VERBOSE: Attachment Path : $Attachment” -ForegroundColor Cyan</p><p>$Subject = “Azure Backup Reports on $Script_Start_Time”<br>Write-Host “VERBOSE: Sending Email Subject Name : $Subject”</p><p>$Username =”$SendGrid_Username”<br>$Password = ConvertTo-SecureString “$SendGrid_Password” -AsPlainText -Force<br>$Credential = New-Object System.Management.Automation.PSCredential ($UserName, $Password)<br>$SMTP_Server = “smtp.sendgrid.net”</p><p>$txt1 = “Hello,<br>Please find attached Azure Backup Report executed on $Script_Start_Time.<br>Please check and take appropriate actions accordingly.<br>Thanks!<br>Automation Team. <br>“<br>$Body = $txt1</p><p>Send-MailMessage -From $From -to $To_Email_ID -subject $Subject -Body $Body -SmtpServer $SMTP_Server -Credential $Credential -Usessl -Port 587 -Attachments $Attachment -Verbose</p><p>$Script_End_Time = Get-date</p><p>Write-Host “VERBOSE: Script Execution End Date &amp; Time : $Script_End_Time” -ForegroundColor Cyan</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fab9af4cbdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>