Can someone please tell me what I am doing wrong with the below code.
Im having trouble pulling the “LastLogontime” Attribute from the Get-MailboxStatistics cmdlet, and its duplicating all the data. Im using the Invoke-All for Speed on the Get-MailboxStatics, since its usually a slow cmdlet.
I’ve changed the code several times and wasted too many hours trying to make it work, i’ve no other choice but to ask for help.
How can I make this an efficient script?
$AzureUser = Get-AzureADUser -All $true | Where-Object { $_.DisplayName -match 'jose' } $mb = $AzureUser |Invoke-All {Get-MailboxStatistics -Identity $_.DisplayName} & { foreach ($mbx in $mb) { foreach ($Azure in $AzureUser) { [pscustomobject] @{ DisplayName = $Azure.DisplayName UserPrincipalName = $Azure.UserPrincipalName LastDirSyncTime = $Azure.LastDirSyncTime EmployeeId = $Azure.ExtensionProperty["employeeId"] Licensed = if($Azure.AssignedLicenses){$TRUE}else{$False} Plan = if($Azure.AssignedPlans){$TRUE}else{$False} Mail = $Azure.Mail AccountEnabled = $Azure.AccountEnabled SamAccountName = ($Azure.DisplayName | foreach {Get-ADUser -filter {Displayname -eq $_}}).SamAccountName LastLogon = $mbx.LastLogontime } } } } | Export-Csv Desktop:\NewTest.csv -NoTypeInformation