Get-mailbox powershell command

Hi,
I am trying to to create a power shell script to display the information as per below, any help would be greatly appreciated. Also is it possible to have another column to show if user is disable in AD or not,
regards,
Hazey
Get-Mailbox
foreach
$DisplayName
=Select-Object
DisplayName
$PrimarySMTPAddress
=Select-Object
PrimarySMTPAddress
$IssueWarningQuota
=Select-Object
IssueWarningQuota
$ProhibitSendQuota
=Select-Object
ProhibitSendQuota
$WhenCreated
=Select-Object
WhenCreated
$lastlogontime
=get-MailboxStatistics
|
Select-Object
lastlogontime
$ItemCount
=get-MailboxStatistics
|
Select-Object
ItemCount
$TotalItemSize
=get-MailboxStatistics
|
Select-Object
TotalItemSize
$AdGroups
=(Get-QADUser).memberof
| Get-QADGroup|
select
name
Export-Csv
-Path
c\results.csv
-NoTypeInformation
-append

Save the complete Script as a GetMailboxInfo.Ps1 File. Open Exchange Management Shell as administrator and run this PS1 File. Reply back in case if the you see any errors while the script execution.
$Global:Report = @()
Function GetMailboxDetails($List)
Write-Host -ForeGroundColor YELLOW "Import Active Directory Module"
Import-Module ActiveDirectory
foreach($Line in $List)
$GroupInfo = @()
$CurrentMailbox = $Line.Alias
$MailboxObj = "" | Select DisplayName,Alias,PrimarySMTPAddress,SAMACcountNAme,Database,IssueWarningQuota,ProhibitSendQuota,WhenCreated,ExchangeUserAccountControl,TotalItemSize,LastLoggedOnBy,MemberOf
$MailboxObj.Alias = (Get-Mailbox $CurrentMailbox).Alias
$MailboxObj.DisplayName = (Get-Mailbox $CurrentMailbox).DisplayName
$MailboxObj.PrimarySMTPAddress = (Get-Mailbox $CurrentMailbox).PrimarySMTPAddress
$MailboxObj.SAMACcountNAme = (Get-Mailbox $CurrentMailbox).SamAccountName
$MailboxObj.Database = (Get-Mailbox $CurrentMailbox).Database
$MailboxObj.IssueWarningQuota = (Get-Mailbox $CurrentMailbox).IssueWarningQuota
$MailboxObj.ProhibitSendQuota = (Get-Mailbox $CurrentMailbox).ProhibitSendQuota
$MailboxObj.WhenCreated = (Get-Mailbox $CurrentMailbox).WhenCreated
[String]$AccountControl = (Get-Mailbox $CurrentMailbox).ExchangeUserAccountControl
$MailboxObj.ExchangeUserAccountControl = "DISABLED ACCOUNT"
If($AccountControl -eq "None")
$MailboxObj.ExchangeUserAccountControl = "ACTIVE"
$MailboxObj.TotalItemSize = (Get-MailboxStatistics $CurrentMailbox).TotalItemSize
$MailboxObj.LastLoggedOnBy = (Get-MailboxStatistics $CurrentMailbox).LastLoggedOnBy
$DLGroupMembership = (Get-ADUser $Line.SamAccountName).MemberOf
for($i = 0;$i -lt $DLGroupMembership.Count;$i++)
$GroupInfo += $DLGroupMembership[$i]
$GroupInfo += ","
$MailboxObj.MemberOf = $GroupInfo
$Global:Report += $MailboxObj
# MAIN #
"`n+++Gathering Mailbox Info..."
$MailboxList = Get-Mailbox -ResultSize Unlimited | Select DisplayName,Alias,PrimarySMTPAddress,SAMACcountNAme,Database,IssueWarningQuota,ProhibitSendQuota,WhenCreated,ExchangeUserAccountControl
GetMailboxDetails $MailboxList
Write-Host -ForeGroundColor GREEN "Exporting Report to CSV File..."
$Global:Report | Export-Csv MailboxInfo.Csv -NoTypeInformation

Similar Messages

  • Get-InboxRule Powershell Command To Display all Rules

    Hello,
    I am in need a powershell command that display all InboxRules per mailbox database. I want to export the information to a CSV and show DisplayName,IsValid,Name,From,RedirectTo as the the column names.
    I found this great article below but I have been unable to pull additional information like the DisplayName. 
    http://blogs.msdn.com/b/canberrapfe/archive/2012/11/05/ever-needed-to-find-server-side-outlook-rules-that-forward-mail-outside-of-your-organisation.aspx
    Any assistance would be greatly appreciated.
    This is what I have been working with so far.
    Get-MailboxDatabase -Identity 'db-f' | Get-Mailbox -ResultSize unlimited  | Get-InboxRule -ErrorAction:SilentlyContinue | Select-Object
    DisplayName, isvalid, @{Name="Forward To";Expression={[string]::join(";",($_.ForwardTo))}} | Export-Csv filename.csv
    Jason

    From the output you are selecting, it appears you are trying to pull rules that forward items to other recipients.  If this is the case, there is no value "DisplayName" returned by the Get-InboxRule command, so what you're going to need
    to do is put bits of information together into the data you want.  Try the following and see if it gives you something workable:
    $MbxDbs = Get-MailboxDatabase
    $MbxDbs | % {
        $DbName = $_.Name
        $DbMbxs = Get-Mailbox -Database $DbName
        $DbMbxs | % {
            $MbxName = $_.Name
            Get-InboxRule -Mailbox $MbxName
        } | Select @{E={ $DbName };L='Database'}, @{E={ $MbxName };L='DisplayName'}, $IsValid, `
            @{Name="ForwardTo";Expression={[string]::join(";",($_.ForwardTo))}}
    } | Export-Csv filename.csv
    In addition to the mailbox display name, I've written this to run through all databases, and added the database to the information returned, to show how you might pull other info into your CSV.  Notice from the Get-InboxRule output (Get-InboxRule
    | Get-Member) that there is also a MailboxOwnerId property, which holds the ADObjectID of the account owning the mailbox.  However, this is the DN of the account, which isn't as clean and readable as the mailbox's DisplayName property,
    which the above returns in the $MbxName = $_.Name line of code.
    If I'm barking up the wrong tree here, feel free to let me know.

  • New-Mailbox Powershell Command

    We're in the process of deploying orchestrator to create new users\mailboxes.  Everything was working fine in our test environment through the End of January 2015.  Trying to create some new test users today and received a rather strange error:
    PowerShell invoke error: Cannot process command because of one or more missing mandatory parameters: Room
    Troubleshooting this I tried to manually run the PowerShell command that Orchestrator was running:
    New-Mailbox -Alias p015test -Name "Testerson, Evan" -UserPrincipalName "[email protected]" -Database "Mailboxes" -DisplayName "Testerson, Evan" -FirstName "Evan" -LastName
    "Testerson" -Office "Atlanta" -OranizationalUnit "OU=Employees,OU=OurUsers,DC=Child,DC=Parent,dc=com"
    And was promptly prompted to supply the values for the mandatory attribute "Room"
    I then re-ran the command without the "Office" parameter, and that was successful.
    Help (Both TechNet and Get-Help) says
    Office
    Optional
    System.String
    The Office parameter specifies the Microsoft Office attribute for this mailbox.

    Hi Dave,
    Based on my test (using Exchange 2013 server), the Office parameter can only be used when creating a room mailbox. For example, if I run the New-Mailbox -Alias test1 -Office Wuxi -Name test1 -Room cmdlet, it will create a room mailbox named test1, and the
    Location is Wuxi.
    Hope my clarification can be helpful.
    Best regards,
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]
    Amy Wang
    TechNet Community Support

  • Get-Mailbox PS command import/export csv - need help

    Greetings,
    I know this should be simple but I'm having trouble.  I have about 500 users that have left the company and I want to verify their Exchange 2010 mailbox have been disabled.  If I just run the basic command "Get-Mailbox -identity alias"
    I see all I need to see.  The Name, Alias, and ServerName (that their mailbox is on).  If I check someone whose mailbox has been disabled I get "object could not be found."  Perfect, then I know their mailbox no longer exists. 
    In trying to import a csv file of the 500 users - and export it I'm having trouble. There are a few posts on these forums for similar issues but none are working or the conditions are different.  I'm not too good and PS scripting so I am hoping someone
    can assist.  I pieced this together.
    import-csv C:\temp\DisabledMBs.csv | get-mailbox >c:\temp\DisabledMBsOutput.csv
    The csv output file is blank.  The PS screen outputs this error for each user.
    The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
        + CategoryInfo          : InvalidArgument: (@{Name=Heaton; ...er Logon Name=}:PSObject) [Get-Mailbox], ParameterBindingException
        + FullyQualifiedErrorId : InputObjectNotBound,Get-Mailbox
    I guess I'm missing something here but stuck.  Any help is greatly appreciated!
    thank you!

    If you use a CSV for input, you need to tell the Get-Mailbox command what field is the identifier.  So if you have an alias field in your CSV, you would run your command as follows:
    import-csv C:\temp\DisabledMBs.csv | % { get-mailbox $_.Alias } | Export-Csv c:\temp\DisabledMBsOutput.csv -NoTypeInformation
    BTW, you'll notice that I've also piped your output to the Export-Csv command.  If you just pipe the output of Get-Mailbox to a file with a CSV suffix, you don't get a CSV - you get a text file with only one field named "Name                     
    Alias                ServerName       ProhibitSendQuota" (note, not "Name", "Alias", "ServerName", and "ProhibitSendQuota"
    separately).

  • Powershell command to migrate Exchange 2007 mailbox databases with a legacy name, & import them into a new 2007 instance, with a new name.

    Hi All. I am currently at the later stage of provisioning a new CCR Exchange 2007 migration (to
    virtualise old Exchange 2007 hardware) for 5,000 users & have a quick question.
    I have created around 15 newly named storage groups, & have named 1 new DB per group, with the same name (let's say New-DB-1), residing within them.  The problem I have, is the old legacy DB's have different names (let's say Old-DB-1) & I need
    to import them into the new storage groups, to match the new names. So far I can import/export between old & new OK if both old & new DB names\folders etc. names marry up perfectly, but are unable to if there not the same. Does anyone have any thoughts
    on how best to tackle this, as this is one of the final hurdles stopping the migration? Many Thanks, John 

    Hi All
    Many Thanks for the feedback.
    The terminology 'migrate' was used based around the fact I will be decommissioning the old 2007 physical environment. This is after moving all DB's over to the new newly created Virtual environment that will host all roles.
    The solution I ended up using yesterday, was the following:
    1) Dismounted the relevant named DB (NEWDB) in the new environment.
    2) I then ticked the 'This database can be overwritten by a restore option' box.
    3) Copied over the old named DB (OLDDB) to the same location, & overwrote using the new name (NEWDB).
    4) Re-mounted the (NEWDB).
    5) Ran the following 2 PowerShell commands:
     Get-mailbox –database OLDDB | move-mailbox –targetdatabase NEWDB -configurationonly:$true
     Get-MailboxDatabase NEWDB | ResetSearchIndex.ps1 -force
    6) Checked to make sure the clients were working ok, in the now the new (NEWDB) environment.
    Rich: Many thanks for your PS script, which I will test with future DB moves & provide feedback
    J
    John.

  • Require assistance in Powershell script to get Mailbox count database wise with server name in Exchange 2010.

    Hi All,
    I have the below script which gives me the Exchange database names with the number of mailboxex in it.
    (get-mailboxdatabase) | foreach-object {write-host $_.name (get-mailbox -database $_.name).count}
    What i want is i also need the Server name and the DAG name (If possible) in this script so i get the output in the below format
    What i get is:
    Database name  | No of mailboxes in the DB
    XXXXX                         250
    What i want is:
    Server name   | Database name  | No of mailboxes in the DB  | DAG name (If possible)
    XXXXXX                  XXXXXXX             250                                      
    DAG01
    Can any one help me in making this script plz.
    Gautam.75801

    Hi Peter,
    Script works well and Good. But i cannot export the same in a CSV File. I used the below commands. But the output csv file is empty. I can just view the data in the monitor in the powershell window.
    Any idea how can i export this in CSV ?
    (get-mailboxdatabase) | foreach-object {write-host $_.Server, $_.name (get-mailbox -resultsize
    unlimited -database $_.name).count, $_.masterserveroravailabilitygroup} | Export-csv -Path C:\Rpt.csv
    And
    (get-mailboxdatabase) | foreach-object {write-host $_.Server, $_.name (get-mailbox -resultsize
    unlimited -database $_.name).count, $_.masterserveroravailabilitygroup} >C:\Rpt.csv
    Gautam.75801

  • How to get Systemstate Backup size using PowerShell command in Windows 2008 R2

    Hi,
    We using WBSummary command to get completed backup status.
    I need to find how much data is backed up  using powerShell command .
    Is there any way to get the details , i can see the GUI but no in command.
    Please advise
    Regards Gopi K

    Hi,
    You mentioned that you can see the system state backup size in the GUI. Does the backup size mean the amount of date transferred?
    It seems that there is no such a PowerShell to get Systemstate Backup size. You may need to you need a PowerShell scripts to do this work.
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=ITCG
    Regards,
    Mandy
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • TotalVHDCapacity attribute is returning zero in "Get-SCVMTemplate | select Name, TotalVhdCapacity" powershell command though the Vhd capacity is 20 gb in size, vmm 2012 r2

    Hi All,
    TotalVHDCapacity attribute is returning zero in "Get-SCVMTemplate | select Name, TotalVhdCapacity" powershell command though the template has Vhd capacity is 20 gb in size, vmm 2012 r2. I can create VM using this template too.
    For other templates it is returning correct value though.
    Can anyone help us understanding the root cause and the solution too.
    Thanks in advance.
    Debabrata

    I booted this drive from another computer (Asrock M3A770DE mobo) and works fine, speed with dd was ~100MB/s
    I also update bios on my first computer with Intel D945GSEJT (there is selected AHCI mode) still the same transfers with dd (~10Mb/s)
    I have no idea what to do with it now
    EDIT:
    More tests with other hdd (Samsung HD502IJ), dd on mounted NTFS partition:
    Intel D945GSEJT booted from Archlinux iso:
    hdparm: ~75 MB/s
    dd: ~10 MB/s
    Intel D945GSEJT booted from Archlinux iso, HDD connected to PCI SATA controller (Promise 378):
    hdparm: ~60 MB/s
    dd: ~10 MB/s
    Asrock M3A770DE booted from Archlinux iso:
    hdparm: ~87 MB/s
    dd: ~76 MB/s
    Asrock M3A770DE booted from Archlinux iso, HDD connected to PCI SATA controller (Promise 378):
    hdparm: ~81MB/s
    dd: ~76 MB/s
    What is broken on D945GSEJT?
    Last edited by miskoala (2012-03-30 13:47:23)

  • What is the powershell command to get the user count in Active Directory

    What is the powershell command to get the user count in Active Directory

    Get-ADuser
    REF: http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/30/powertip-single-line-powershell-command-to-list-all-users-in-an-ou.aspx
    This post is provided AS IS with no warranties or guarantees, and confers no rights.
    ~~~
    Questo post non fornisce garanzie e non conferisce diritti

  • Branchcache hosted mode Powershell commands not working - unable to get BC to do anything (2012R2)

    Hi,
    I am setting up a Branchcache environment in the lab. I've configured everything as per the MS guides, and using some knowledge imparted to me from a recent MCSA course on Server 2012R2.
    However a couple of things caused an issue before I was able to even test. I'm running the lab in a segregated OU within our existing AD forest/domain. I'll go through what I've done so far:
    Setup and configure content server (installed BC role, BC for network files feature)
    Created share on content server and enabled caching
    Setup and configured host server (installed roles etc)
    Created GPO's for servers to enable BC and enable BC hashing for enabled shares and linked to lab servers OU
    Created GPO's for clients to enable BC and linked to lab clients OU
    Attempted to run the Powershell command Enable-BCHostedServer -RegisterSCP
    When I run that I get the following error:
    Enable-BCHostedServer : Could not access the Windows Firewall configuration.
    At line:1 char:1
    + Enable-BCHostedServer -RegisterSCP
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (MSFT_NetBranchCacheOrchestrator:root/StandardCi...cheOrchestrator) [Enable-BCHostedServer],CimException + FullyQualifiedErrorId : HRESULT 0x800706d9,Enable-BCHostedServer
    So I thought I'd try and see if I could use the Get-BCStatus command. When I run that, I get the following error:
    get-bcstatus : A general error occurred that is not covered by a more specific error code.
    At line:1 char:1
    + get-bcstatus
    + ~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (MSFT_NetBranchCacheStatus:root/StandardCi...anchCacheStatus) [Get-BCStatu
    s], CimException
    + FullyQualifiedErrorId : MI RESULT 1,Get-BCStatus
    I would like to point out that we DO NOT use Windows Firewall on our servers or client machines. There is no server firewall at all (prefer to use hardware firewalls) and our client use SEP.
    The other thing I cannot get my head around is the certificate stuff. I cannot seem to find any definitive documentation that specifies whether or not it is required in an AD domain environment. All servers are automatically enrolled with a certificate from
    our CA upon joining the domain, so I cannot understand why the hosted servers would need an additional certificate to authenticate with clients trying to push cached files.
    In the lab, all servers are Windows Server 2012R2 and my test clients are Windows 8.1 and Windows 7 (which is what we have in the real-world).
    Sufficed to say, I cannot get Branchcache to work in this lab.
    Any help appreciated.

    Update:
    Upon some further research and reading, I've found a reference that lists the cmdlets that
    Get-BCStatus uses.
    I have managed to isolate the specific command that is causing it to generate an error - as shown in this screenshot.
    As you can see, it looks like the configuration is set up correctly. However, it doesn't work, and the generic error message on the
    Get-BCNetworkConfiguration cmdlet is irritating to say the least, since it leaves me at a dead end for troubleshooting.
    Here is a screenshot of the output when running the command to enable the hosted mode and register the SCP:
    Still at a loss here. My next attempt will be to strip down these servers and rebuild them off the domain and see if I get similar results.
    Thanks,
    Greg

  • Need powershell commands to get email addresses from public folder created in EAC to CSV

    Need powershell commands to get email addresses from public folder created in EAC to CSV
    1. Created Public folders via EAC - not mail enabled - just to hold contacts.
    2. Assigned owners and showed to add new contacts - then add to favorites and finally to display as address book.
    Now I need a powershell command to get those email contacts in those public folders.
    I need to view them because when we send emails to those groups (via select all) in the public folders, it is creating an NDR for 3 users saying - "..blah blah -OFFICE FAX or HOME FAX) - yet they are getting the emails.
    I suspect that their contact details are corrupt somehow and want to see what contacts are actually listed in the public folders. I already checked to see if the source of the contacts was the public folder or "my contacts" and they are not.'
    I have tried multiple get recipient commands and get public folder commands with no results in the CSV

    The only way to get that data is either via the Outlook com object or using EWS. None of the commands in the Exchange shell look inside of a folder, the most you can get with those is email addresses for mail-enabled Public folders. Here is a link that can
    get you started with how to connect to public folders via EWS, then its just enumerating the folders and looping through the items in the folders for the details of the items. 
    http://gsexdev.blogspot.com/2013/08/public-folder-ews-how-to-rollup-part-1.html
    DJ Grijalva | MCITP: EMA 2007/2010 SPA 2010 | www.persistentcerebro.com

  • Powershell script sends e-mail in ISE but not from powershell command line

    I have created a script that generates a report of all users who do not have photos in Active Directory. The script runs and sends an e-mail to a distribution list. It runs fine in ISE, but I cannot run it from command line or as a scheduled task. Any suggestions
    what I am doing wrong?
    #Starts Powershell Snap-In
    Start-Transcript -path c:\Scripts\StaffWithoutPhotos.txt
    add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010 -erroraction silentlyContinue
    $mailboxes = $null
    $mailboxes = @(Get-Mailbox -OrganizationalUnit "Staff User Accounts" -ResultSize Unlimited | Where {$_.HasPicture -eq $False})
    Write-Host $mailboxes
    $report = @()
    foreach ($mailbox in $mailboxes)
    $mbObj = New-Object PSObject
        $mbObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailbox.DisplayName
        $report += $mbObj
    Write-Host "Diagnostic Output"
    Write-Host "Before Mailbox value check"
    Write-Host $report
    Write-Host "After Mailbox Value check"
    if ($mailboxes -ne $null)
        Write-Host $report
        #Send the report generated to the e-mail list specified above
        $style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
        $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
        $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
        $style = $style + "TD{border: 1px solid black; padding: 5px; }"
        $style = $style + "</style>"
        #Start-Sleep -Seconds 5
        $smtpserver = "MAIL.contoso.com"
        $msg = new-object Net.Mail.MailMessage
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $msg.From = "[email protected]"
        $msg.To.Add("[email protected]")
        #$msg.To.Add("[email protected]") #Used for testing
        $msg.Subject = "Staff without Photos report"
        $msg.Body = "This report contains the list of users who do not currently have photos."
        $msg.Body += "<p>"
        $msg.Body += "After photos are available for these users please submit a request to have their accounts updated or send an e-mail to <a href='mailto:[email protected]?Subject=Staff%20Photo%20Updates' target='_top'> [email protected]
    </a> with <b>Staff Photo Updates</b> in the subject."
        $msg.Body += "<p>"
        $msg.Body += "This report runs on Fridays and will only send a message if we have Staff without Photos. For more information please contact your systems administrator."
        $msg.Body += "<p>"
        $msg.Body += $Report | ConvertTo-Html -Head $Style
        $msg.IsBodyHTML = $true
        $smtp.Send($msg)
    Stop-Transcript

    So after researching further and not receiving any more replies I decided to rewrite the script and attempt to use the send-mailmessage function. I have been unable to determine the reason for the original not script not working. We use a very similar script
    to my original code which works to generate a report and e-mail that report as an attachment and it works without any problems.
    After re-writing the script and using the send-mailmessage function I was able to get this report to work as expected. This has now been set up as a scheduled task to run on a server once a week. Here is the final code:
    Start-Transcript -path c:\Scripts\StaffWithoutPhotos.txt
    #Starts Powershell Snap-In
    add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010 -erroraction silentlyContinue
    $mailboxes = $null
    $mailboxes = @(Get-Mailbox -OrganizationalUnit "contoso Staff User Accounts" -ResultSize Unlimited | Where {$_.HasPicture -eq $False})
    Write-Host $mailboxes
    $report = @()
    foreach ($mailbox in $mailboxes)
    $mbObj = New-Object PSObject
        $mbObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailbox.DisplayName
        $report += $mbObj
    Write-Host "Diagnostic Output"
    Write-Host "Before Mailbox value check"
    Write-Host $report
    Write-Host "After Mailbox Value check"
    if ($mailboxes -ne $null)
        Write-Host $report
        #Send the report generated to the e-mail list specified above
        $style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
        $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
        $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
        $style = $style + "TD{border: 1px solid black; padding: 5px; }"
        $style = $style + "</style>"
        $smtpserver = "MAIL.contoso.com"
        $smtpFrom = "[email protected]"
        $smtpTo = "[email protected]
        $messageSubject = "Staff without Photos report"
        $Body = "This report contains the list of users who do not currently have photos."
        $Body += "<p>"
        $Body += "After photos are available for these users please submit a request to the Help Desk to have their accounts updated or send an e-mail to <a href='mailto:[email protected]?Subject=Staff%20Photo%20Updates' target='_top'> [email protected]
    </a> with <b><u>Staff Photo Updates</b></u> in the subject."
        $Body += "<p>"
        $Body += "This report runs on Fridays and will only send a message if we have Staff without Photos. For more information please contact your systems administrator."
        $Body += "<p>"
        $Body += $Report | ConvertTo-Html -Head $Style
        #Send the report
        send-mailmessage -from "$smtpFrom" -to "$smtpTo" -subject "$messageSubject" -body "$Body" -smtpServer "$smtpserver" -BodyAsHtml
    Stop-Transcript

  • Powershell Command to permanently delete items in ALL users Deleted Items folder older than X days.

    Does anyone know a powershell command that can be run on Exchange 2010 SP1 that will permanently delete mail in the deleted items folder older than X days for ALL users in a specific database? This should include any user created subfolders in deleted items
    also.
    I know that seems bizarre to have user created subfolders in deleted items but we have found that users have discovered that if they create subfolders then their deleted items dont get purged at the regular retention period time.
    Thank You.

    Hi,
    For Exchange 2010 SP1, we can use search-mailbox and new-mailboxexportrequest to delete message in certain folder.
    Understanding Exchange Search
    http://technet.microsoft.com/en-us/library/bb232132.aspx
    Xiu Zhang
    TechNet Community Support

  • Database filter not working in Powershell command

    I'm trying to run a powershell query to find what users have a retention policy applied to them. However, I'm also trying to filter out a database that contains service accounts, which should be excluded. The issue I'm running into is that the database filter
    doesn't seem to be working. if I use "database -ne mydb" I get all accounts, including from that db. If I use "database -eq mydb" I get zero results. I can see on the MS doc about filterable properties that this is one of them that should
    work with get-mailbox.
    http://technet.microsoft.com/en-us/library/bb738155(v=exchg.150).aspx
    Can anybody point me towards what I have wrong in this command:
    Get-Mailbox -ResultSize unlimited -Filter {(ManagedFolderMailboxPolicy -eq $null) -and (database -ne "Service Accounts - DAG")} | fl name,database
    I'm running exchange 2010 but I can't seem to find the right forum for that, is it in the archives somewhere?
    Thanks in advance,
    Joel

    Belinda,
    Thanks for the reply. I probably didn't write my end goal as clearly as I should have. I am aware of the meaning of eq and ne and I have them applied properly. I'm trying to find everyone who does not have any ManagedFolderMailboxPolicy and who is not in
    the service account DB. That syntax isn't my issue. What is my issue is that the database filter simply isn't getting applied properly. Let me give you another example.
    If I write Get-Mailbox -Database 'Service Accounts - DAG' I return only the users from that DB.
    If I write Get-Mailbox -Filter {database -eq 'Service Accounts - DAG'} I get zero results.
    If I write Get-Mailbox -Filter {database -ne 'Service Accounts - DAG'} I get every user in my organization, including the ones in the service accounts DB, which I just tried to filter out.
    I thought perhaps I had misspelled the actual name of the property or of the database so I did a Get-Mailbox for a single user and then "cut/paste" the proper fields into my commands. So it appears that somehow the name of the DB is causing it fail when
    it's in the Filter section, even though that same syntax works when I use it as it's own switch.
    I would be happy to find a different way to write this. Since I know it works when I use the -Database command, I could just do that and then pipe it to the rest of the command. The issue I have though is that I have a couple dozen DBs and I only want
    to filter out 1 so I would much rather use a "not equal" command.

  • How to Customize powershell command to desired output

    Hello,
    By below command I got below output.  Please let me know how can I get User1102 get printed multiple times in each row along with Folder Name , FolderPath, ItemsInFolder, FolderSize
    $bg = Get-Mailbox User1102
    Get-MailboxFolderStatistics | FT $bg.Alias, Name, FolderPath, @{n= "FolderSize" ; e = {$_.FolderSize.Tobytes()}}
    User1102                    Name                       
    FolderPath                                ItemsInFolder                
    FolderSize
                                Top of Information Store    /Top of Information Store                            
    0                          0
                                Calendar                   
    /Calendar                                            
    4                       8055
                                Contacts                   
    /Contacts                                            
    2                        552
                                Conversation Action Sett... /Conversation Action Set...                          
    0                          0
                                Deleted Items              
    /Deleted Items                                        0                         
    0
                                Drafts                     
    /Drafts                                              
    0                          0
                                Inbox                      
    /Inbox                                              
    10                      63897
                                Inbox01                    
    /Inbox/Inbox01                                        1                     
    57464
                                Journal                    
    /Journal                                             
    0                          0
                                Junk E-Mail                
    /Junk E-Mail                                         
    0                          0
                                News Feed                  
    /News Feed                                           
    0                          0
                                Notes                      
    /Notes                                               
    1                        396
                                Outbox                     
    /Outbox                                              
    0                          0
                                Quick Step Settings         /Quick Step Settings                                 
    0                          0
                                RSS Feeds                  
    /RSS Feeds                                           
    0                          0
                                Sent Items                 
    /Sent Items                                          
    2                       7859
                                Suggested Contacts          /Suggested Contacts                                  
    0                          0
                                Sync Issues                
    /Sync Issues                                         
    0                          0
                                Conflicts                  
    /Sync Issues/Conflicts                                0                         
    0
                                Local Failures              /Sync
    Issues/Local Failures                           0                         
    0
                                Server Failures             /Sync
    Issues/Server Fail...                           0                         
    0
                                Tasks                      
    /Tasks                                               
    1                       3542
                                Recoverable Items           /Recoverable Items                                   
    0                          0
                                Deletions                  
    /Deletions                                           
    1                       3443
                                Purges                     
    /Purges                                              
    0                          0
                                Versions                   
    /Versions                                            
    0                          0

    What is happening is that you are specifying User1102 as a property name via $bg.alias in the Format-Table an also Get-MailboxFolderStatistics is grabbing everything because you have not supplied a mailbox. Try this instead:
    Get-Mailbox User1102 | Get-MailboxFolderStatistics |
    FT Alias, Name, FolderPath, @{n= "FolderSize" ; e = {$_.FolderSize.Tobytes()}}
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

Maybe you are looking for