You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Bind to Site Collection$Context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Context.Credentials=$Creds#Identify users in the O365.User group$root= [ADSI]''$searcher=New-Object System.DirectoryServices.DirectorySearcher($root)
# Please change user group for your query$searcher.filter="(&(objectcategory=user)(memberof=CN=O365.Users,OU=Distribution Lists,OU=Exchange,DC=na,DC=qualcomm,DC=com))"$users=$searcher.findall()
$adminCookie=$Creds.GetAuthenticationCookie($adminUrl)
# Get the authentication cookie by passing the url of the web service$siteCookie=$Creds.GetAuthenticationCookie($siteUrl);
# Create a CookieContainer to authenticate against the web service$authContainer=New-Object System.Net.CookieContainer;
# Put the authenticationCookie string in the container$authContainer.SetCookies($adminUrl,$authCookie);
# Concatenate the URL for Web Service / REST API$url=$adminUrl+"/_vti_bin/userprofileservice.asmx";
# Create the O365 REST service $UserProfileWS=$null;
try{
$UserProfileWS=New-WebServiceProxy-Uri $url-Namespace 'SPOUserProfileService';
$UserProfileWS.UseDefaultCredentials=$false;
$UserProfileWS.CookieContainer=New-Object System.Net.CookieContainer;
$UserProfileWS.CookieContainer.SetCookies($adminUrl,$adminCookie);
# Assign previously created auth container to web service#$UserProfileWS.CookieContainer = $authContainer; $targetSite=New-Object Uri($adminUrl);
#$UserProfileWS.CookieContainer = New-Object System.Net.CookieContainer;Write-Host$authCookie;
$secondPartOfCookie=$adminCookie.TrimStart("SPOIDCRL=".ToCharArray());
$cookie=New-Object System.Net.Cookie;
$cookie.Name="FedAuth";
$cookie.Value=$secondPartOfCookie;
$UserProfileWS.CookieContainer.Add($cookie);
}
catch{
Write-Error$_-ErrorAction:'SilentlyContinue';
}
# Create People Manager object to retrieve O365 profile data$PeopleManager=New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
for ($i=0; $i-le$users.Count – 1; $i++)
{
$user=$users.Item($i)
$email=$user.Properties["mail"]
$login="i:0#.f|membership|"+$user.Properties["mail"]
$UserProfile=$PeopleManager.GetPropertiesFor($login)
try
{
Write-Host"User LoginName:"$User.LoginName-ForegroundColor Green
Write-Host"User Email:"$User.Email-ForegroundColor Green
# Query AD to get user UPN value through email$searcher.filter="(&(objectClass=user)(mail= $email))"$aduser=$searcher.findall()
$UPNValue=$aduser[0].Properties["userprincipalname"]
Write-Host"UPN Value:"$UPNValue.Item(0) -ForegroundColor Green
# Update the SIP of O365 UPS for this user$userProperty=$UserProfileWS.GetUserPropertyByAccountName($login,'SPS-SipAddress')
$currentsid=$userProperty[0].Values[0].Value;
$userProperty[0].Values[0].Value =$UPNValue.Item(0);
$userProperty[0].IsValueChanged =$true;
$UserProfileWS.ModifyUserPropertyByAccountName($login,$userProperty)
$line=$login+“,”+'"'+$email+'"'+“,”+$currentsid+“,”+'"'+$UPNValue.Item(0) +'"'Add-Content$reportFile$line
}
catch
{
Write-Error$_-ErrorAction:'SilentlyContinue';
}
}
$b=Get-DateWrite-Host"Time after:"$b-ForegroundColor Green
The text was updated successfully, but these errors were encountered:
potatoqualitee
changed the title
potentail workaround for auth issue in core
potential workaround for auth issue in core
Aug 17, 2018
http://sharepointconnoisseur.blogspot.com/2015/01/workaround-to-make-sharepoint-online.html
The text was updated successfully, but these errors were encountered: