Home > Software engineering >  How can i convert the property MaxsizeBytes for an Azure database to GB?
How can i convert the property MaxsizeBytes for an Azure database to GB?

Time:12-01

I get a database using Powershell like this:

   $dbs= (Get-AzSqlDatabase -ResourceGroupName <rg> -ServerName  <server>
   foreach ($db in $dbs)
   {       
       "Size "  ($db.MaxSizeBytes /1024)Mb        
   }

That gives the size of the db in MB , how can i get the size in GB , unless im taking the wrong property ?

CodePudding user response:

Using the normal size math options. kb/mb/gb, applies to any file/filesystem object.

$filename = '.\EventLogs.csv'    

# Get file size in bytes
(Get-Item -Path $filename).Length

# get file size in KB in PowerShell
(Get-Item -Path $filename).Length/1KB

# get file size in MB in PowerShell   
(Get-Item -Path $filename).Length/1MB

# get file size in GB in PowerShell
(Get-Item -Path $filename).Length/1GB 

In PowerShell, we can convert from bytes to KB, MB, GB, TB, and PB using the multipliers. For example,

$size = 123456789
$size / 1KB
$size / 1MB
$size / 1GB
$size / 1TB
$size / 1PB
  • Related