I have to access a User Profile application for user profile manipulation by PowerShell.
Environment:
I have two user profile service applications installed in my farm.
I wrote this code:
$site = new-object Microsoft.SharePoint.SPSite("http://XXXXXX/_layouts/15/ManageUserProfileServiceApplication.aspx?&ApplicationID=XXXXXXX GUID XXXXXXXXXX);
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
The problem is that this code always points to the same (the first created) User Profile Service application.
I changed the GUID to point to the second User Profile application but it still points to the firts one. How can I reach the second one?