none
PowerShell and Office 365 SharePoint

    Question

  • Is anyone aware of a way to interact with SharePoint running in Office 365 via PowerShell(even though a RESTful API)? I need to work with a SharePoint list in Office 365 using some basic CRUD operations.  However, everything I have found so far is if you are running your own SharePoint server on-site. I haven't been able to find anything related to SharePoint in Office 365. Thanks!
    Thursday, April 13, 2017 1:06 PM

All replies

  • Hi Brad,

    Thanks for visiting our forum.

    Then this is the forum to discuss general questions and feedback related to Office client. Since your query is about PowerShell and SharePoint, I'll move your thread to the following dedicated SharePoint Forum for better response:

    https://social.technet.microsoft.com/Forums/office/en-US/home?forum=onlineservicessharepoint

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best regards,
    Yuki Sun

    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, April 14, 2017 2:36 AM
  • Hi Brad_Jackson,

    To list items from SharePoint Online site using PowerShell, we need to install the SharePoint Online Management Shell.

    Run the SharePoint Online Management Shell command prompt, initialize context object with the site URL parameter and the SharePoint Online Credentials.

    $siteURL = ""
    
    $userId = ""
    
    $pwd = Read-Host -Prompt "Enter password" -AsSecureString 
    
    $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd) 
    
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL) 
    
    $ctx.credentials = $creds


    Then access the list using the context.

    $lists = $ctx.web.Lists 
    
    $list = $lists.GetByTitle("TestList")


    Here are some examples to get/create/update/delete SharePoint Online list items using PowerShell:

    http://www.c-sharpcorner.com/article/list-item-operations-using-csom-with-powershell-for-sharepoi/

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, April 14, 2017 6:12 AM
  • Yuki, thank you for pointing me to the correct group!
    Monday, April 24, 2017 12:29 PM
  • Hi Brad_Jackson,

    Does the information about the PowerShell for SharePoint Online answer your question?

    If you think the reply is helpful, please mark it an answer.

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 25, 2017 6:05 AM
  • Hi Linda,

    Sorry for the slow reply.  This isn't working.  I need to work with an office365 SharePoint site.  What should I specify for my url?  I have tried the following, and neither works.  They both fail when I try to do anything with the $lists object because I don't think anything is being returned.

    $url = "https://otsf.sharepoint.com/mysite"

    $url = "https://otsf.sharepoint.com/mysite/SitePages/Home.aspx"

    An error occurred while enumerating through a collection: The collection has not been initialized. It has not been
    requested or the request has not been executed. It may need to be explicitly requested.

    I've tried the following as my URL.  Most of the SharePoint PowerShell examples I've seen are for on-premise, but this is an Office365 SharePoint site.  Since it is an organization in Office365, I don't have to specify a password either.  I still specified my AD credentials, which is how the web knows who I am.

    I appreciate your help on this topic.

    Friday, April 28, 2017 2:05 PM
  • Hi Brad_Jackson,

    We need to connect to the SharePoint Online Administration Center URL.

    To connect, run this script in the SharePoint Online Management Shell:

    Connect-SPOService –url https://mytenant-admin.sharepoint.com

    And use the full email address of a SharePoint for the user Id:

    Information about how to connect to SharePoint Online using PowerShell:

    https://technet.microsoft.com/en-us/library/fp161372.aspx

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, May 1, 2017 2:19 AM
  • Sorry for the slow reply.  This a project I'm working on when I have time.

    The command gives me an unathorized response back, which is because the account I'm using is not a SharePoint Online global administrator.  I simply would like to connect to sharepoint in Office 365 as a standard user who is permissions to the sharepoint site and get the contents of a sharepoint list.  This should never require admin access.


    Friday, May 19, 2017 7:03 PM
  • Hi Brad_Jackson,

    We must use an account that is a SharePoint Online global administrator if we want to use the SharePoint Online Management Shell.

    Best regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, May 24, 2017 2:45 AM