Powershell For SDSPowershell For SDS

使用學校資料同步處理及 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 的先決條件和學校資料同步處理,讓系統管理員可以使用 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.

安裝 Azure PowerShell 模組Install the Azure PowerShell Modules

Azure AD 的目前有 3 PowerShell 模組。There are currently 3 PowerShell modules for Azure AD. 在 PowerShell SDS 物件管理,建議您安裝 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 指令程式已合併成單一 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:



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

  4. 若要檢閱每個模組內可用的 cmdlet 清單,請執行下列兩個命令: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 ADConnect 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

    如需詳細資訊,請參閱文章部署工作For more information, please see Post Deployment Tasks

所有 SDS 指令碼All SDS scripts.