How can I run SharePoint Online PowerShell from Azure Cloud Shell?

James Slora 41 Reputation points
2024-06-03T13:12:09.2366667+00:00

I want to run SharePoint Online PowerShell, from Azure Cloud Shell. It yields nonsense about the command being unrecognized, though. Here is some example session transcription.

PS /home/entra> Connect-SPOService -Url https://(tenant-admin).sharepoint.com

Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

PS /home/entra> Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell | Select Name,Version

Name Version


Microsoft.Online.SharePoint.PowerShell 16.0.24810.12000

PS /home/entra> Connect-SPOService -Url https://(tenant-admin).sharepoint.com

Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

PS /home/entra> Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force

PS /home/entra> Install-Module Microsoft.Online.SharePoint.PowerShell

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A

PS /home/entra> Connect-SPOService -Url https://(tenant-admin).sharepoint.com

Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

PS /home/entra> Update-Module -Name Microsoft.Online.SharePoint.PowerShell

PS /home/entra> Connect-SPOService -Url https://(tenant-admin).sharepoint.com

Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

PS /home/entra>

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,071 questions
0 comments No comments
{count} votes

Accepted answer
  1. William Nieto 465 Reputation points
    2024-06-03T13:48:16.84+00:00

    It seems you're encountering issues while running SharePoint Online PowerShell commands from Azure Cloud Shell.

    Install the SharePoint Online Management Shell:

    • First, uninstall any existing version:
       powershellCopy code
       Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force
    
      - Then, install the module:
      
      ```powershell
      powershellCopy code
      Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force -AllowClobber
      ```
      
         - If you don't have administrative privileges, install the module for the current user:
         
         ```powershell
         powershellCopy code
         Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser
         ```
         
         **Import the Module**:
         
            - Import the module explicitly to ensure it's loaded:
            
            ```yaml
            powershellCopy code
            Import-Module Microsoft.Online.SharePoint.PowerShell
            ```
            
            **Set Execution Policy**:
            
               - Set the execution policy to allow running scripts:
               
               ```yaml
               powershellCopy code
               Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
               ```
               
               **Connect to SharePoint Online**:
               
                  - Use the **`Connect-SPOService`** cmdlet:
                  
                  ```yaml
                  powershellCopy code
                  Connect-SPOService -Url https://yourtenant-admin.sharepoint.com
                  ```
                  
                     - Replace **`yourtenant-admin`** with your actual tenant admin URL.
                     
                     **Verify Your Connection**:
                     
                        - After connecting, you should be able to run SharePoint Online cmdlets successfully.
                        
    

    Here’s a summary of the commands you'll need:

    powershellCopy code
    Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force
    Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force -AllowClobber
    Import-Module Microsoft.Online.SharePoint.PowerShell
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
    Connect-SPOService -Url https://yourtenant-admin.sharepoint.com
    

    Remember to replace placeholders like yourtenant-admin.sharepoint.com with your actual SharePoint admin center URL. For more detailed information official documentation.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful