Repository navigation
Replies: 2 comments
|
The warning shown is generated by your There is also a separate return-value issue in the calculation: the currently documented This version checks the CSV header, reports the original exception message, and skips blank usernames or a missing quota result: [CmdletBinding()]
param(
[string]$CsvPath = 'C:\Temp\lista1.csv',
[string]$OutputPath = 'onedrive_cuotas.csv'
)
$usuarios = @(Import-Csv -LiteralPath $CsvPath -ErrorAction Stop)
if ($usuarios.Count -eq 0 -or 'username' -notin $usuarios[0].PSObject.Properties.Name) {
throw 'The CSV must contain at least one data row and a username header.'
}
$resultados = @(foreach ($usuario in $usuarios) {
$account = ([string]$usuario.username).Trim()
if ([string]::IsNullOrWhiteSpace($account)) {
Write-Warning 'Skipping a row with an empty username.'
continue
}
try {
$quotaBytes = Get-PnPUserOneDriveQuota -Account $account -ErrorAction Stop
if ($null -eq $quotaBytes) {
Write-Warning ('No quota was returned for {0}.' -f $account)
continue
}
[PSCustomObject]@{
userEmail = $account
cuotaMB = [double]$quotaBytes / 1MB
}
}
catch {
Write-Warning ('{0}: {1}' -f $account, $_.Exception.Message)
}
})
$resultados | Export-Csv -LiteralPath $OutputPath -NoTypeInformation -Encoding utf8For example, a returned value of I checked the CSV, conversion and error-handling paths locally on PowerShell 7.6.6 with a mocked PnP command: one successful row, one simulated error, a missing quota, an empty username, and a missing
|
|
Hi! 👋 The warning in your Try changing your catch block to this: } catch {
Write-Warning "Failed for $($usuario.username): $($_.Exception.Message)"
Write-Host $_
}This should help reveal the real error from Hope this helps! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This is my code, to get quotas of onedrive.
but i got this error msg
_WARNING: Error al obtener la cuota para @{IsReadOnly=False; IsFixedSize=False; IsSynchronized=False; Keys=System.Collections.Hashtable+KeyCollection; Values=System.Collections.Hashtable+ValueCollection; SyncRoot=System.Object; Count=2}
WARNING: Error al obtener la cuota para @{IsReadOnly=False; IsFixedSize=False; IsSynchronized=False; Keys=System.Collections.Hashtable+KeyCollection; Values=System.Collections.Hashtable+ValueCollection; SyncRoot=System.Object; Count=2}
Cuotas de OneDrive exportadas a onedrive_cuotas.csv_
Could anyone help me please?
All reactions