Coder Social home page Coder Social logo

spreplicator's Introduction

SPReplicator

SPReplicator logoSPReplicator is a PowerShell module that helps replicate SharePoint list data.

This module uses the SharePoint Client Side Object Model (CSOM), the PnP.PowerShell module and all required libraries and dlls are included. Installing the SharePoint binaries is not required for the replication to work 👍 Thank you Microsoft for the redistributable nuget and PnP.PowerShell.

SPReplicator works with both on-prem and SharePoint Online and is currently in beta. It also works on .NET Core, so it's cross-platform, and supports Windows, macOS and Linux.

Please report any issues to [email protected].

Installer

SPReplicator is now in the PowerShell Gallery. Run the following from an administrative prompt to install SPReplicator for all users:

Install-Module SPReplicator

Or if you don't have administrative access or want to save it locally (just for yourself), run:

Install-Module SPReplicator -Scope CurrentUser

If you're scheduling tasks via Task Schedule or SQL Server agent, installing the module with administrative privileges is best because it will ensure all users have access via Program Files.

Command Reference

For more details about commands, visit the wiki or use Get-Help.

Usage scenarios

This module can be used for replicating data in a number of ways.

  • Between air gapped (offline) servers that do not have direct access to each other
  • Directly from SharePoint site collection to SharePoint site collection
  • From SQL Server to SharePoint
  • From SharePoint to SQL Server
  • From CSV to SharePoint
  • From SharePoint to CSV
  • From On-prem to SharePoint Online and back

Usage examples

SPReplicator has a number of commands that help you manage SharePoint lists. You can view, delete, and add records easily and there's even a command that makes it easy to see internal column names and datatypes.

Export from SharePoint List

Export-SPRListItem -Site https://intranet -List Employees -Path \\nas\replicationdata\Employees.csv

Establish a session to the SharePoint site

You can specify -Site and -Credential with every command. Or you can establish a connection and not worry about specifying the Site or Credentials in subsequent command executions.

There is no need to assign the output to a variable, as it creates a reusable global variable $global:spsite.

# using your own account credentials
Connect-SPRSite -Site https://intranet

# specifying other credentials
Connect-SPRSite -Site https://intranet -Credential ad\otheruser

# using your own account credentials and SP Online
Connect-SPRSite -Site https://corp.sharepoint.com -Credential otheruser@corp.onmicrosoft.com

# using MFA
Connect-SPRSite -Site https://corp.sharepoint.com -AuthenticationMode WebLogin

# using app login
Connect-SPRSite -Site https://corp.sharepoint.com -AuthenticationMode AppOnly -Credential 1e36c5cc-5281-4235-a84f-c94dc2de8800

Import to SharePoint List

Now that we've established a connection via Connect-SPRSite, we no longer need to specify the Site.

We can import data two ways, using Import-SPRListItem or Add-SPRListItem

# Import from CSV
Import-SPRListItem -List Employees -Path \\nas\replicationdata\Employees.csv

# Import from SQL Server
Invoke-DbaQuery -SqlInstance sql2017 -Query "Select fname, lname where id > 100" | Add-SPRListItem -List emps

# Import any PowerShell object, really. So long as it has the properly named columns.
Get-ADUser -Filter * | Select SamAccountName, whateverelse | Add-SPRListItem -List ADList

# Didn't have time to create a good SharePoint list? Use -AutoCreateList
Get-ADUser -Filter * | Add-SPRListItem -List ADList -AutoCreateList

Find out more

This was just a subset of command examples. For more command examples, visit the wiki or use Get-Help.

Selected screenshots

Connect to a site

image

Add a generic object to a list

image

Add SQL data to a list and auto create the list if it doesn't exist

image

This is what it looks like!

image

Get details about columns to help you format your input/output

image

Results of built-in logger (New-SPRLogList and -LogToList)

image

Power BI

A Power BI Template can be downloaded from here.

image

Pester tested

This module comes with integration tests! If you'd like to see how I test the commands, check out Integration.Tests.ps1

image

Learn more

To find out more about any command, including additional examples, use Get-Help.

Get-Help Get-SPRColumnDetail -Detailed

spreplicator's People

Contributors

potatoqualitee avatar cporteou avatar

Stargazers

David Midlo avatar  avatar Keyth M Citizen  avatar  avatar 3Li avatar  avatar CC avatar  avatar Jimmy Briggs avatar  avatar Randy Miller avatar  avatar Igor avatar Tom-- avatar  avatar Marcin Wisniowski avatar TheCave avatar  avatar Kiran Dangol avatar Jack Waters avatar Luke Brunning avatar Luke Evans avatar Phil Carney avatar  avatar Mark Norynberg avatar  avatar Mike Campbell avatar  avatar Jeff Jerousek avatar Chris Dituri avatar Jonathan Moss avatar Alberto Suarez C. avatar  avatar  avatar George Yang avatar Jason White avatar Ali Robertson avatar Jess Pomfret avatar Franklin Cole avatar Joseph avatar

Watchers

James Cloos avatar  avatar  avatar Franklin Cole avatar

spreplicator's Issues

modify log url

FieldUrlValue url = new FieldUrlValue();
url.Url = "Your Url here";
url.Description = "Your description here";
oListItem["URL"] = url;

ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
var lib = ctx.Web.Lists.GetByTitle("All Project List");
li = lib.AddItem(itemCreateInfo);
li["Title"] = "New Item";
Microsoft.SharePoint.Client.FieldUrlValue u = new Microsoft.SharePoint.Client.FieldUrlValue();
u.Url = "http://www.espn.com";
u.Description = "title";
li["Project"] = u;
li.Update();
ctx.Load(li);
ctx.ExecuteQuery();

uninformative failure

new-sprlist should ahve a better failure message all the time but especially if a duplicat elist is attempted

random potential features

  • Explore hooks, such as the check-in or check-out of a document.
  • File copy using BITS and zips and maybe Microsoft Remote Differential Compression?
  • Explore ListItemCollectionPosition - no need cuz i used a different position tracker in delete
  • Make a dictionary that tracks what's already been imported
    • Taken care of by Column Key, but maybe.

fix tab completion back to enumerator

Register-PSFTeppScriptblock -Name Template -ScriptBlock { Get-SPRListTemplate | Where-Object Id -ne -1 | Select-Object -ExpandProperty Template }

potential workaround for auth issue in core

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.