Powershell – Office 365 Powershell – Export user to csv file

exchangeonlinemicrosoft-office-365powershell

I took this script from that post : Office 365 Powershell
but when I run it, I receive that error :

WARNING: More results are available. Please specify one of the All or
MaxResults parameters.

Where do I need to add the maxresults parameters in order to make the export possible?

$lines = @()
foreach($msolUser in (Get-MSOLUser -ALL | where {$_.isLicensed -eq $true}))
{
    $UserInfo = Get-User -identity $msolUser.UserPrincipalName
    foreach($license in $msolUser.Licenses)
    {
        $lines += New-Object PsObject -Property @{
                    "Nom/Prenom"="$($UserInfo.DisplayName)";
                    "Societe"="$($UserInfo.Company)";
                    "AdressePrincipale"="$($UserInfo.UserPrincipalName)";
                    "Licences"="$($license.AccountSKUid)"
                  }
    }
}
$lines | Export-CSV C:\out1.csv -Delimiter ";" -Encoding Unicode

Best Answer

By default commands like Get-User and Get-MSOLUser only give you the first 200 objects. you have -ALL next to the Get-MSOLUser command but not next to the GET-USER cmdlet. try using Get-USER -ALL

Hope This Works,

Mike