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://github.com/VikasSukhija/Downloads/blob/master/RoleAdmins.zip

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://techwizard.cloud/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 
 
##############################################

 

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

2 thoughts on “Extract office 365 Role Admins

  1. Pingback: Extract office 365 Role Admins | Cloud Computers Guide

  2. Pingback: MgGraph Sdk Extract Role Admins from AzureAD | Tech Wizard

Leave a comment