I tried this code to access user profile information:
add-pssnapin "Microsoft.Sharepoint.Powershell";
$serviceContext = Get-SPServiceContext("my central admin");
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
foreach($usrProfile in $profileManager.GetEnumerator()) {
Write-Host $usrProfile.AccountName "|" $usrProfile.DisplayName;
}
But I am getting these errors:
New-Object : Exception calling ".ctor" with "1" argument(s): "UserProfileApplicationNotAvailableException_Logging ::
UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have 5a2fe999-9785-442e-882e-77f850c64f54"
At line:3 char:19
+ $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileMan ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At line:4 char:24
+ foreach($usrProfile in $profileManager.GetEnumerator()) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Can someone help please
Thanks