適用於 SDS 的 PowershellPowershell For SDS

使用 School Data Sync 和 Azure Active Directory 時,在 PowerShell 中執行工作及動作會有幫助。When working with School Data Sync and Azure Active Directory, performing tasks and actions in PowerShell is helpful. PowerShell 可讓大量及指令碼執行的作業,以輕鬆完成。PowerShell enables bulk and scripted operations to be completed with ease. 本文說明安裝以及開始使用 PowerShell 與 Azure AD 的先決條件和 School Data Sync,讓系統管理員可以使用 PowerShell 做為工具以更妥善地管理其同步處理的 SDS 資料。This article explains the setup and prerequisites to start using PowerShell with Azure AD and School Data Sync,enabling administrators to use PowerShell as a tool to better manage their synced SDS data.

參照,您可以找到這裡: SDS Powershell 指令碼For reference, you can find here: SDS Powershell scripts.

安裝 Azure PowerShell 模組Install the Azure PowerShell Modules

Azure ad 目前有 3 PowerShell 模組。There are currently 3 PowerShell modules for Azure AD. 適用於 SDS 的 PowerShell 物件管理,建議您安裝的 MSOnline 模組 (V1) 和 AzureADPreview 模組 (V2)。For SDS object management in PowerShell, we recommend installing both the MSOnline Module (V1) and the AzureADPreview Module (V2). V1 模組已被取代,但是兩者仍有用直到所有 V1 cmdlet 會合併成單一 V2 模組。The V1 module is being deprecated, however both are still useful until all V1 cmdlets are consolidated into a single V2 Module. 若要檢閱必要條件並安裝這兩個模組,請遵循下列連結,2 中的指示:To review the prerequisites and install both modules, follow the instructions in the 2 links below:

安裝 powershell V1 MSOnline 模組Install the V1 MSOnline Module for PowerShell

安裝 PowerShell V2 AzureADPreview 模組Install the V2 AzureADPreview Module for PowerShell

確認安裝並匯入模組Confirm Installation and Import the Modules

安裝後,請先確認已成功安裝的模組。Once installed, confirm the modules installed successfully. 這也是如何 PowerShell 中載入模組。This is also how you load the modules into PowerShell. PowerShell 中載入模組,可讓您執行每個模組相關聯的 cmdlet。Loading the modules into PowerShell allows you to run the cmdlets associated with each module.

若要確認已安裝的模組,並匯入 PowerShell,執行下列步驟:To confirm the modules installed and import them into PowerShell, perform the steps below:

  1. 啟動 PowershellLaunch Powershell

  2. 執行匯入這兩個模組下方的 2 命令:Run the 2 commands below to import both modules:

    Import-Module MSOnline 
    Import-Module AzureADPreview
    
  3. 執行下列命令,以確保載入的模組,並已成功安裝:Run the command below to ensure the module loaded and are installed successfully:

    Get-Module
    

    注意

    如果您看見列出的 AzureADPreview 和 MSOnline 模組,他們是否已成功安裝。If you see both the AzureADPreview and MSOnline modules listed, they have been installed successfully.

  4. 若要檢閱每個模組內的可用指令程式的清單,請執行下列兩個命令:To review the list of available cmdlets within each module, run the two commands below:

    $FormatEnumerationLimit = 1000
    Get-Module | ? {($_.Name -eq 'AzureADPreview') -or ($_.Name -eq 'MSOnline')} | fl ExportedCommands
    

使用 PowerShell 的 Azure ad connectConnect to Azure AD using PowerShell

模組會匯入之後,您需要將 PowerShell 連線到 Azure AD 以執行 Azure AD 目錄針對每個模組相關聯的命令。Once the Modules are imported, you’ll need to connect PowerShell to Azure AD to run the commands associated with each module against your Azure AD directory. 若要這麼做,請執行下列詳細說明的命令:To do this, run the commands detailed below:

  1. 將您的認證儲存在變數Store your credentials in variable

    $Cred = Get-Credential
    
  2. 出現提示時在 O365 租用戶中,輸入您的全域系統管理員認證。Enter your Global Admin Credentials for your O365 tenant, when prompted.

  3. 連線到 Azure AD 的 MSOnline 模組Connect the MSOnline Module to Azure AD

    Connect-MsolService -Credential $Cred
    
  4. 連線到 Azure AD 了 AzureADPreview 模組Connect the AzureADPreview module to Azure AD

    Connect-AzureAD -Credential $Cred
    

    如需詳細資訊,請參閱部署後工作所有 SDS 指令碼For more information, please see Post Deployment Tasks and All SDS scripts.