Get all the External users using Get-SPOExternalUser cmdlet
The below script list the external users from first page. You have to specify your SharePoint Online Admin Center url and Office 365 Admin Credentials to run the following commands.
#Connection to SharePoint Online
$SPOAdminSiteUrl="https://<YourDomain>-admin.sharepoint.com/"
$365Logon = Get-Credential
Connect-SPOService -Url $SPOAdminSiteUrl -Credential $365Logon
Get-SPOExternalUser -Position 0 -PageSize 50 | Select DisplayName,Email | FT
If you want to retrieve users from second page, you have to set the position as 1. The below command returns first 10 external users from the second page of the collection.
Get-SPOExternalUser -Position 1 -PageSize 10
You can also specify the parameter SiteUrl to retrieve external users only for a specific site.
Get-SPOExternalUser -Position 0 -PageSize 50 -SiteUrl <YourSiteUrl>
Fetch all the Office 365 External (Guest) users using Get-MsolUser cmdlet
The above command
Get-SPOExternalUser will be very helpful if you have minimum number of external users. But it will be difficult if you have 100s of users as you have to fetch users page by page. So to overcome this problem, we can use the Azure AD Powershell cmdlet
Get-MsolUser.
#Connection to Azure AD Module
Import-Module MSOnline
$365Logon = Get-Credential
Connect-MsolService –Credential $365Logon
Get-MsolUser -All | ? {$_.UserType -eq "Guest"} | Select DisplayName,SignInName | FT
The above command returns all the Office 365 external users (guest users).
You can also apply more where filter to get users from specific domain. The below command returns users only from the domain
TestDomain.com.
Get-MsolUser -All | ? {$_.UserType -eq "Guest"} | ? {$_.SignInName -like "*TestDomain.com"}
Export all the External user details to CSV file
You can easily export the external user details to csv file by using the cmdlet
Export-Csv.
Get-MsolUser -All | ? {$_.UserType -eq "Guest"} | Select DisplayName,SignInName |
Export-CSV "C:\\External-Users.csv" -NoTypeInformation -Encoding UTF8
No comments:
Post a Comment