I wanted to get the exported.CSV list of the figure of mailboxes resides on-premise and Office 365 environments in each own.CSV
Here's what I've come up with, but not working:
Code: Select all
Try {
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -Prefix O365 # Prefix to differentiate O365 cmdlets
# Office 365 Mailbox list export
$MailboxList = @()
$MailboxList += Get-O365Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox, SharedMailbox |
Get-O365MailboxStatistics |
Sort-Object lastlogontime -Descending |
Select-Object DisplayName, LastLogonTime |
Export-Csv -Path C:\TEMP\Office365-Mailboxes.CSV
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRDMAIL01-VM/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
# Exchange Server 2013 OnPremise Mailbox list export, The last active mailbox login in the past 30 days determine if it is active mailbox or not
$MailboxList = @()
$MailboxList += Get-Mailbox -ResultSize Unlimited –RecipientTypeDetails UserMailbox, SharedMailbox;
$MailboxList | Where-Object {(Get-MailboxStatistics $_.Identity).LastLogonTime -gt (Get-Date).AddDays(-30)} |
Sort-Object -Property @{e = {( Get-MailboxStatistics $_.Identity).LastLogonTime}} -Descending |
Select-Object DisplayName, @{n = "LastLogonTime"; e = {(Get-MailboxStatistics $_.Identity).LastLogonTime}} |
Export-Csv -Path C:\TEMP\OnPremise-Mailboxes.CSV -NoTypeInformation
}
Catch {
Throw
}
Finally {
If ($Session) {
Remove-PSSession -Session $Session
}
}
Any help would be greatly appreciated.WARNING: The names of some imported commands from the module 'tmp_3rgd0wvj.ptf' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
ModuleType Version Name
ExportedCommands ---------- ------- ---- ---------------- Script 1.0 tmp_3rgd0wvj.ptf {Add-O365AvailabilityAddressSpace, Add-O365DistributionGroupMember, Add-O365MailboxFolderPermission, Add-O365MailboxLocation...} The term 'Get-MailboxStatistics' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ ... ypeDetails UserMailbox, SharedMailbox | Get-MailboxStatistics | Sort- ... + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-MailboxStatistics:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CommandNotFoundException
Thanks,