Tuesday, June 8, 2010

My Exchange PowerShell Comands



Remove disconnected mailboxes
Get-MailboxStatistics -database “GULFSIP-SRV1\"Mailbox Database"” | where {$_.disconnectdate -ne $null} | foreach {Remove-mailbox -database $_.database -storemailboxidentity $_.mailboxguid}



List by size Mailboxes:
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount





BULK IMPORT
Import-csv Big-List-of-users.csv | %{get-mailbox $_.emailAddress | set-mailbox -HiddenFromAddressListsEnabled $true/$false}

Import-Csv contacts.csv | ForEach { New-MailContact -Name $_.displayName -Firstname $_.Firstname -Lastname $_.Lastname -ExternalEmailAddress $_.Emailaddress -OrganizationalUnit "MyDomain.com/Contacts" }

CREATE CERTIFICATION :
New-ExchangeCertificate -GenerateRequest -SubjectName "c=KW, o=GULFGATE, cn=gulfgate.com" -DomainName gulfgate.com, webmail.gulfgate.com -PrivateKeyExportable $true -Path E:\Backup\Configurations\Exchange2007\certrequest2.txt
===========
Thumbprint Services Subject
---------- -------- -------
A8A645B773E790010E8A60AD12117CD086C5F9B9 ..... CN=gulfgate.com, O=GULF...
===========
Import-ExchangeCertificate -path "C:\webmail.DOMAIN.com.crt"

Enable-ExchangeCertificate -Thumbprint A8A645B774E720010E8A60AD12117CD086C5F9B9 -Services:"SMTP, IIS"
CREATING SEND CONECTOR:new-SendConnector -Name 'Send connector to Internet' -Usage 'Internet' -AddressSpaces 'smtp:*;1' -DNSRoutingEnabled $true -UseExternalDNSServersEnabled $false -SourceTransportServers 'gulfsip-01'

DYNAMIC GROUP:
new-DynamicDistributionGroup -Name 'KNPC' -IncludedRecipients 'AllRecipients' -OrganizationalUnit 'gulfsip.kw/Gulf/Gate/KNPC' -Alias 'KNPC' -RecipientContainer 'gulfsip.kw/Gulf/Gate/KNPC'


ENABLE/DISABLE IMAP/POP
==================================================================
Set-CASMailbox -Identity 'Esraa@gulf.com' -PopEnabled $false
Set-CASMailbox -Identity 'Esraa@gulf.com' -IMAPEnabled $false
==================================================================

BULK CONTACT INSERT:
New-MailContact -ExternalEmailAddress 'SMTP:moustafa@gulf.com' -Name 'Mostafa' -OrganizationalUnit 'gulfsip.kw/Gulf/ExternalContacts/GulfSip' -FirstName 'Mostafa' -LastName 'Magdy'

HIDE ALL USERS FROM ADDRESS LIST:
get-mailcontact * | set-mailcontact -hiddenfromaddresslistsenabled $true -ErrorAction SilentlyContinue -ErrorVariable +hidecontactserr;

INSTALL ANTI SPAM AGENT:
[PS] C:\Program Files\Microsoft\Exchange Server\Scripts>.\install-AntispamAgents.ps1

KNOW SEND CONNECTOR DETAILS:Get-SendConnector |fl
Get-EventLogLevel
Set-EventLogLevel -Identity MSExchangeTransport\SmtpSend -Level expert

MAILBOX QUOTA:
http://www.simple-talk.com/sysadmin/powershell/managing-exchange-2007-mailbox-quotas-with-windows-powershell/
Set-Mailbox amir -IssueWarningQuota 3000MB -ProhibitSendQuota 3000MB –UseDatabaseQuotaDefaults $false
Get-MailboxStatistics "ayman@gulf.com" | fl TotalItemSize
Set-Mailbox "ayman@gulf.coM" -IssueWarningQuota 2700MB -ProhibitSendQuota 3000MB –UseDatabaseQuotaDefaults $false

NEW USER:


IF ALREADY EXISTS:

Enable-Mailbox -Identity 'gulf.kw/Users/amany' -Alias 'amany' -Database 'GULFSIP-01\First Storage Group\Mailbox Database'
basma@gulf.com Eng. B
dsadd user CN=Basma,CN=users,DC=gulfsip,DC=kw -samid "Basma" -display "Basma" -pwd BBakry -email basma@gulf.com
Enable-Mailbox -Identity 'gulf.kw/Users/basma' -Alias 'basma' -Database 'GULFSIP-01\First Storage Group\Mailbox Database'

SET SEND SIZE LIMIT:
Get-SendConnector | select gulfsip-01

Get-ReceiveConnector | select gulfsip-01


Set-SendConnector -identity "Send connector to Internet" -MaxMessageSize 30MB

Set-ReceiveConnector -identity "Send connector to Internet" -MaxMessageSize 30MB




Organizational Limits
====================
Set-TransportConfig -MaxReceiveSize 30MB

Set-TransportConfig -MaxSendSize 30MB

Set-ReceiveConnector -identity "Client GULFSIP-01" -MaxMessageSize 30MB

Set-ReceiveConnector -identity "Default GULFSIP-01" -MaxMessageSize 30MB
get-mailbox | set-mailbox -maxsendsize 30MB



OWA TIME OUT:
set-ItemProperty ‘HKLM:\SYSTEM\CurrentControlSet\Services\MSExchangeOWA’ -name TrustedClientTimeout -value 30 -type dword

---------------------------------------------------------------------------
Add a mailbox/contact/mailuser
(e.g. John Doe) to a group (e.g. AllStudents) is:
Add-DistributionGroupMember -Identity AllStudents -Member 'John Doe'
Remove a mailbox/contact/mailuser (e.g. John Doe) from a group (e.g. AllStudents) is:
Remove-DistributionGroupMember -Identity AllStudents -Member 'John Doe



*******************
Trouble Shooting
*******************
Exchange 2010 , Event ID 2501
The site monitor API was unable to verify the site name for this Exchange computer - Call=DsGetSiteNameW Error code=800703e5. Make sure that Exchange server is correctly registered on the DNS server.
---->

Run:
[PS] C:\Windows\system32>nltest /dsgetsite
Getting DC name failed: Status = 1919 0x77f ERROR_NO_SITENAME
[PS] C:\Windows\system32>nltest /server:ServerName /dsgetsite
Getting DC name failed: Status = 1722 0x6ba RPC_S_SERVER_UNAVAILABLE
if you got the above errors , then follow the below:
 
  1. Open RegEdit
  2. Browse to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters
  3. Create a REG_SZ entry with the name SiteName
  4. Set the Value to the site name of the site the Schema Masters in
  5. Restart Netlogon service
  6. Restart MSExchangeADTopology , it will restart all dependent services 
  7. Have Fun :)
 [PS] C:\Windows\system32>nltest /server:HC-01 /dsgetsite
Default-First-Site-Name
The command completed successfully
[PS] C:\Windows\system32>nltest /dsgetsite
Default-First-Site-Name
The command completed successfully
[PS] C:\Windows\system32>

Monday, June 7, 2010

Dsquery / Dsget Active directory

dsquery user -name "Ahmad Sabry El Gendi" | dsget user -title -tel -samid -Email