Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Sharepoint O365 (online) remote Powershell script works on one machine but not another

$
0
0

I'm using a remote Powershell script to retrieve User Profile data from Sharepoint O365 online.  I run the script using -executionpolicy bypass because the the script is unsigned. Also, I have set the Execution Policy within Powershell to RemoteSigned.

The script works fine from my Win 7 machine and my internet connection. However, I have another user on a different Win 7 machine (actualy tried 2 different machines) and a different internet connection for which the user profile query returns no records. The script runs, because it creates an empty txt file with the proper headers, but there are no records in the txt file.

I'm not sure if the problem is with the script, the Sharepoint dlls, the credentials, the connection to the Sharepoint site, or something else entirely. I'm hoping someone with more experience can help me get past this problem.

So far, I have tried the following to try to isolate the problem:

Had the user login to the Sharepoint site (using IE and stay connected).

Had the user log off to the Sharepoint site.

Had the user try 2 different sets of user and password that both have Sharepoint admin rights. Both work on my machine, neither work on his.

Have the user copy and paste the script into a new ps1 file so it is created on his machine and not blocked because it is a downloaded script.

Checked to make sure the Sharepoint dll files are in the correct path as indicated in the script. (The dll files were installed using the MS download site indicated in the first commented line of the script)

I'm beyond my ability to figure this out and I could sure use some help!

Thanks,

Sup

This is the script that I am using:

#Please install the SharePoint client components SDK - http://www.microsoft.com/en-us/download/details.aspx?id=35585 prior to running this script.

#Configure Site URL and User
$User = "admin@mydomain.com"
$SiteURL = "https://tenant.sharepoint.com/sites/site"

#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

$Password = "MyPwd"
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$SecurePassword)

#Bind to Site Collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Creds

#Identify users in the Site Collection
$Users = $Context.Web.SiteUsers
$Context.Load($Users)
$Context.ExecuteQuery()

#Create People Manager object to retrieve profile data
#Output to pipe delimited text file
$Output = "C:\SharepointUsers\SharepointUsers.txt"
$Headings = "Email","First Name","LastName","Address","Phone","Job Title","Department","Name"
$Headings -join "|" | Out-File -Encoding default -FilePath $Output

$PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
Foreach ($User in $Users)
    {
    $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
    $Context.Load($UserProfile)
    $Context.ExecuteQuery()
    If ($UserProfile.Email -ne $null)
        {
        $UPP = $UserProfile.UserProfileProperties
        $Properties = $UserProfile.Email,$UPP.FirstName,$UPP.LastName,$UPP.'SPS-StreetAddress',$UPP.WorkPhone,$UPP.'SPS-JobTitle',$UPP.Department,$UserProfile.DisplayName
        $Properties -join  "|" | Out-File -Encoding default -Append -FilePath $Output
        }
    }


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>