Powershell to pull Application Event logs with Event Id 1221

Application Event ID 1221 gives the details of the white space on the Exchange Database.  With the amount of white space we can determine if we wanted to do a defrag on the store or not. Below powershell helps you to pull all the application events with id 1221 from last 2 days

$2DaysAgo = [DateTime]::Now.AddDays(-2)
$Events = Get-Eventlog Application | Where {($2DaysAgo -le $_.TimeWritten)} | ?{$_.eventid -eq “1221”}
$Events

Powershell to get the Home Directory Path

If we wanted to find Home Directory Path of the users in the Orginization then below commands helps you to pull the data

Get-QADUser | select DisplayName,Email,HomeDirectory | Export-Csv c:\HomeDirectory.csv

Command to get the Home Directory for the given list of users and export the result to CSV

get-content C:\users.txt | select DisplayName,Email,HomeDirectory | Export-Csv c:\HomeDirectory.csv

 

 

Powershell to Manager ManagedFolderpolicy on user accounts

Powershell to manage Managedfolderpolicy on user accounts

Below powershell to apply -Managedfolderpolicy new user mailbox at the time of new mailbox creation

New-Mailbox -Name $DName -Database $Database -UserPrincipalName $PrincipalName -FirstName $FName -LastName $LName -Alias $Aliasname -Password $passwd -ResetPasswordOnNextLogon $true -SamAccountName $Aliasname -ManagedFolderMailboxPolicy $MPolicy

Below  powershell to apply folderpolicy to set to all the mailbox in the orginization

$Folderpolicy = “Policyname”
get-mailbox -ResultSize unlimited |Set-Mailbox -Identity -ManagedFolderMailboxPolicy $Folderpolicy

Powershell to remove folderpolicy to specific users in the DL

Get-DistributionGroupMember $group | Set-Mailbox -Identity -ManagedFolderMailboxPolicy $null

Powershell to get the number of mails in the Inbox and number of unread emails in Inbox

Powershell using Outlook.Application to pull out the mailbox details

$outlook = new-object -com Outlook.Application
$session = $outlook.Session
$session.Logon()
$inbox = $outlook.session.GetDefaultFolder(6)
$unreadCount = (%{$inbox.Items | where {$_.UnRead}}).Count
Write-Host $unreadCount
$ItemCount = (%{$inbox.Items }).Count
Write-Host $ItemCount

 

Troubleshooting Exchange 2007 Store Log/Database growth issues

 

One of the Interesting Issue with Many Exchange administrator faces and finds it difficult to address is Store Log/Database growth issue. Below is the link which has step by step instruction help you to find case of Database growth and logs in Exchange 2007 Mailbox Server

 

http://blogs.technet.com/mikelag/archive/2009/07/12/troubleshooting-store-log-database-growth-issues.aspx

Powershell to get Mailboxes lists who’s Mailbox Quota limits is not get as Default

For various reason we increase the mailbox of the user  or reduce from the default size which is applied throught mailbox store policy. If you want to get the list of users who is not set to default Quota limits. Below command helps you to get the same

Get-Mailbox -ResultSize unlimited |Where{($_.UseDatabaseQuotaDefaults -eq $false)}

Below command gets you the list of mailbox who Quota limits is not get set as default in a given Exchange sever

Get-Mailbox -ResultSize unlimited |Where{($_.UseDatabaseQuotaDefaults -eq $false) -and ($_.Servername -eq “<servername>”)}

Below command to get the list of mailbox who quota limit is get set as default in a given Exchange Store

Get-Mailbox -ResultSize unlimited |Where{($_.UseDatabaseQuotaDefaults -eq $false) -and ($_.Database -eq “servername\SG\Store”)}

Powershell to get the list of Hidden Mailbox and DL in the Exchange Organization

Below powershell helps you the get the list of the entire Hidden mailbox in the Exchange Organization

Get-Mailbox -ResultSize unlimited |Where{$_.HiddenFromAddressLissEnabled -eq $true}

If you wanted to the get the list of Hidden maibox from the specific Exchange server then

Get-Mailbox -ResultSize unlimited |Where{($_.servername -eq “<servername>”) -and ($_.HiddenFromAddressListsEnabled -eq $true)}

If you get the list of Hidden Mailboxes from the specific mailbox store then please use below command

Get-Mailbox -ResultSize unlimited |Where{($_.Database -eq “Server\SG\Store”) -and ($_.HiddenFromAddressListsEnabled -eq $true)}

Powershell to command to get the list of Hidden DL from the Orgnization

Get-DistributionGroup -resultsize unlimited| ?{$_.HiddenFromAddressLissEnabled -eq $true}

Powershell to Export list of Permission given to the mailbox to CSV file

If we need to get the list users who has access to the specific mailbox then below powershell help you the fetch the same. It gets all the details that have mailbox permission to the user krishna.k. It will only get the user accounts which are not inherited to the mailbox. User Permission which is given explicitly given to the mailbox

$user =”Krishna.k”
get-mailbox -identity $user| Get-MailboxPermission | ?{($_.IsInherited -eq $False) -and -not ($_.User -match “NT AUTHORITY”)}

Below powershell commming will export all the user mailbox permission of the mailbox to the CSV file. It exports all the mailbox permission which are explicit permission

Get-mailbox | Get-MailboxPermission | ?{($_.IsInherited -eq $False) -and -not ($_.User -match “NT AUTHORITY”)} |Select User,Identity,@{Name=”AccessRights”;Expression={$_.AccessRights}} | Export-csv C:\mailboxPermission.csv