Archive

Posts Tagged ‘Exchange 2007’

Get-Inboxrule – easy way to get rules from mailboxes

November 11, 2013 Leave a comment

An easy command for checking if there are any automatic rules on an Exchange Mailbox is to use PowerShell and Get-InboxRule, this commandlet will give you an output of all the rules and what the rule does with emails that`s arriving in the mailbox.

Example: Get-InboxRule -Mailbox “account” | Select Name, Description | fl

exc_ps

Usefull PowerShell commands


PowerShell is a powerfull tool when administrating Microsoft products and personally i like using Windows PowerShell ISE that is an powershell tool provided from Microsoft.
It can be found on Windows 8, Windows Server 2012, Windows Server 2008 R2 and Windows Server 2008.

Here are som usefull PS one-liners that i use often 🙂

# Connect to remote server
Enter-PSSession “yourdomaincontroller”

# Disconnect remote session
exit-pssession

# Import the ActiveDirectory cmdlets
Import-Module ActiveDirectory

# List available snapins on your system
Get-PSSnapin

# Add snapins examples
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin # Exchange 2007
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 # Exchange 2010
Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager # WMM (Hyper-V)
Add-PSSnapin Quest.Activeroles.ADManagement # Quest commandlets

# List registered snapins
Get-PSSnapin -Registered

# List Active Directory Computers that have never logged in within time span (-TimeSpan 365.00:00:00, this is 365 days), first line counts the result, second line shows the result, line three sends output to an txt file.
(Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 35.00:00:00 | select name | sort-object name).count
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 90.00:00:00 | select name | sort-object name
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 65.00:00:00 | select name | sort-object name | out-file c:\temp\computers.txt

# The following example demonstrates how to find user accounts that have been inactive for 90 days:
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 | where {$_.ObjectClass -eq ‘user’} | FT Name,ObjectClass –A

# The following example demonstrates how to find inactive user accounts
Search-ADAccount -AccountInactive | where {$_.ObjectClass -eq ‘user’} | FT Name,ObjectClass –A

# The following example demonstrates how to find user accounts that have been inactive since 01/01/2013
Search-ADAccount -AccountInactive -DateTime 01/04/2013 | where {$_.ObjectClass -eq ‘user’} | FT Name,ObjectClass –A

# The following example demonstrates how to find locked-out users in your domain
Search-ADAccount -LockedOut | where {$_.ObjectClass -eq ‘user’} | FT Name,ObjectClass -A

#The following example demonstrates how to unlock the user account U1 in the organizational unit (OU) Test in your domain.
Unlock-ADAccount -Identity “CN=U1,OU=Test,DC=FABRIKAM,DC=COM”

# The following example demonstrates how to unlock the user account U1 in your domain.
Unlock-ADAccount -Identity U1

# Reset pasword on spesific user where “bob” is changed to the username of the user you want to change password on
Set-ADAccountPassword -Identity bob -Reset

How to clear move-requests in Exchange 2007/2010

September 11, 2012 Leave a comment

Run this command in powershell to clear completed move-requests

Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest

Exporting distribution list membership to Excel


Easy one-liner for exporting members of a distribution list:

Get-DistributionGroupMember -identity "company-dl" Export-Csv C:\MyFile.Csv

you can also use “-not” that gives you a nice csv file

Get-DistributionGroupMember -identity "company-dl" Export-Csv C:\MyFile.Csv -not

Exchange 2007/2010 – Hide users from global adress list (GAL)


Hide all users:

1, Connect PowerShell to Exchange.
2, Run the following command:
Get-Mailbox Alias | Set-Mailbox -HiddenFromAddressListsEnabled $True
Change Alias to your user’s information.

Hide users in a spesific OU

1, Connect PowerShell to Exchange.
2, Run the following command:
get-mailcontact -OrganizationalUnit “contoso.com/path/to/ou” | Set-mailContact -HiddenFromAddressListsEnabled $true -whatif

List users and size of mailbox in Exchange 2007 and 2010 with Powershell


Get-Mailbox | Get-MailboxStatistics | select-object DisplayName, {$_.TotalItemSize.Value.ToMB()}

Find emails with Powershell commandlets

December 19, 2011 Leave a comment

Get-MessageTrackingLog -start “12/18/2011 08:00” -Sender user@domain.com | Format-List sender, Recipients, timestamp, MessageSubject

Get-MessageTrackingLog -MessageSubject Testsubject

%d bloggers like this: