How to connect to office365
1. Connect to Exchange Online
$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://partner.outlook.cn/PowerShell -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session
Also We can use command with username and password
$CNUser = "admin@consto.partner.onmschina.cn" $CNPWord = ConvertTo-SecureString –String "password" –AsPlainText -Force $CNCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $CNUser,$CNPWord Import-Module MSOnline Connect-MsolService -Credential $CNCredential $ExchangeShell = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://partner.outlook.cn/PowerShell-LiveID?PSVersion=2.0 -Credential $CNCredential -Authentication Basic -AllowRedirection $importresults = Import-PSSession $ExchangeShell -AllowClobber
2. Connect to Office 365
Get-ExecutionPolicy Set-ExecutionPolicy RemoteSigned #更改执行策略 $credential = Get-Credential /#创建凭据 $credential #验证凭据 #连接到office365上面(首先要导入模块,安装登录助手,Azure AD模块) #注意要是安装好了Azure Adconnect 的时候,先决条件会自动安装成功 Import-Module MsOnline #导入office365模块 Get-Module #验证是否导入模块 ,若是返回Manifest MSOnline {Add-MsolAdministrativeUnitMe… 即是导入模块成功 Connect-MsolService -Credential $credential #连接到office365上面 Get-MsolDomain #获取office365中的域
Also We can use command with username and password
$User = "admin@constos.partner.onmschina.cn" $PWord = ConvertTo-SecureString –String "password" –AsPlainText -Force $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Pword Import-Module MsOnline Connect-MsolService -Credential $Credential
3. connct office 365 sharepoint online
在你开始使用 Office 365 PowerShell 管理 SharePoint Online 之前,请确保安装了 SharePoint Online Management Shell 及其先决条件并且已连接到 SharePoint Online。
通过下载并运行 SharePoint Online Management Shell 安装 SharePoint Online Management Shell。只需对每台计算机执行一次此操作。
若要打开 SharePoint Online Management Shell 的命令提示符,请从开始屏幕中键入 sharepoint,然后单击“SharePoint Online Management Shell”。
若要连接到 SharePoint Online,请填写 $adminUPN 和 $orgName 变量的值(替换引号中的所有文本,包括 < and > 字符),然后在 SharePoint Online Management Shell 命令提示符中运行以下命令:
$adminUPN="<the full email address of an Office 365 administrator account, example: jdoe@contosotoycompany.onmicrosoft.com>" $orgName="<name of your Office 365 organization, example: contosotoycompany>" $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password." Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential
https://technet.microsoft.com/library/dn568036.aspx
连接到 SharePoint Online PowerShell
在你开始使用 PowerShell 管理 SharePoint Online 之前,请确保安装了 SharePoint Online 命令行管理程序并且已连接到 SharePoint Online。
通过下载并运行 SharePoint Online 命令行管理程序 安装 SharePoint Online 命令行管理程序。只需对你正在从其中运行 SharePoint Online PowerShell 命令的每台计算机执行一次此操作。
若要打开 SharePoint Online 命令行管理程序的命令提示符,请从开始屏幕中键入 sharepoint,然后单击“SharePoint Online 命令行管理程序”。
若要连接到 SharePoint Online,请填写 $adminUPN 和 $orgName 变量的值(替换引号中的所有文本,包括 < and > 字符),然后在 SharePoint Online 命令行管理程序命令提示符中运行以下命令:
$adminUPN="<the full email address of a SharePoint Online global administrator account, example: jdoe@contosotoycompany.onmicrosoft.com>" $orgName="<name of your Office 365 organization, example: contosotoycompany>" $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password." Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential
系统通过“Windows PowerShell 凭据请求”对话框提示你时,请键入 SharePoint Online 全局管理员帐户的密码。
你现在就可以开始执行 SharePoint Online 命令。