Looking for SharePoint 2016 powershell script to pull User profile information like No users profile, No of User properties , Last sync status etc.
2 Answers
You can use the below PowerShell script:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#variables
$AdminCenterURL = "https://crescenttech-admin.sharepoint.com"
$SiteURL="https://crescenttech.sharepoint.com/"
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Authenticate the web service
$UserProfileService= New-WebServiceProxy -Uri ("$AdminCenterURL/_vti_bin/UserProfileService.asmx?wsdl") -UseDefaultCredential False
$UserProfileService.Credentials = $Credentials
$URI = New-Object System.Uri($AdminCenterURL)
$Container = New-Object System.Net.CookieContainer
$Container.SetCookies($URI, $Credentials.GetAuthenticationCookie($AdminCenterURL))
$UserProfileService.CookieContainer = $Container
#Sets the first User profile, at index -1
$UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1)
#To Get All Properties available: $UserProfileResult.UserProfile| Select name
#Loop through all user profiles
While ($UserProfileResult.NextValue -ne -1)
{
#Get the user UPN property
$Property = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "SPS-UserPrincipalName"}
Write-host $Property.Values[0].Value
#Get Account Name
$Property = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "AccountName"}
Write-host $Property.Values[0].Value
#Get the next profile
$UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue)
}
Using PnP PowerShell:
#Set Variables
$SiteURL = "https://crescent.sharepoint.com"
$UserAccount = "[email protected]"
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get all properties of a User Profile
$UserProfile = Get-PnPUserProfileProperty -Account $UserAccount
$UserProfile.UserProfileProperties
References:
SharePoint Online: Get User Profile Properties using PowerShell
Get and Export User Profile Properties using PowerShell in SharePoint 2013
-
Question was about on-prem, not online.– user6024Commented Jul 30, 2020 at 15:19
$site = (Get-SPWebApplication -IncludeCentralAdministration | ?{$_.IsAdministrationWebApplication -eq $true}).Sites[0]
$context = Get-SPServiceContext $site
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $upm.GetEnumerator()
$profile = $profiles | ?{$_.AccountName -eq 'domain\jdoe'} #if you want to get a specific profile
$upm.Properties.Count #UPSA profile property count
$upm.Count #User Profile count
$job = Get-SPTimerJob | ?{$_.DisplayName -match 'User Profile ActiveDirectory Import Job'}
$job.LastRunTime
-
This works fine.Looking for Audience compliance status.. Commented Aug 1, 2020 at 2:39