Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential workaround for auth issue in core #71

Open
potatoqualitee opened this issue Aug 17, 2018 · 0 comments
Open

potential workaround for auth issue in core #71

potatoqualitee opened this issue Aug 17, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@potatoqualitee
Copy link
Owner

http://sharepointconnoisseur.blogspot.com/2015/01/workaround-to-make-sharepoint-online.html

#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.Count1; $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-Date
Write-Host "Time after:" $b -ForegroundColor Green
@potatoqualitee potatoqualitee changed the title potentail workaround for auth issue in core potential workaround for auth issue in core Aug 17, 2018
@potatoqualitee potatoqualitee added the enhancement New feature or request label Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant