
我嘗試從一個簡單的、新安裝的powershell 中執行此操作,頂部沒有安裝任何其他內容,但官方方式似乎只是導致有關缺少包管理器、不存在的包提供程序、缺少命令和各種其他類似訊息的錯誤。 (微軟網站只是簡單地說明了Install-Module ExchangeOnlineManagement
所需要的一切)
簡而言之,真正的方法是將一大堆相互依賴的程式安裝到 powershell 中,最終能夠執行該Install-Module ExchangeOnlineManagement
命令。有關執行此操作的說明分散在 Microsoft 網站上,嘗試執行此操作需要調試十幾個不同的錯誤,這是一個耗時的過程。
什麼是完全的在 Windows 電腦上從普通的 powershell 轉變為可以連接到 Office-365 Exchange Online 的一組步驟?
答案1
可用模組和 cmdlet 特定於 PowerShell 版本。您沒有說您正在執行什麼 WinOS,也沒有說您正在執行哪個版本的 PowerShell。
沒有理由在 Windows 上安裝 PowerShell。預設情況下它就在那裡,因為它是作業系統的一部分。只需使用開始功能表來啟動控制台主機或 ISE(整合腳本環境)。但是,如果您使用的是舊版 Windows,則您使用的是舊版 PowerShell,除非您將 Windows Powershell 版本升級到最新版本。
因此,powershell.exe 或 powershell_ise.exe 是執行檔。
唯一的其他安裝選項是安裝跨平台 PowerShell Core(雖然不是您所追求的必需的,但這是一個選擇,您可以使用其中任何一個,甚至可以同時使用。)
安裝 PSCore 不會升級或取代 Windows PowerShell,它是作業系統的一部分。這是一個並排模型......
pwsh.exe
...是 PSCore 的可執行檔。
然後更新 PowerShell 幫助文件...
Update-Help -Force -ErrorAction SilentlyContinue
...,然後使用...
Find-Module
....單獨命令來更新套件管理或特定模組,
Find-Module -Name 'ExchangeOnlineManagement' |
Install-Module -Force
....或者只是運行這個...
Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber
...手動更新套件管理器。
最後,安裝您需要/想要的模組,並使用您的 PowerShell 設定檔自動載入它們。在您的個人資料中,這...
# Required for use with web SSL sites
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::
SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
...應該在那裡以及所有分發的腳本中。
若要在 O365/M365 上使用任何內容,您必須先登入該服務。
在單一 PowerShell 視窗中連線到所有 Microsoft 365 服務
$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
$acctName="<UPN of the account, such as [email protected]>"
$credential = Get-Credential -UserName $acctName -Message "Type the account's password."
#Azure Active Directory
Connect-AzureAD -Credential $credential
#SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -credential $credential
#Skype for Business Online
Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential
#Exchange Online
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -ShowProgress $true
#Security & Compliance Center
Connect-IPPSSession -UserPrincipalName $acctName
#Teams
Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential
答案2
透過一些試驗和錯誤,我設法這樣做了(儘管我不確定這樣做的安全性和正確性,或者是否有一些多餘的步驟,因為正確的知識是支離破碎的):
開始:
首先是檢查 powershell 版本Get-Host
,至少必須是5.0
.如果沒有,.msu
請透過下載並執行所述安裝程式來安裝最新的軟體包。然後運行:
# Powershell defaults to TLS1.1, which was deprecated.
# Thus by default its package management functions ship broken. Force it to use TLS1.2 by setting:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Find-PackageProvider -Name "NuGet" -AllVersions
# Select the latest version
Install-PackageProvider -Name "NuGet" -RequiredVersion "2.8.5.208" -Force
# Check with
Get-PackageProvider
# Register the repo
Register-PSRepository -Default -Verbose
# Check with
Get-PSRepository
# Check which version pops up in the error when running
Install-Module PowerShellGet
# Then run the command to update PowerShellGet (replace the version number with the latest from the previous command):
Install-Module PowerShellGet -RequiredVersion 2.2.5
# Finally:
Install-Module ExchangeOnlineManagement
# Next, enable running scripts with:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
# Import
Import-Module ExchangeOnlineManagement
答案3
確保您的 Windows 伺服器/用戶端版本是支援的作業系統,並且您的伺服器/客戶端滿足EXO V2 模組的先決條件(EXO V2 模組支援的作業系統):
然後安裝 EXO V2 模組:
安裝或更新PowerShell取得模組(確保您使用的是 TLS 1.2)
使用以下命令安裝 EXO V2 模組
Install-Module -Name ExchangeOnlineManagement
除了在 PowerShell 中使用 EXO V2 模組來管理 Office 365 物件外,您還可以使用連接到 Exchange Online PowerShell 的基本驗證(在此之前,先決條件應該注意。