How to connect to SharePoint Online with PowerShell

preview_player
Показать описание
This is a how-to video on connecting to SharePoint Online with PowerShell.
#On the local machine open PowerShell as an administrator.
#To Check what version of PowerShell you are using use the below command make sure that you are running 'Desktop'
$PSVersionTable

#Check your Execution Policy
#For demonstrations I will set my execution policy to 'Unrestricted'
#To check the execution policy value for the local machine
Get-ExecutionPolicy -Scope LocalMachine

#To set the local machine to unrestricted
Set-ExecutionPolicy -Scope "LocalMachine" -ExecutionPolicy "Unrestricted"

#Check for NuGet
Get-PackageProvider | Where-Object {$_.Name -EQ "NuGet"} | Select-Object -Property Name, ProviderName, Version, ProviderPath, FromTrustedSource | Format-List

#Check for 'PSGallery' repository
Get-PSRepository -Name "PSGallery" | Select-Object -Property *

#Getting quick details on SharePoint Online Module
Find-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Repository "PSGallery" | Select-Object -Property Name, Version, Author, CompanyName, Copyright, PublishedDate, RepositorySourceLocation, Repository, PackageManagementProvider

#List commands in Module
(Find-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Repository "PSGallery").Includes.Cmdlet | Sort-Object

#Checking if module has a Connect command
(Find-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Repository "PSGallery").Includes.Command | Where-Object {$_ -LIKE "Connect-*"}

#Checking module for a Disconnect command
(Find-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Repository "PSGallery").Includes.Command | Where-Object {$_ -LIKE "Disconnect-*"}

#Check if SharePoint Online module is already installed on the machine
Get-InstalledModule -Name "Microsoft.Online.SharePoint.PowerShell"

#If it is not installed use the below command to install it.
Install-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Repository "PSGallery"

#Import SharePoint Online module into current PSSession
Import-Module -Name "Microsoft.Online.SharePoint.PowerShell"

#Update SharePoint Online module
Update-Module -Name "Microsoft.Online.SharePoint.PowerShell"

#Connect to SharePoint Online with your Global Administrator account
Connect-SPOService -Url $URL | Out-Null

#Check if you are connected to your tenant by using Get-SPOSite | Select URL; for this demonstration I will not be revealing my site URLs
(Get-SPOSite | Measure-Object).Count

#At the end disconnect from SharePoint Online
Disconnect-SPOService

#Check if you are disconnected from SharePoint Online
(Get-SPOSite | Measure-Object).Count
Рекомендации по теме