【问题标题】:Office 365 - how to manage many usersOffice 365 - 如何管理多个用户
【发布时间】:2015-10-18 17:05:06
【问题描述】:

我在 Office 365 中有 200 个未排序的用户。我想找到一种简单的方法来管理他们是谁以及每个用户所属的安全组。

有没有一种简单的方法可以导出用户名和每个用户所属的组?

我对 poweshell 还很陌生...
但我想用用户和组导出一个 CSV 文件。

这可能吗?

或者您是否推荐任何其他方式来快速了解所有用户以及他们所属的组。

有些用户需要在多个组中,我怀疑有些用户在他们应该在的组中丢失..

感谢我能得到的任何提示。

【问题讨论】:

    标签: security powershell office365


    【解决方案1】:
    ################################################################################################################################################################ 
    # Script accepts 2 parameters from the command line 
    # 
    # Office365Username - Optional - Administrator login ID for the tenant we are querying 
    # Office365Password - Optional - Administrator login password for the tenant we are querying 
    # 
    # 
    # To run the script 
    # 
    # .\Get-DistributionGroupMembers.ps1 [-Office365Username admin@xxxxxx.onmicrosoft.com] [-Office365Password Password123]
    # 
    # 
    # Author:                 Alan Byrne 
    # Version:                 2.0 
    # Last Modified Date:     16/08/2014 
    # Last Modified By:     Alan Byrne alan@cogmotive.com 
    ################################################################################################################################################################ 
    
    #Accept input parameters 
    Param( 
        [Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)] 
        [string] $Office365Username, 
        [Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)] 
        [string] $Office365Password 
    ) 
    
    #Constant Variables 
    $OutputFile = "DistributionGroupMembers.csv"   #The CSV Output file that is created, change for your purposes 
    $arrDLMembers = @{} 
    
    
    #Remove all existing Powershell sessions 
    Get-PSSession | Remove-PSSession 
    
    #Did they provide creds?  If not, ask them for it.
    if (([string]::IsNullOrEmpty($Office365Username) -eq $false) -and ([string]::IsNullOrEmpty($Office365Password) -eq $false))
    {
        $SecureOffice365Password = ConvertTo-SecureString -AsPlainText $Office365Password -Force     
    
        #Build credentials object 
        $Office365Credentials  = New-Object System.Management.Automation.PSCredential $Office365Username, $SecureOffice365Password 
    }
    else
    {
        #Build credentials object 
        $Office365Credentials  = Get-Credential
    }
    #Create remote Powershell session 
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $Office365credentials -Authentication Basic –AllowRedirection         
    
    #Import the session 
    Import-PSSession $Session -AllowClobber | Out-Null          
    
    #Prepare Output file with headers 
    Out-File -FilePath $OutputFile -InputObject "Distribution Group DisplayName,Distribution Group Email,Member DisplayName, Member Email, Member Type" -Encoding UTF8 
    
    #Get all Distribution Groups from Office 365 
    $objDistributionGroups = Get-DistributionGroup -ResultSize Unlimited 
    
    #Iterate through all groups, one at a time     
    Foreach ($objDistributionGroup in $objDistributionGroups) 
    {     
    
        write-host "Processing $($objDistributionGroup.DisplayName)..." 
    
        #Get members of this group 
        $objDGMembers = Get-DistributionGroupMember -Identity $($objDistributionGroup.PrimarySmtpAddress) 
    
        write-host "Found $($objDGMembers.Count) members..." 
    
        #Iterate through each member 
        Foreach ($objMember in $objDGMembers) 
        { 
            Out-File -FilePath $OutputFile -InputObject "$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($objMember.DisplayName),$($objMember.PrimarySMTPAddress),$($objMember.RecipientType)" -Encoding UTF8 -append 
            write-host "`t$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($objMember.DisplayName),$($objMember.PrimarySMTPAddress),$($objMember.RecipientType)"
        } 
    } 
    
    #Clean up session 
    Get-PSSession | Remove-PSSession 
    

    【讨论】:

    • 那个脚本很好用。它导出包含组和成员的 csv。
    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 2020-08-30
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多