Friday, June 12, 2020

Check specific service plan (Exchange, OneDrive or Yammer) enabled or disabled in office 365 license users with assigned Date


$O365Account = 'admin.sanjiv.kumar@abcabc.onmicrosoft.com'
$O365pw = ConvertTo-SecureString 'Password' -AsPlainText -Force
$O365Credentials = New-Object TypeName System.Management.Automation.PSCredential ArgumentList $O365Account, $O365pw

Connect-AzureAD -Credential $O365Credentials
Connect-MsolService -Credential $O365Credentials
#Log File
$users = Import-Csv 'C:\Temp\Excel data\Data.csv'
Start-Transcript -Path C:\Temp\SOF_Yammer_LicensesReportTranscript_$(get-date -f ddMMyyyy-HHmm).txt -Append
$Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss
$LogFileName=([string]::Concat("C:\Temp\SOT_Yammer_Report-" , $Datetime ,".csv"))
New-Item  $LogFileName  -ItemType file

Add-Content $LogFileName -Value ([string]::Concat("User email" +","+ "License Assigned date"))


#$users = Get-MsolUser -all #| Where isLicensed -EQ $true


#Foreach ($employee in $employee_list) 
Foreach ($user in $users)

{
    
    
    $intFlag = 0

    $UserEmailAddress = $user.Email

    $assignedplans = (Get-AzureADuser -ObjectId $UserEmailAddress).assignedplans

    foreach ($assignedplan in $assignedplans)

    {

       # To check the service plan ID look at MS website https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/licensing-service-plan-reference#next-steps
         #If (($assignedplan.ServicePlanId -eq "efb87545-963c-4e0d-99df-69c6916d9eb0"))# for Excahnge
         If (($assignedplan.ServicePlanId -eq "7547a3fe-08ee-4ccb-b430-5077c5041653")) #for Yammer
         #If (($assignedplan.ServicePlanId -eq "5dbe027f-2339-4123-9542-606e4d348a72")) #for OneDrive
        
        
        
        {
            If (($assignedplan.CapabilityStatus -eq "Enabled"))

             {
        
                    Write-Host   $UserEmailAddress -ForegroundColor White
                    Add-Content $LogFileName -Value ([string]::Concat($UserEmailAddress) +","+ $($assignedplan.AssignedTimestamp))
           
            }
        }

    }

    

}


Write-Host -ForegroundColor Cyan "`n***** Script completed, please close this window *****"
Stop-Transcript

No comments:

Post a Comment

HTML

Script:

JS