Wednesday, 9 February 2022

Azure Windows VM Disk Usage report for All VM in a Azure Tenant

I was setting up monitoring for my Azure environment and I had an requirement to email the VM Disk usage of all windows VM's in a tenant to Support team on daily Basis and also sent notification in Slack. I used PowerShell to consolidate the data and Logic apps for the integration for Slack notification.


To breakdown the script for better understanding, I have used a credential from credential manager which had RBAC permissions to all subscriptions in the tenant and I used the function in  https://gallery.technet.microsoft.com/scriptcenter/Accessing-Windows-7210ae91 for my Azure and SFTP authentication using the credentials already in credential manager. I am using Invoke-AzVMRunCommand which basically runs a PowerShell script file on the remote server. The below PowerShell script will run C:\temp\GetDisk.ps1 on all the remote servers I am passing. 

GetDisk.ps1 runs the below PowerShell commandlet 

"Get-Volume|where {$_.FileSystemLabel -ne 'System Reserved' -and $_.FileSystem -eq 'NTFS'}|SELECT DriveLetter,Size,SizeRemaining|ConvertTo-Json"

Invoke-AzVMRunCommand Will return only as single string irrespective of output format so I have converted into json so I can easily convert to PSObject for processing in my main script.


The script will consolidate result in HTML format and Json format. Json format will be sent as Payload to Webhooks to Logic Apps were you can integrate with Slack or Teams alerts. HTML format will be styled with yellow rows for 10 to 15% free space and Red Rows for usage less than 10% free space as below.

VM Disk Usage

VMName

SubscriptionName

RGName

DriveLetter

Size(GB)

SizeRemaining(GB)

UsedSpace(GB)

FreeSpacePercentage

Server1

Sub-1

RG-1

C

512

223

289

43.49978

Server1

Sub-1

RG-1

D

32

30

2

92.29322

Server1

Sub-1

RG-1

F

2048

381

1667

18.60302

Server2

Sub-2

RG-2

C

127

19

108

14.84652

Server2

Sub-2

RG-2

F

512

27

485

5.293138

 

Copyright © 2022 Vinoth N Manoharan.The information provided in this post is provided "as is" with no implied warranties or guarantees.

3 comments:

  1. How To Access Slots By Phone - DRMCD
    The free games, the 충주 출장샵 app and the 속초 출장안마 security are all there For 시흥 출장안마 example, 김천 출장마사지 in the 포커 고수 slot machine gambling apps that use the free casino app, the

    ReplyDelete
  2. I've been so busy with my writing projects for the past few days that I've stopped using PowerShell to consolidate data and logic apps for slack notification integration. But for the last couple of days, I have been using Masters Dissertation Writing Services which has turned my attention towards the Azure environment.

    ReplyDelete
  3. จุดเด่นของ เกมสล็อตทดลองเล่นอย่าง ลึกซึ้ง ทำให้เกมของเรา มีคุณภาพทั้งเรื่อง กราฟิกสีสันของเกม ซึ่งทาง BETFLIX เสนอและสอนวิธีเล่น

    ReplyDelete