Colleagues, what I need is to get the list of mailboxes based on domain\logon name only. Shared mailboxes contain mostly the users that are located on other domains hence I have to use command for getting the data for linked accounts.
First of all I export the list of names to a csv file.
Get-Mailbox -Identity GROUP | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Export-csv -path C:\Users\mplumsky\Desktop\GROUP_list.csv NoTypeInformation
When I try the following command on a single user it works well:
get-mailbox -Resultsize Unlimited | ? { $_.LinkedMasterAccount -eq 'domain\user' } | select Name, Primarysmtpaddress > mailbox.txt
Of course I have a long list of users and it would be great when powershell could do the job in the background. That's why I've come up with the idea:
$users = import-csv C:\Users\mplumsky\Desktop\GROUP_list.csv
ForEach ($item in $users)
{
$username = $item.User
get-mailbox -Resultsize Unlimited | ? { $_.LinkedMasterAccount -eq '$username' } | select Name, Primarysmtpaddress > mailbox_list.csv
}
As a result I get a blank csv or txt file. Any ideas what could be wrong?