none
Get external Users using powershell RRS feed

  • Question

  • Hi All,

    I have a task, that I need to get external users based on DistinguishedName?

    Using PowerShell for SharePoint 2016.


    Abenet

    Friday, September 13, 2019 3:37 PM

Answers

  • Internal users will have a loginname like

    • Beverly.Johnson@contoso.com

    appearing in the Get-SPOUser list, while external users will have something like

    • John.Smith_gmail.com#ext#@contoso.onmicrosoft.com

    Therefore, use standard filtering method.  In the SharePoint Online Management Shell, use something like:

    • Get-SPOUser -Site $site -Limit "All" | ?{$_.LoginName -eq "*contoso.onmicrosoft.com" | select DisplayName,LoginName,IsSiteAdmin,IsGroup,@{n="Groups";e={$_.Groups -join ";"}}  | Export-Csv -nti -path "users"

    References

    • Edited by Stephan Bren Saturday, September 14, 2019 1:36 PM
    • Marked as answer by NewET12345 Monday, September 16, 2019 2:42 PM
    Saturday, September 14, 2019 1:34 PM
  • Hi NewET12345,

    Has the problem been solved?

    According to my research, this is the command used to return the external user: Get-SPOExternalUser.

    But it can't specify the parameters of DistinguishedName.

    This parameter(DistinguishedName) seems to be specified only in Get-ADUser.

    Get-ADUser -Filter * -Properties givenName, sn, displayName, sAMAccountName, mail, proxyAddresses, distinguishedName | ft givenName, sn, displayName, sAMAccountName, mail, proxyAddresses, distinguishedName > .\AllUsers.txt

    I'm not very familiar with the power shell command, I didn't find the power shell command that can be used directly.

    Looking forward to your update on this issue.

    Best regards

    Itch Sun


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by NewET12345 Monday, September 16, 2019 2:42 PM
    Monday, September 16, 2019 8:18 AM
  • The SPO cmd is for SP Online, mine is on Prem-2016

    Here is what I did:

        $WebApp = Get-SPWebApplication $WebAppUr

       $Sites = Get-SPSite -Limit All -WebApplication $WebApp

        foreach($Site in $Sites)     {        $AllUsers = $Site.RootWeb.SiteUsers

    //get all the users with displayName

    if( $displayName =="*Contractor*" -or $DisplayName -like "*Client*")

    {

    write-hose $displayName -ForeGroundColor Yellow

    }



    Abenet

    • Marked as answer by NewET12345 Monday, September 16, 2019 2:42 PM
    Monday, September 16, 2019 2:42 PM

All replies

  • Internal users will have a loginname like

    • Beverly.Johnson@contoso.com

    appearing in the Get-SPOUser list, while external users will have something like

    • John.Smith_gmail.com#ext#@contoso.onmicrosoft.com

    Therefore, use standard filtering method.  In the SharePoint Online Management Shell, use something like:

    Get-SPOUser -Site $site -Limit "All" | ?{$_.LoginName -eq "*contoso.onmicrosoft.com" | select DisplayName,LoginName,IsSiteAdmin,IsGroup,@{n="Groups";e={$_.Groups -join ";"}}  | Export-Csv -nti -path "users"

    Saturday, September 14, 2019 1:34 PM
  • Internal users will have a loginname like

    • Beverly.Johnson@contoso.com

    appearing in the Get-SPOUser list, while external users will have something like

    • John.Smith_gmail.com#ext#@contoso.onmicrosoft.com

    Therefore, use standard filtering method.  In the SharePoint Online Management Shell, use something like:

    • Get-SPOUser -Site $site -Limit "All" | ?{$_.LoginName -eq "*contoso.onmicrosoft.com" | select DisplayName,LoginName,IsSiteAdmin,IsGroup,@{n="Groups";e={$_.Groups -join ";"}}  | Export-Csv -nti -path "users"

    References

    • Edited by Stephan Bren Saturday, September 14, 2019 1:36 PM
    • Marked as answer by NewET12345 Monday, September 16, 2019 2:42 PM
    Saturday, September 14, 2019 1:34 PM
  • Hi NewET12345,

    Has the problem been solved?

    According to my research, this is the command used to return the external user: Get-SPOExternalUser.

    But it can't specify the parameters of DistinguishedName.

    This parameter(DistinguishedName) seems to be specified only in Get-ADUser.

    Get-ADUser -Filter * -Properties givenName, sn, displayName, sAMAccountName, mail, proxyAddresses, distinguishedName | ft givenName, sn, displayName, sAMAccountName, mail, proxyAddresses, distinguishedName > .\AllUsers.txt

    I'm not very familiar with the power shell command, I didn't find the power shell command that can be used directly.

    Looking forward to your update on this issue.

    Best regards

    Itch Sun


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by NewET12345 Monday, September 16, 2019 2:42 PM
    Monday, September 16, 2019 8:18 AM
  • The SPO cmd is for SP Online, mine is on Prem-2016

    Here is what I did:

        $WebApp = Get-SPWebApplication $WebAppUr

       $Sites = Get-SPSite -Limit All -WebApplication $WebApp

        foreach($Site in $Sites)     {        $AllUsers = $Site.RootWeb.SiteUsers

    //get all the users with displayName

    if( $displayName =="*Contractor*" -or $DisplayName -like "*Client*")

    {

    write-hose $displayName -ForeGroundColor Yellow

    }



    Abenet

    • Marked as answer by NewET12345 Monday, September 16, 2019 2:42 PM
    Monday, September 16, 2019 2:42 PM
  • You are quite correct. When you indicated "external user" I immediately thought you might be actually working with Online and not onprem and just miscategorized it.

    For onprem, you would use Get-SPUser and use pretty much the same format, using filtering to only get that subset of interest:

    Get-SPUser -Identity "https://www.contoso.com/ -Limit "All" | ?{$_.LoginName -eq "*[etc]"} | Export-CSV -nti path "users.csv"
    Monday, September 16, 2019 11:01 PM
  • Thanks for the help

    Abenet

    Tuesday, September 17, 2019 3:18 PM