CSV Export - Add GB to export

Hi Team

So i have been working on this script and hit a bit of a snag

The script connects in to Sharepoint and grabs me all the OneDrive sites for me. It grabs the OneDrive size and converts it GB for me. I then export the results out to a CSV file. This all works fine and no issues.

In the CSV export i see these two columns

“Owner” = $.Owner
“Storage Quota (Gb)” = ConvertTo-Gb -size $
.StorageQuota

The owner has whos OneDrive it is and the StorageQuota then adds for example 2 for 2GB

I am trying to get the value in the StoageQuota to read 2GB rather then just a 2

The script

##############################################################
param
(
$AzureLocation = (Read-Host -Prompt ‘Enter Azure Site’)
)
##############################################################

switch ($AzureLocation) {
‘SERVER1’ { $SPURL = ‘https://domain-name-admin.sharepoint.com’ }
default { $SPURL = “https://domain-name$AzureLocation-admin.sharepoint.com”}
}

#Share Point Connection Properties
$CxParams = @{
URL = $SPURL
ClientID = “something-here”
Tenant = “domain-name.onmicrosoft.com
Thumbprint = “something-here”
}

#Connect to SharePoint Online
Connect-PnPOnline @CxParams

Function ConvertTo-Gb {

param(
[Parameter(
Mandatory = $true
)]
[string]$size
)
process {
if ($size -ne $null) {
$sizeInGb = ($size / 1024)

  return [Math]::Round($sizeInGb,2,[MidPointRounding]::AwayFromZero)
}

}
}

Function Get-OneDriveStats {

process {
$oneDrives = Get-PnPTenantSite -IncludeOneDriveSites -Filter “Url -like ‘-my.sharepoint.com/personal/’” -Detailed | Select Title,Owner,StorageQuota,StorageQuotaWarningLevel,StorageUsageCurrent,LastContentModifiedDate,Status
$i = 0

$oneDrives | ForEach {

  [pscustomobject]@{
    #"Display Name" = $_.Title
    "Owner" = $_.Owner
    #"Onedrive Size (Gb)" = ConvertTo-Gb -size $_.StorageUsageCurrent
    #"Storage Warning Quota (Gb)" = ConvertTo-Gb -size $_.StorageQuotaWarningLevel
    "Storage Quota (Gb)" = ConvertTo-Gb -size $_.StorageQuota
    #"Last Used Date" = $_.LastContentModifiedDate
    #"Status" = $_.Status
  }

  $currentUser = $_.Title
  Write-Progress -Activity "Collecting OneDrive Sizes" -Status "Current Count: $i" -PercentComplete (($i / $oneDrives.Count) * 100) -CurrentOperation "Processing OneDrive: $currentUser"
  $i++;
  
}

}
}

Get-OneDriveStats | Export-CSV -Path ‘C:\Export.csv’ -NoTypeInformation

Something like this

"Storage Quota (Gb)" = $("{0}GB" -f $(ConvertTo-Gb -size $_.StorageQuota))