Need PowerShell script to connect multiple sharepoint listID to user machine

Shiv 65 Reputation points
2023-06-15T07:47:35.6966667+00:00

HI,

I need to sync multiple SharePoint listId's to user file explorer, can any one suggest me a PowerShell script.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,118 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,758 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Yanli Jiang - MSFT 28,531 Reputation points Microsoft Vendor
    2023-06-16T08:49:22.5366667+00:00

    Hi @Shiv ,

    Based on your description, I don't quite understand your needs.

    Do you want to synchronize all listids in the site to file explore, can you describe further?

    My understanding is that you want to store all listids in a site to file explore in the form of files.

    If this is the case, then you can use powershell to get all the listids in the site.

    For details, please refer to this article:

    https://www.sharepointdiary.com/2018/08/get-list-id-sharepoint-online-powershell.html

    Or, do you want to export all the items in the list to a csv file, and then store the file in file explore?

    If so, you can refer to this article:

    https://www.sharepointdiary.com/2016/03/export-list-items-to-csv-in-sharepoint-online-using-powershell.html

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Limitless Technology 44,566 Reputation points
    2023-06-16T08:55:13.4166667+00:00
    Hello there,
    
    Found this script online and might use for your requirements.
    
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
       
    #Variables for Processing
    $SiteUrl = "
    $ListName="Projects"
     
    $UserName="admin@crescent.com"
    $Password ="Password goes here"
      
    #Setup Credentials to connect
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
      
    #Set up the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Context.Credentials = $credentials
       
    #Get the List
    $List = $Context.web.Lists.GetByTitle($ListName)
     
    #sharepoint online get list items powershell
    $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
    $Context.Load($ListItems)
    $Context.ExecuteQuery()      
     
    write-host "Total Number of List Items found:"$ListItems.Count
     
    #Loop through each item
    $ListItems | ForEach-Object {
        #Get the Title field value
        write-host $_["Title"]
    }
    
    Hope this resolves your Query !!
    
    --If the reply is helpful, please Upvote and Accept it as an answer–
    
    0 comments No comments

  3. Yanli Jiang - MSFT 28,531 Reputation points Microsoft Vendor
    2023-06-27T09:25:01.7233333+00:00

    Hi @Shiv ,

    To sync multiple SharePoint list IDs to a user's file explorer using PowerShell, you can use the following script:

    # Load SharePoint Online PowerShell Module
    Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
    # Set the SharePoint site URL
    $siteUrl = "https://yoursharepointsiteurl.sharepoint.com"
    # Set the list IDs you want to sync to the user's file explorer
    $listIDs = @("list1", "list2", "list3")
    # Connect to SharePoint Online
    Connect-SPOService -Url $siteUrl -Credential $credential
    # Loop through each list ID and sync it to the user's file explorer
    foreach ($listID in $listIDs) {
        # Get the list object
        $list = Get-SPOList -Identity $listID
        # Sync the list to the user's file explorer
        $listUrl = $list.DefaultViewUrl
        $syncPath = "C:\Users\$env:USERNAME\Documents\SharePoint\$listID"
        New-Item -ItemType Directory -Path $syncPath -Force
        New-PSDrive -Name $listID -PSProvider FileSystem -Root $listUrl -Persist -Credential $credential
        $drive = Get-PSDrive -Name $listID
        $driveLocation = $drive.Root
        $driveLetter = $drive.Name + ":"
        $net = new-object -com WScript.Network
        $net.MapNetworkDrive($driveLetter, $driveLocation)
    }
    

    In this script, you first import the SharePoint Online PowerShell module and set the SharePoint site URL. Then, you set the list IDs you want to sync to the user's file explorer in an array.

    Next, you connect to SharePoint Online using the Connect-SPOService cmdlet and provide the user's credentials.

    Finally, you loop through each list ID in the array and get the list object using the Get-SPOList cmdlet. Then, you use the New-PSDrive cmdlet to create a new PowerShell drive for the list and sync it to the user's file explorer using the New-Item and WScript.Network cmdlets.

    Please note that you will need to replace "https://yoursharepointsiteurl.sharepoint.com" with the URL of your SharePoint site, and "list1", "list2", and "list3" with the actual list IDs you want to connect. You will also need to provide the user's credentials to connect to SharePoint Online.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.