Hi all,
I'm working on a script to update data in User Profiles. The normal sync chain for Office 365 doesn't permit customization the way you can do on-site so the Support folks provided me with a script to update user data directly from the on-site AD.
The script works but uses GetAuthenticatedCookiesto get the authentication cookies and stuff it into the New-WebServiceProxy object via a CookieContainer. This works of course but requires a login through a pop-up. Not useful to a timed background job.
My goal is to replace the popup with passed PScredentials. The approach that I landed on was to simply use the -credential option of New-WebServiceProxy. I swear it was working last night - had a few test runs and all was good. Went
back this morning to tidy up comments, did one last check, and GetUserProfileByIndex was throwing an exception that I had attempted to perform an unauthorized operation. I'm baffled! I am very (very!) new to PowerShell so perhaps this is just
a newbe thing. Maybe credentials were somehow being stored in my environment through something else I had tried and disappeared when I closed ISE.
I've also noted that passing bad credentials, or allowing the popup and typing in jibberish, does not result in an an exception at the New-WebServiceProxy declaration.
So the question is "Should I be able to use PScredentials in an Office365 environment?". I'm wondering if they might have restrictions in the claims based authentication world.
the script fragment:
# Local parameters
$userName = "admin user at tenant.onmicrosoft.com"
$password = "somepassword"
$siteAdminUrl ="tenant-admin.sharepoint.com"
#load required assemblies
$script_folder = (Split-Path -Parent $MyInvocation.MyCommand.Path)
[void][System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.dll")
[void][System.Reflection.Assembly]::LoadFile($script_folder + "\Microsoft.SharePoint.Client.Runtime.dll")
[void][System.Reflection.Assembly]::LoadFile($script_folder + "\ClaimsAuth.dll")
# Path to user profile service web service - ups
$ups_url = $siteAdminUrl.TrimEnd('/') + "/_vti_bin/UserProfileService.asmx";
# Put username and password into a standard credential object
$securePassword = ConvertTo-SecureString $password –AsPlainText –force
$O365Credential = New-Object System.Management.Automation.PsCredential($username, $securePassword)
# And set up the service. Providing credentials skips the login popups
#$ups_ws = New-WebServiceProxy -Uri $ups_url -Credential $O365Credential
$ups_ws = New-WebServiceProxy -Uri $ups_url -Credential $userName
$ups_indexresult = $ups_ws.GetUserProfileByIndex(-1)