Extract office 365 Role Admins

Sharing a quickly written small script which will be useful if you want to extract all the admins from office 365.

Download and Extract the script from below:

https://gallery.technet.microsoft.com/scriptcenter/Extract-office-365-Role-b4007ddf

Run the batch file, It will prompt you for your credentials.

Note: MSOL should be installed and I have tested the script with Global Admin credentials.

follow: https://syscloudpro.com/2015/04/30/connecting-office-365-via-powershell/

 

 

It will start extracting the admin details from office 365

Ones its finished, it will generate a csv file as o365admin.csv in the same folder as below.


 

<#     
    .NOTES 
    =========================================================================== 
     Created on:       6/5/2018 9:47 AM 
     Created by:       Vikas Sukhija (http://SysCloudPro.com) 
     Organization:      
     Filename:         RoleAdmins.ps1 
    =========================================================================== 
    .DESCRIPTION 
        To extract the Admins from o365 
#> 
###connect to MSOL################# 
Connect-MsolService 
$collection =@() 
$AllRoles = Get-MsolRole 
 
$AllRoles | ForEach-Object{ 
    $rolName = $_.Name 
    $rolobjid = $_.Objectid 
    $description = $_.Description 
    Write-Host "Extracting........$rolName" -ForegroundColor Green 
    $getroleadmins = Get-MsolRoleMember -RoleObjectId $rolobjid 
    $getroleadmins | ForEach-Object{ 
        $mcoll = "" | select USerId, RoleName, Description 
        $uid=$null 
        $uid = $_.EmailAddress 
        $mcoll.USerId = $uid 
        $mcoll.RoleName = $rolName 
        $mcoll.description = $description 
        $collection +$mcoll 
    } 
} 
$collection | Export-Csv .\o365Admins.csv -NoTypeInformation 
 
##############################################

 

Thanks for Downloading

Sukhija Vikas

http://SysCloudPro.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s