从Azure AD Powershell导出组类型
我正在尝试导出所有Azure广告组、其所有者、说明、电子邮件及其组类型。例如Office 365、安全或分发。我已成功地将所有内容正确导出到.csv中,但组类型除外。Get-AzureADGroup将只返回“Group”,我无法从Get-msolgroup-grouptype获得任何结果 我一直在使用的脚本:从Azure AD Powershell导出组类型,azure,powershell,azure-active-directory,Azure,Powershell,Azure Active Directory,我正在尝试导出所有Azure广告组、其所有者、说明、电子邮件及其组类型。例如Office 365、安全或分发。我已成功地将所有内容正确导出到.csv中,但组类型除外。Get-AzureADGroup将只返回“Group”,我无法从Get-msolgroup-grouptype获得任何结果 我一直在使用的脚本: $array = @() $Properties=@{} $Properties.add("GroupDisplayName","1") $Properties.add("OwnerObj
$array = @()
$Properties=@{}
$Properties.add("GroupDisplayName","1")
$Properties.add("OwnerObjectId","2")
$Properties.add("OwnerObjectType","3")
$Properties.add("OwnerUserType","4")
$Properties.add("OwnerUserPrincipalName","5")
$Properties.add("GroupDescription","6")
$Properties.add("Email","7")
$Properties.add("GroupTypes","8")
$groups = Get-AzureADGroup -All $true
$GroupType = Get-MsolGroup -Grouptype
Foreach($group in $groups){
$Owners = Get-AzureADGroupOwner -ObjectId $group.ObjectId -All $true
$Properties.GroupDisplayName=$group.DisplayName
$Properties.GroupDescription=$group.description
$Properties.Email=$group.mail
$Properties.GroupTypes=$group.GroupType
if($Owners -ne $null){
# group has owner
Foreach($Owner in $Owners){
$Properties.OwnerObjectId=$Owner.ObjectId
$Properties.OwnerObjectType=$Owner.ObjectType
$Properties.OwnerUserType=$Owner.UserType
$Properties.OwnerUserPrincipalName=$Owner.UserPrincipalName
$obj=New-Object PSObject -Property $Properties
$array +=$obj
}
}
else{
#group has no owner
$Properties.OwnerObjectId=$null
$Properties.OwnerObjectType=$null
$Properties.OwnerUserType=$null
$Properties.OwnerUserPrincipalName=$null
$obj=New-Object PSObject -Property $Properties
$array +=$obj
}
}
$array | export-csv -Path C:\scripts\Owners13.csv -NoTypeInformation -Encoding UTF8
根据我的研究,命令
getmsolgroup
是Azure AD V1模块的一个命令:。但您使用的其他命令是Azure AD V2模块的命令:。它们在不同的模块中。因此,如果要使用命令getmsolgroup
,首先需要运行命令connectmsolservice
。
例如:
Connect-MsolService
Get-MsolGroup -all | Select-Object DisplayName, GroupType
此外,如果您只想使用AzureAD模块来获取组类型,我们可以使用命令getazureadmsgroup
来获取它。但是如果我们使用这个命令,我们需要根据响应的属性做出一些判断。有关更多详细信息,请参阅
比如说
Connect-AzureAD
Get-AzureADMSGroup -All $true | Select-Object DisplayName, GroupTypes,MailEnabled, SecurityEnabled
更新 您可以使用以下脚本来实现您的需求
connect-AzureAD
$array = @()
$Properties=@{}
$Properties.add("GroupDisplayName","1")
$Properties.add("OwnerObjectId","2")
$Properties.add("OwnerObjectType","3")
$Properties.add("OwnerUserType","4")
$Properties.add("OwnerUserPrincipalName","5")
$Properties.add("GroupDescription","6")
$Properties.add("Email","7")
$Properties.add("GroupTypes","8")
$groups = Get-AzureADGroup -All $true
Foreach($group in $groups){
$Owners = Get-AzureADGroupOwner -ObjectId $group.ObjectId -All $true
$Properties.GroupDisplayName=$group.DisplayName
$Properties.GroupDescription=$group.description
$Properties.Email=$group.mail
$result=Get-AzureADMSGroup -Id $group.ObjectId | Select-Object GroupTypes,MailEnabled, SecurityEnabled, DisplayName
If($result.GroupTypes[0] -eq "Unified"){
$Properties.GroupTypes="O365"
}
elseif($result.SecurityEnabled ){
$Properties.GroupTypes="Security"
}
else{
$Properties.GroupTypes="Distrubution"
}
if($Owners -ne $null){
# group has owner
Foreach($Owner in $Owners){
$Properties.OwnerObjectId=$Owner.ObjectId
$Properties.OwnerObjectType=$Owner.ObjectType
$Properties.OwnerUserType=$Owner.UserType
$Properties.OwnerUserPrincipalName=$Owner.UserPrincipalName
$obj=New-Object PSObject -Property $Properties
$array +=$obj
}
}
else{
#group has no owner
$Properties.OwnerObjectId=$null
$Properties.OwnerObjectType=$null
$Properties.OwnerUserType=$null
$Properties.OwnerUserPrincipalName=$null
$obj=New-Object PSObject -Property $Properties
$array +=$obj
}
}
$array | export-csv -Path E:\test.csv -Encoding UTF8 -NoTypeInformation
我不介意使用哪个模块。我只需要能够获得组类型以及指定的所有其他属性。我将如何将上述脚本实现到我的脚本中?