2017-09-04 6 views
1

特定のライセンスタイプが割り当てられているすべてのユーザーを検索しようとしています。 私は基本的に私のAzureモジュールv1コマンドをAzureモジュールv2コマンドに変換しようとしています。 Azure module v1コマンドと同じ結果を得る方法は?Azure Active Directory V2 PowerShell - ライセンスを取得したすべてのOffice 365ユーザーの検索

アズールV1:

$OutputFile = "C:\Export\O365LicensedADEnabledUsers.csv" 
$T1 = @() 
$O365Users = Get-MsolUser -All 
ForEach ($O365User in $O365Users) 
{ 
    $ADuser = Get-ADUser -Filter { UserPrincipalName -eq $O365User.UserPrincipalName } -Properties whenCreated, Department, Company, Enabled 
    If (($ADUser.Enabled -eq $true) -and ($O365User.isLicensed -eq $true)) 
    { 
     $T1 += New-Object psobject -Property @{ 
      CollectDate = $(Get-Date); 
      ADUserUPN = $($ADUser.UserPrincipalName); 
      O365UserUPN = $($O365User.UserPrincipalName); 
      ADUserCreated = $($ADUser.whenCreated); 
      ADUserDepartment = $($ADUser.Department); 
      ADUserCompany = $($ADUser.Company); 
      ADUserEnabled = $($ADUser.Enabled); 
      O365Licensed = $($O365User.isLicensed) 
     } 
    } 
} 
$T1 = $T1 | Sort-Object -Property ADUserCreated 
$T1 | Format-Table 
$T1 | Export-Csv -Path $OutputFile -NoTypeInformation 
Write-Host "Output to $OutputFile" 

アズールV2:

私の知る限り、アズールAD V2のPowerShellでないisLicensedプロパティが存在しません。私はこれの代わりにAssignedLicensesプロパティを見つける。しかし私は確信していません。

$OutputFile = "C:\Export\O365LicensedADEnabledUsers.csv" 
    $T1 = @() 
    $O365Users = Get-AzureADUser -All $true 
    ForEach ($O365User in $O365Users) 
    { 
     $ADuser = Get-ADUser -Filter { UserPrincipalName -eq $O365User.UserPrincipalName } -Properties whenCreated, Department, Company, Enabled 
     If (($ADUser.Enabled -eq $true) -and ($O365User.AssignedLicenses -ne $null)) 
     { 
      $T1 += New-Object psobject -Property @{ 
       CollectDate = $(Get-Date); 
       ADUserUPN = $($ADUser.UserPrincipalName); 
       O365UserUPN = $($O365User.UserPrincipalName); 
       ADUserCreated = $($ADUser.whenCreated); 
       ADUserDepartment = $($ADUser.Department); 
       ADUserCompany = $($ADUser.Company); 
       ADUserEnabled = $($ADUser.Enabled); 
       O365Licensed = $($O365User.AssignedLicenses) 
      } 
     } 
    } 
    $T1 = $T1 | Sort-Object -Property ADUserCreated 
    $T1 | Format-Table 
    $T1 | Export-Csv -Path $OutputFile -NoTypeInformation 
    Write-Host "Output to $OutputFile" 
+0

:あなたは、コードの一部を変更するには、以下のコードを参照することができます。 AssignedLicensesプロパティが決してnullにならないように見えるので、あなたのチェックは機能しません。私はあなたが有効だと思うSKUが含まれているかどうかをチェックしなければならないと思います。 [ユーザーエンティティのドキュメント](https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#user-entity)、[AssignedLicense documentation]( https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#assignedlicense-type) – juunas

+0

テナントのサブスクライブされたSKUを取得するには、 Get-AzureAdSubscribedSku'を入力します。次に、それらのうちどれがあなたのユースケースに対して有効であるかを何らかの形で把握し、ユーザがそれらのうちの1つを持っていることを確認します。 – juunas

+0

あなたの答えをありがとう。サンプルスクリプトを教えていただけますか? – Arbelac

答えて

1

ユーザーがAzureのAD V2のPowerShell経由のライセンスであるかどうかを確認するもう一つの簡単な方法は、それがnullであるかどうか代わりに、チェックのAssignedLicensesの数を確認しています。

このプロパティは配列であり、前述のように、このプロパティはヌル可能ではありません。あなたはおそらく代わりに、 `は、Get-ADUser`のうちの第2に、`は、Get-AzureAdUser`を使用することを意図し

If (($ADUser.Enabled -eq $true) -and ($O365User.AssignedLicenses.Count -ne 0)) 
+0

非ライセンスユーザーの場合でも 'If(($ ADUser.Enabled -eq $ true) - と($ O365User.AssignedLicenses.Count -eq 0))'を使用することを前提としています。私は正しいですか? – Arbelac

+0

はい、あなたは正しいです。 –

関連する問題