当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 连接到所有 Office 365 服务

作者:精品下载站 日期:2024-12-14 08:14:18 浏览:13 分类:玩电脑

使用 PowerShell 连接到所有 Office 365 服务


由于我必须通过过时的链接和过时的 technet 文章的反复试验来积累以下内容,因此我创建了如何通过 PowerShell 连接到所有 Office 365 会话的最新实际版本。我将每个服务分为自己的部分以及连接到所有服务的组合功能。

先决条件:下载并安装以下内容:
1) 微软.NET框架4.5.2
2) Windows管理框架4.0
3) 面向 IT 专业人员的 Microsoft Online Services 登录助手 RTW(64 位版本)
4) Windows PowerShell 的 Windows Azure Active Directory 模块(64 位版本)
5) Skype for Business Online Windows PowerShell 模块
6) SharePoint在线管理外壳
7) PowerShell的执行策略至少需要经过RemoteSigned。

步骤#1:第一步是输入您的 Office 365 凭据。这将是具有所需权限的 Office 365 登录信息。

$credential = Get-Credential

步骤#2:Office 365 租户 - 下一步是连接到在线租户。

Import-Module MsOnline
Connect-MsolService -Credential $credential

步骤#3:SharePoint Online - 接下来我们可以连接到SharePoint Online,没有特定的顺序。 *将此处的 yourtenantname 替换为您的租户名称。

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://yourtenantnamehere-admin.sharepoint.com -credential $credential

步骤#4:Skype For Business Online - 我们列表中的下一个是 Skype For Business Online。如果您本地有 Lync/Skype For Business,则需要使用 -OverrideAdminDomain 参数。 *将此处的 yourtenantname 替换为您的租户名称。

Import-Module LyncOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential -OverrideAdminDomain "yourtenantnamehere.onmicrosoft.com"
Import-PSSession $sfboSession

步骤#5:Exchange Online - 以下命令将连接到 Exchange Online。

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking

步骤#6:Office 365 合规性 - 最后一项服务是 Office 365 合规性。

$ccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.compliance.protection.outlook.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $ccSession -Prefix cc

步骤#7:我们现在可以将所有服务连接合并到一个名为 Connect-Office365 的函数中。

function Connect-Office365
{
$credential = Get-Credential


Import-Module MsOnline
Connect-MsolService -Credential $credential


Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://yourtenantnamehere-admin.sharepoint.com -credential $credential


Import-Module LyncOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential -OverrideAdminDomain "yourtenantnamehere.onmicrosoft.com"
Import-PSSession $sfboSession


$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking


$ccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.compliance.protection.outlook.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $ccSession -Prefix cc
}

步骤#8:与任何远程 PowerShell 会话一样,您需要在断开连接时清理会话。这是一个用于此目的的函数。

function Disconnect-Office365
{ Remove-PSSession $sfboSession; Remove-PSSession $exchangeSession; Remove-PSSession $ccSession; Disconnect-SPOService }

请随时在评论中留下意见、建议或要求。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯