Pour télécharger le référentiel GitHub, veuillez suivre ce lien.
Ce script PowerShell créera un fichier LogonTime.csv dans le répertoire actif.
#=============================================================== # author: Julien Bonnier# file: getMsolLicenses.ps1 # project: office365licenses # version: 1.0.2.20170425.1448 # url: https://github.com/jbonnier/office365licenses #=============================================================== $LiveCred = Get-Credential $ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection Connect-MsolService -Credential $LiveCred Import-PSSession $ExchangeSession $mailboxes = Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientTypeDetails -Ne "DiscoveryMailbox"} $arr = @() foreach ($mailbox in $mailboxes) { $obj = New-Object -TypeName PSObject $stats = Get-MailboxStatistics -Identity $mailbox.Identity $msolUser = Get-MsolUser -UserPrincipalName $mailbox.UserPrincipalName $licenses = "" foreach ($license in $msolUser.Licenses) { if ($license.AccountSkuId -Like "*:VISIOCLIENT") { $licenses += "Visio, " } elseif ($license.AccountSkuId -Like "*:EXCHANGE*") { $licenses += "Exchange, " } elseif ($license.AccountSkuId -Like "*:POWER_BI_*") { $licenses += "Power-Bi, " } elseif ($license.AccountSkuId -Like "*:OFFICESUBSCRIPTION") { $licenses += "Office, " } else { $licenses += "$license.AccountSkuId, "} } if ($licenses.Length -Ne 0) { $licenses = $licenses.Substring(0, $licenses.Length-2) } Add-Member -InputObject $obj -MemberType NoteProperty -Name Identity -Value $mailbox.Identity Add-Member -InputObject $obj -MemberType NoteProperty -Name DisplayName -Value $mailbox.DisplayName Add-Member -InputObject $obj -MemberType NoteProperty -Name Address -Value $mailbox.PrimarySmtpAddress Add-Member -InputObject $obj -MemberType NoteProperty -Name Licensed -Value $msolUser.islicensed Add-Member -InputObject $obj -MemberType NoteProperty -Name "License(s)" -Value $licenses Add-Member -InputObject $obj -MemberType NoteProperty -Name LastLogonTime -Value $stats.LastLogonTime $arr += $obj } $arr | Export-Csv LogonTime.csv Remove-PSSession $ExchangeSession