在 基本行動性和安全性 中管理裝置存取設定

如果您使用 基本行動性和安全性,可能有您無法使用 基本行動性和安全性 來管理的裝置。 如果是,您應該針對 基本行動性和安全性 不支援的行動裝置,封鎖 Exchange ActiveSync 應用程式存取 Microsoft 365 電子郵件。 封鎖 Exchange ActiveSync 應用程式存取有助於保護組織在更多裝置上的資訊。

採取以下步驟:

  1. 使用您的全域系統管理員帳戶登入 Microsoft 365。

  2. 在瀏覽器中,輸入: https://compliance.microsoft.com/basicmobilityandsecurity

  3. 移至 [組織設定] 索引 標籤。

  4. 針對 不支援的 MDM 裝置選取 [存取限制 ],並確定已選取 [ ) 需要允許存取 (裝置註冊 ]。

若要瞭解 基本行動性和安全性 支援哪些裝置,請參閱 基本行動性和安全性 的功能

取得受管理裝置 基本行動性和安全性 詳細數據

此外,您可以使用 Microsoft Graph PowerShell 來取得您為 基本行動性和安全性 設定之組織中裝置的詳細數據。

以下是可供您使用的裝置詳細數據明細。

詳細資料 PowerShell 中要尋找的內容
裝置已在 基本行動性和安全性 中註冊。 如需詳細資訊,請參閱使用 基本行動性和安全性 註冊行動裝置 isManaged 參數的值為:
True= 裝置已註冊。
False= 裝置未註冊。
裝置符合您的裝置安全策略。 如需詳細資訊,請 參閱建立裝置安全策略 isCompliant 參數的值為:
True = 裝置符合原則規範。
False = 裝置不符合原則規範。

基本行動性和安全性 PowerShell 參數。

注意事項

後續的命令和腳本也會傳回 Microsoft Intune 所管理之任何裝置的詳細數據

以下是您需要設定才能執行下列命令和文稿的一些事項:

步驟 1:下載並安裝 Microsoft Graph PowerShell SDK

如需這些步驟的詳細資訊,請 參閱使用 PowerShell 連線到 Microsoft 365

  1. 使用下列步驟安裝適用於 Windows PowerShell 的 Microsoft Graph PowerShell SDK:

    1. 開啟管理員層級的 PowerShell 命令提示字元。

    2. 執行下列命令:

      Install-Module Microsoft.Graph -Scope AllUsers
      
    3. 如果系統提示您安裝 NuGet 提供者,請輸入 Y,然後按 ENTER 鍵。

    4. 如果系統提示您從 PSGallery 安裝模組,請輸入 Y,然後按 ENTER 鍵。

    5. 安裝完成後,請關閉 PowerShell 命令視窗。

步驟 2:連線到您的 Microsoft 365 訂閱

  1. 在 Powershell 視窗中,執行下列命令。

    Connect-MgGraph -Scopes Device.Read.All, User.Read.All
    
  2. 隨即會開啟快顯供您登入。 提供系統管理帳戶的認證並登入。

  3. 如果您的帳戶具有必要的許可權,您會在Powershell視窗中看到「歡迎使用 Microsoft Graph!」。

步驟 3:確定您能夠執行 PowerShell 腳本

注意事項

如果您已設定執行 PowerShell 腳本,則可以略過此步驟。

若要執行 Get-GraphUserDeviceComplianceStatus.ps1 文稿,您必須啟用 PowerShell 腳本的執行。

  1. 從您的 Windows 桌面選取 [開始],然後輸入 Windows PowerShell] 。 以滑鼠右鍵按兩下 [Windows PowerShell],然後選取 [以系統管理員身分執行]

  2. 執行下列指令:

    Set-ExecutionPolicy RemoteSigned
    
  3. 出現提示時,輸入 Y,然後按 Enter。

執行 Get-MgDevice Cmdlet 以顯示組織中所有裝置的詳細數據

  1. 開啟 Windows PowerShell 的 Microsoft Azure Active Directory 模組。

  2. 執行下列指令:

    Get-MgDevice -All -ExpandProperty "registeredOwners" | Where-Object {($_.RegisteredOwners -ne $null) -and ($_.RegisteredOwners.Count -gt 0)}
    

如需詳細範例,請參閱 Get-MgDevice

執行腳本以取得裝置詳細數據

首先,將腳本儲存到您的計算機。

  1. 將下列文字複製並貼到記事本中。

        param (
     	[Parameter(Mandatory = $false)]
     	[PSObject[]]$users = @(),
     	[Parameter(Mandatory = $false)]
     	[Switch]$export,
     	[Parameter(Mandatory = $false)]
     	[String]$exportFileName = "UserDeviceOwnership_" + (Get-Date -Format "yyMMdd_HHMMss") + ".csv",
     	[Parameter(Mandatory = $false)]
     	[String]$exportPath = [Environment]::GetFolderPath("Desktop")
     )
    
     #Clearing the screen
     Clear-Host
    
     #Preparing the output object
     $deviceOwnership = @()
    
    
     if ($users.Count -eq 0) {
     	Write-Output "No user has been provided, gathering data for all devices in the tenant"
     	#Getting all Devices and their registered owners
     	$devices = Get-MgDevice -All -Property * -ExpandProperty registeredOwners
    
     	#For each device which has a registered owner, extract the device data and the registered owner data
     	foreach ($device in $devices) {
     		$DeviceOwners = $device | Select-Object -ExpandProperty 'RegisteredOwners'
     		#Checking if the DeviceOwners Object is empty
     		if ($DeviceOwners -ne $null) {
     			foreach ($DeviceOwner in $DeviceOwners) {
     				$OwnerDictionary = $DeviceOwner.AdditionalProperties
     				$OwnerDisplayName = $OwnerDictionary.Item('displayName')
     				$OwnerUPN = $OwnerDictionary.Item('userPrincipalName')
     				$OwnerID = $deviceOwner.Id
     				$deviceOwnership += [PSCustomObject]@{
     					DeviceDisplayName             = $device.DisplayName
     					DeviceId                      = $device.DeviceId
     					DeviceOSType                  = $device.OperatingSystem
     					DeviceOSVersion               = $device.OperatingSystemVersion
     					DeviceTrustLevel              = $device.TrustType
     					DeviceIsCompliant             = $device.IsCompliant
     					DeviceIsManaged               = $device.IsManaged
     					DeviceObjectId                = $device.Id
     					DeviceOwnerID                 = $OwnerID
     					DeviceOwnerDisplayName        = $OwnerDisplayName
     					DeviceOwnerUPN                = $OwnerUPN
     					ApproximateLastLogonTimestamp = $device.ApproximateLastSignInDateTime
     				}
     			}
     		}
    
     	}
     }
    
     else {
     	#Checking that userid is present in the users object
     	Write-Output "List of users has been provided, gathering data for all devices owned by the provided users"
     	foreach ($user in $users) {
     		$devices = Get-MgUserOwnedDevice -UserId $user.Id -Property *
     		foreach ($device in $devices) {
     			$DeviceHashTable = $device.AdditionalProperties
     			$deviceOwnership += [PSCustomObject]@{
     				DeviceId                      = $DeviceHashTable.Item('deviceId')
     				DeviceOSType                  = $DeviceHashTable.Item('operatingSystem')
     				DeviceOSVersion               = $DeviceHashTable.Item('operatingSystemVersion') 
     				DeviceTrustLevel              = $DeviceHashTable.Item('trustType')
     				DeviceDisplayName             = $DeviceHashTable.Item('displayName')
     				DeviceIsCompliant             = $DeviceHashTable.Item('isCompliant')
     				DeviceIsManaged               = $DeviceHashTable.Item('isManaged')
     				DeviceObjectId                = $device.Id
     				DeviceOwnerUPN                = $user.UserPrincipalName
     				DeviceOwnerID                 = $user.Id
     				DeviceOwnerDisplayName        = $user.DisplayName
     				ApproximateLastLogonTimestamp = $DeviceHashTable.Item('approximateLastSignInDateTime')
     			}
     		}
     	}
    
     }
    
     $deviceOwnership
    
     if ($export) {
     	$exportFile = Join-Path -Path $exportPath -ChildPath $exportFileName
     	$deviceOwnership | Export-Csv -Path $exportFile -NoTypeInformation
     	Write-Output "Data has been exported to $exportFile"
     }
    
  2. 使用擴展名 「.ps1」 將它儲存為 Windows PowerShell 腳本檔案。 例如,Get-MgGraphDeviceOwnership.ps1。

    注意事項

    此腳本也可在 Github 上下載。

執行腳本以取得單一用戶帳戶的裝置資訊

  1. 開啟 Powershell。

  2. 移至您儲存文稿的資料夾。 例如,如果您將它儲存至 C:\PS-Scripts,請執行下列命令。

    cd C:\PS-Scripts
    
  3. 執行下列命令,以識別您想要取得裝置詳細數據的使用者。 此範例會取得的詳細數據 user@contoso.com。

    $user = Get-MgUser -UserId "user@contoso.com"
    
  4. 執行下列命令來起始腳本。

    .\Get-GraphUserDeviceComplianceStatus.ps1 -users $user -Export
    

此資訊會以 CSV 檔案匯出至您的 Windows Desktop。 您可以指定 CSV 的檔案名稱和路徑。

執行腳本以取得一組使用者的裝置資訊

  1. 開啟 Powershell。

  2. 移至您儲存文稿的資料夾。 例如,如果您將它儲存至 C:\PS-Scripts,請執行下列命令。

    cd C:\PS-Scripts
    
  3. 執行下列命令來識別您想要取得裝置詳細數據的群組。 此範例會取得 FinanceStaff 群組中用戶的詳細數據。

    $groupId = Get-MgGroup -Filter "displayName eq 'FinanceStaff'" | Select-Object -ExpandProperty Id
    $Users = Get-MgGroupMember -GroupId $groupId | Select-Object -ExpandProperty Id | % { Get-MgUser -UserId $_ }
    
  4. 執行下列命令來起始腳本。

    .\Get-GraphUserDeviceComplianceStatus.ps1 -User $Users -Export
    

此資訊會以 CSV 檔案匯出至您的 Windows Desktop。 您可以使用其他參數來指定 CSV 的檔案名和路徑。

Microsoft Connect 已淘汰

基本行動與安全性概觀

MSOnline 和 AzureAD Cmdlet 的淘汰公告

Get-MgUser

Get-MgDevice

Get-MgUserOwnedDevice