none
New to SharePoint Online and working with SharePoint Management Shell

    Question

  • I am very confused about working in this environment.

    - We have SharePoint Online

    - I have installed Power Shell and SharePoint Online Management Shell on my Windows 7 PC.

    As configured none of the SharePoint commands work.  It seems that I need to load modules or assemblies.  I don't understand why I seem to need to use both Import-Module command and the LoadWithPartialName command.  For example my connect script does the following (after the ======)

    1. Can someone explain to me why this is the way?
    2. In addition, I have no clue to get Get-SPOWeb command loaded.  I have many reference scripts that require this command and I'm unable to fire out why.

    ============

    $adminUPN="yyyy@xxxxx.edu"
    $orgName="XXXXXXXXXXXXXX"
    $userCredential = Get-Credential -UserName $adminUPN -Message "Enter Password"

    if ((Get-Module Microsoft.Online.SharePoint.PowerShell).Count -eq 0) {

            Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
    }
    Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential

            if ((Get-Module Microsoft.Online.SharePoint.PowerShell -ListAvailable) -eq $null) {
                throw "The Microsoft SharePoint Online PowerShell cmdlets have not been installed."
            }
            if ($global:spoCred -eq $null) {
                [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null

                $global:spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userCredential .UserName, $userCredential .Password)      

    }

    Tuesday, March 14, 2017 8:22 PM

All replies

  • Hi,

    A module is a set of related Windows PowerShell functionalities, grouped together as a convenient unit (usually saved in a single directory). Modules can be written in PowerShell and/or compiled as DLLs, which contain cmdlets, variables and etc.

    So, you won’t be able to use any SharePoint Online cmdlets without loading the required module (Import-Module) in Windows PowerShell.

    But you don’t need to import Module if you run scripts via SharePoint Online Management Shell. When you click the SharePoint Online Management Shell shortcut, it loads the installed Microsoft.Online.SharePoint.PowerShell module into a standard PowerShell console window.

    More information about SharePoint Online Management Shell for your reference:

    https://www.itunity.com/article/intro-spo-management-shell-959

    The script “[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")” is to load the Clients DLL installed with the Office Developer tools on your local machine. After loading client DLL, you’re able to manipulate SharePoint Online objects.

    For example, in your script “$global:spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userCredential .UserName, $userCredential .Password)”, the “Microsoft.SharePoint.Client.SharePointOnlineCredentials” object is from the “Microsoft.SharePoint.Client.Runtime” DLL.

    More information about SharePoint online script for your reference:

    https://blogs.technet.microsoft.com/french_sharepoint_gbs_blog/2014/04/08/how-to-manage-your-o365-sites-with-powershell-and-csom/

    Thanks,

    Dean Wang


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

    Wednesday, March 15, 2017 5:11 AM
    Moderator
  • Hi,
    Is there any update?
    If my reply is helpful to you, you can mark as answer.
    Thanks,
    Dean Wang

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

    Monday, March 20, 2017 1:33 PM
    Moderator