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. 本文說明開始使用 Azure AD 和 School Data Sync PowerShell 的設定和必要條件,讓系統管理員可以使用 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. 若要在 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 Cmdlet 合併成單一的 V2 模組之前,這兩者都仍然有用。The V1 module is being deprecated, however both are still useful until all V1 cmdlets are consolidated into a single V2 Module. 若要查看必要條件並安裝這兩個模組,請遵循下列兩個連結中的指示: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. 若要查看每個模組內可用 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. 將 MSOnline 模組連接至 Azure ADConnect the MSOnline Module to Azure AD

    Connect-MsolService -Credential $Cred
    
  4. 將 AzureADPreview 模組連接至 Azure ADConnect the AzureADPreview module to Azure AD

    Connect-AzureAD -Credential $Cred
    

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