Sunday, October 26, 2014

Exchange Powershell Script

Exchange Control Panel (ECP):

 Get-EcpVirtualDirectory | fl *url*, ide*

Set-EcpVirtualDirectory –Identity “TLCAS01\ecp (Default Web Site)” –ExternalUrl https://mail.msexchangequery.com/ecp

Autodiscover:
Get-ClientAccessServer | fl *uri*
Set-ClientAccessServer –Identity TLCAS01 –AutoDiscoverServiceInternalUri https://autodiscover.msexchangequery.com/autodiscover.xml

Exchange ActiveSync (EAS):
Get-ActiveSyncVirtualDirectory | fl *url*, ide*
Set-ActiveSyncVirtualDirectory –Identity “TLCAS01\Microsoft-Server-ActiveSync (Default Web Site)” –ExternalUrl https://mail.msexchangequery.com/ActiveSync

Exchange Web Services (EWS):
Get-WebServicesVirtualDirectory | fl *url*, ide*
Set-WebServicesVirtualDirectory –Identity “TLCAS01\EWS (Default Web Site)” –ExternalUrl https://mail.msexchangequery.com/Exchange.asmx

Offline Address Book (OAB):
Get-OabVirtualDirectory | fl *url*, ide*,pol*
Set-OabVirtualDirectory –Identity “TLCAS01\OAB (Default Web Site)” –ExternalUrl https://mail.msexchangequery.com/OAB –PollInterval 60

Outlook Web App (OWA):
Get-OwaVirtualDirectory | fl *url*, ide*
Set-OwaVirtualDirectory –Identity “TLCAS01\OWA (Default Web Site)” –ExternalUrl https://mail.msexchangequery.com/OWA

PowerShell:
Get-PowerShellVirtualDirectory | fl *url*, ide*
Set-PowerShellVirtualDirectory –Identity “TLCAS01\PowerShell (Default Web Site)” –ExternalUrlhttps://mail.msexchangequery.com/powershell

Enable Outlook Anywhere:
Enable-OutlookAnywhere –Server TLCAS01 –ExternalHostname mail.msexchangequery.com –InternalHostname tlcas01.msexchangequery.com –ExternalClientAuthenticationMethod Basic –InternalClientAuthenticationMethod Ntlm –IISAuthentication Ntlm –SSLOffloading:$false
Get-OutlookAnywhere –Server TLCAS01
Get-AcceptedDomain
New-AcceptedDomain –Name 
msexchangequery.com –DomainName msexchangequery.com –DomainType Authoritative
Get-EmailAddressPolicy
Get-EmailAddressPolicy | fl

Send & Receive Connector
Get-ReceiveConnector
Get-ReceiveConnector | fl
Set-ReceiveConnector –Identity “TLCAS01\Default Frontend TLCAS01” –MaxMessageSize 30MB
Get-ReceiveConnector | fl ide*,maxmes*
Get-SendConnector
Get-SendConnector| fl
New-SendConnector –Name “Outbound” –AddressSpaces ‘*’ –SourceTransportServers TLMB01 –MaxMessageSize 30MB

New-SendConnector –Name “Outbound” –AddressSpaces ‘*’ –SourceTransportServers TLMB01 –
MaxMessageSize 30MB –DNSRoutingEnabled:$false –SmartHosts “10.10.10.10”
New-SendConnector –Name “Outbound” –AddressSpaces ‘*’ –SourceTransportServers TLMB01 –
MaxMessageSize 30MB –DNSRoutingEnabled:$false –SmartHosts “10.10.10.10” –FrontEndProxyEnabled:$True

Get-SendConnector| fl ide*,maxmes*
Globaladdresslis
Get-Globaladdresslist | update-Globaladdresslist
Get-Addresslist | Update-Addresslist
New-GlobalAddressList -Name "gal" -RecipientFilter {(MemberOfGroup -eq 'cn=<GROUP NAME>,OU=Exchange Groups,DC=ggncloud,DC=internal')}
Update-GlobalAddressList -Identity "gal"
update-AddressList -Identity '\All Contacts

Move Request
New-MoveRequest -Identity 'tony@msexchangequery.com' -TargetDatabase DB01 –WhatIf    
New-MoveRequest -Identity 'tony@msexchangequery.com' -TargetDatabase DB01 -BadItemLimit  100
New-MoveRequest -Identity 'tony@msexchangequery.com' -TargetDatabase DB01 -BadItemLimit 200 -AcceptLargeDataLoss
New-MoveRequest -Identity 'Kweku' -PrimaryOnly -TargetDatabase "DB01" -BadItemLimit 100 –AcceptLargeDataLoss
Get-MoveRequest –MoveStatus queued |Get-MoveRequestStatistics | ft -auto alias,Status,TotalMailboxSize,PercentComplete,TargetDatabase,TotalInProgressDuration
Suspend-MoveRequest -Identity Shaji_John@msexchangequery.com -SuspendComment "Resume suspended request.after @12 PM Today"
Get-MoveRequest -MoveStatus queued | Suspend-MoveRequest -SuspendComment "Resume suspended request.after completion Domino & Cadista"
Get-MoveRequest -MoveStatus suspended | Resume-MoveRequest
Get-LogonStatistics -Database DB-MBX-2
Get-LogonStatistics -Identity shiva_prasad@msexchangequery.com
Get-MoveRequest -MoveStatus failed -TargetDatabase DB-mbx1
Get-MoveRequest –MoveStatus Rajesh_Kajalkar@msexchangequery.com
Get-MoveRequest -TargetDatabase DB-MBX-M8 | Suspend-MoveRequest -SuspendComment "Resume @ 12 PM."
Suspend-MoveRequest -TargetDatabase DB-MBX-M8 -SuspendComment "Resume @ 12 PM."
(Get-MoveRequest  –MoveStatus queued).count
(Get-MailboxStatistics -Database DB-MBX-3).Count
Get-Mailbox -Database DB-MBX-G7 | Get-MailboxStatistics | Select-Object DisplayName, ServerName, Database,
TotalItemSize, ItemCount, StorageLimitStatu

MailboxStatistics
Get-MailboxStatistics -Server ggncloud | Where {$_.DisconnectDate -ne $null} | Format-Table DisplayName,Database

Get-MailboxStatistics -Server HNLMBX01 | Where {$_.DisconnectDate -ne $null} | Format-Table DisplayName,DisconnectDate 
Get-MailboxStatistics -Server HNLMBX01 | Where-Object {$_.DisconnectDate
-gt (Get-Date).AddDays(-7)} | Format-Table displayName,ServerName,
DatabaseName, TotalItemSize -Autosize

Get-MailboxStatistics -Database db3 | where {$_.LastLogonTime -lt
(Get-Date).AddDays(-7)}} | Format-Table displayName,lastlogontime,
lastloggedonuseraccount,ggncloud

Get-MoveRequestStatistics -database db3
Get-Mailbox -Database db3 | New-MoveRequest -TargetDatabase db4
Get-LogonStatistics -Server ggncloud
TransportRule
New-TransportRule -Name 'TS Rule1' -Comments 'transportrule' -Priority '0' -Enabled $true -From 'shailendra@msexchangequery.com' -DeleteMessage $true -ExceptIfFrom 'john@msexchangequery.com'
DatabaseAvailabilityGroup
Restore-DatabaseAvailabilityGroup –Identity DAG1 –ActiveDirectorySite ggncloud
Remove-DatabaseAvailabilityGroupServer -MailboxServer 'RAKESH' -Identity 'DAG2
Get-MailboxDatabase -Status | Sort-Object name | Format-Table Name, DatabaseSize, AvailableNewMailboxSpace
Get-MailboxDatabase -Identity databasename -Status | Format-Table Name, DatabaseSize, AvailableNewMailboxSpace
Get-DatabaseAvailabilityGroupNetwork -Identity DAG2 | fl name, MapiAccessEnabled
Suspend-MailboxDatabaseCopy -Identity DB1\MBX2 -ActivationOnly
Resume-MailboxDatabaseCopy -Identity DB1\MBX2
Set-MailboxServer -Identity MailboxServer–DatabaseCopyAutoActivationPolicy
Set-MailboxServer -Identity MailboxServer–DatabaseCopyAutoActivationPolicy
DynamicDistributionGroup
New-DynamicDistributionGroup -Name "All Research" -IncludedRecipients ‘MailboxUsers’ 
-ConditionalDepartment ‘Research’ -OrganizationalUnit ‘its’-Alias ‘AllResearch’ 
new-DynamicDistributionGroup -Name 'DDG-ITS' -RecipientContainer 'corp.mld/ITS' -IncludedRecipients 'AllRecipients' -OrganizationalUnit 'corp.mld/ITS' -Alias 'DDGits'
Set-DynamicDistributionGroup -Name "All Research" -MaxReceiveSize 75KB

New Mailbox
New-Mailbox -Name "System Administrator" -FirstName "System" -LastName "Administrator" -DisplayName "System Administrator" -Alias "sysadmin" -SamAccountName "sysadmin" -organizationalUnit "Test" -Database "MBXDB3" -UserPrincipalName sysadmin@msexchangequery.com

New-Mailbox -Name:'Help Desk' -OrganizationalUnit:'corp.mld' -Database:'DB01' -UserPrincipalName:'helpdesk@msexchangequery.com' -Shared

Mailbox Permission
Add-MailboxPermission helpdesk -User:'rakesh' -AccessRights:FullAccess
Add-ADPermission helpdesk -User:'rakesh' -ExtendedRights:Send-As -AccessRights:ReadProperty, WriteProperty -Properties:'Personal Information'
New-Mailbox -Alias amit -Name "amit raj" -FirstName amit -LastName raj -DisplayName "amit raj" -UserPrincipalName 
amitraj@ msexchangequery.com  -OrganizationalUnit Users
New-Mailbox -Name:'tss' -OrganizationalUnit:'corp.mld' -Database:'DB02' -UserPrincipalName:'tss@msexchangequery.com' -Shared
Get-Mailbox -RecipientTypeDetails sharedmailbox
Set-Mailbox tss -Type Room

Add-MailboxPermission tss -AccessRights FullAccess -user rakesh
Set-Mailbox its -GrantSendOnBehalfTo amit

Add-ADPermission helpdesk -ExtendedRights Send-As -user rakesh
Add-ADPermission user -User "DomainBUser" -Extendedrights "Send As"

Set-Mailbox -Identity amit -DeliverToMailboxAndForward $true -ForwardingAddress
rakesh@msexchangequery.com 
Get-Mailbox | Get-MailboxFolderStatistics | Select Identity,FolderPath,FolderSize,ItemsInFolder | Sort-Object ItemsInFolder | fl
Add-MailboxPermission testmbx -AccessRights FullAccess -user jaredz
Set-Mailbox testmbx -GrantSendOnBehalfTo jaredz
Add-ADPermission testmbx -ExtendedRights Send-As -user jaredz
Add-ADPermission user -User “DomainB\User” -Extendedrights “Send As”
“Set-Mailbox “USER” -GrantSendOnBehalfTo “DomainB\User”
Get-Globaladdresslist | update-Globaladdresslist
Get-Addresslist | Update-Addresslist
Add-MailboxFolderPermission -Identity marry:\Calendar -User harry -AccessRights Reviewer
Get-MailboxFolderStatistics -Identity marry
Get-MailboxFolderPermission -Identity marry:\Calendar
Get-MailboxFolderStatistics -Identity marry -FolderScope Calendar | Select-Object -First
Get-MailboxFolderPermission -Identity marry:\Calendar
Set-MailboxFolderPermission -Identity marry:\Calendar -User harry -AccessRights Owner
Get-MailboxFolderPermission -Identity marry:\Calendar
Set-MailboxFolderPermission -Identity marry:\inbox -User harry -AccessRights Owner
Set-MailboxFolderPermission -Identity marry:\task -User harry -AccessRights Owner
Set-MailboxFolderPermission -Identity marry -User harry -AccessRights Owner
Update-Calendarpermission -identity marry -User harry -Permission ReadItems
Set-MailboxFolderPermission -Identity LasseP:\Calendar -User Eva -AccessRights Owner
Add-MailboxFolderPermission -Identity LasseP:\Calendar -User Eva -AccessRights Reviewer
Get-MailboxFolderPermission -Identity LasseP:\Calendar
Delete Content
Search-Mailbox –identity gdelete@msexchangequery.com –SearchQuery kind:meetings –DeleteContent
Search-Mailbox –identity rgupta@msexchangequery.com –SearchQuery kind:contacts –DeleteContent
Search-Mailbox –identity alias –SearchDumpsterOnly –DeleteContent
Search-Mailbox –identity username –SearchQuery kind:contacts –DeleteContent
Search-Mailbox –identity username –SearchQuery kind:notes –DeleteContent
Search-Mailbox –identity username –SearchQuery kind:tasks –DeleteContent
Search-Mailbox –identity username –SearchQuery kind:im –DeleteContent
Search-Mailbox –identity username –SearchQuery kind:email –DeleteContent

Recovery Database


New-MailboxDatabase -Recovery -Name RDB1 -Server MBX01

Set-MailboxDatabase RDB1 -AllowFileRestore:$true

new-mailboxdatabase -Recovery -Name BD100 -Server ggncloud -EdbFilePath "D:\BD100\Database\BD100.edb" -LogFolderPath "D:\BD100\Logs"
Restore-Mailbox -ID 'Keith Johnson' -RecoveryDatabase RDB1
Restore-Mailbox -ID 'john' -RecoveryDatabase RDB1 -RecoveryMailbox 'john Thomas'
Restore-Mailbox -Identity john -RecoveryDatabase RDB1

Restore-Mailbox -ID 'john' -RecoveryDatabase RDB1 -SubjectKeywords 'contract' -ContentKeywords 'companyabc' -IncludeFolders \Inbox,\Saved

Get-Mailbox –Database db1 | Restore-Mailbox –RecoveryDatabase RDB1
Add-MailboxDatabaseCopy -Identity DB01 -MailboxServer rakesh -ActivationPreference 2
Get-MailboxDatabaseCopyStatus DB01
Clean-MailboxDatabase MBD01

Mount-Database RDB1
Dismount-Database DB01 -Confirm $false

PowerShell Command
Set-OabVirtualDirectory OAB* -BasicAuthentication $True 
Get-FederationTrust | Set-FederationTrust –RefreshMetadata
Get-OfflineAddressBook | Update-OfflineAddressBook 
Update-FileDistributionService -Identity <insert server name> -Type “OAB”
Set-MailboxDatabase -Identity MDB1 -BackgroundDatabaseMaintenance $true
Get-MailboxDatabase MDB1 -Status | FL AvailableNewMailboxSpace
Set-MailboxDatabase -Identity "Server01\MailboxDatabase1" -MaintenanceSchedule "Sun.2:00-Sun.3:00","Wed.2:00-Wed.3:00"
Set-MailboxDatabase -BackgroundDatabaseMaintenance $true -Identity <dbname>
Remove-DatabaseAvailabilityGroupServer -Identity Netcom -MailboxServer 2013VTC2 –ConfigurationOnly
Get-help New-MailboxRepairRequest -examples 
Get-help New-PublicFolderDatabaseRepairRequest -examples
New-MailboxRepairRequest -Mailbox administrator@msexchangequery.com -CorruptionType SearchFolder, AggregateCounts, ProvisionedFolder, FolderView 
New-MailboxRepairRequest -Mailbox administrator -CorruptionType SearchFolder, AggregateCounts, ProvisionedFolder, FolderView -WhatIf 
New-PublicFolderDatabaseRepairRequest -Database PFD01 -CorruptionType ReplState -DetectOnly
Get-help New-MailboxRepairRequest -detailed (or -full) 
Get-help New-PublicFolderDatabaseRepairRequest -detailed (or -full)
Get-MailboxStatistics -Identity pdf | Format-List 
Get-MSOLDomainVerificationDNS -DomainName innodata.com -Mode DNSMXRecord
Get-LogonStatistics -Identity pdf@msexchangequery.com |FL UserName,LogonTime,LastAccessTime,ServerName
Get-MsolDomain -domain msexchangequery.com
Get-OSCEXOInboxRule -Identity pdf | Select -ExpandProperty Actions
Get-MailboxFolderStatistics -Identity pdf -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder
Get-MailboxFolderStatistics -Identity rgupta |fl Select Name,FolderSize,ItemsinFolder -AutoSize
Connect-OSCEXOWebService -Credential (Get-Credential  admin@msexchangequery.onmicrosoft.com)
Import-Csv -Path c:\users.csv | Set-MsolUseeLicense –AddLicenses msexchangequery:EXCHANGESTANDARD 
Import-Csv -Path c:\users.csv | Set-MsolUseeLicense –AddLicenses msexchangequery:ENTERPRISEPACK 
Get-MailboxFolderStatistics -Identity pdf -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder
Get-MailboxFolderStatistics -Identity pdf | Select Name,FolderSize,ItemsinFolder -AutoSize
Search-Mailbox –identity gdelete@msexchangequery.com –SearchQuery kind:meetings –EstimateResultOnly

Restore-DatabaseAvailabilityGroup –Identity DAG1 –ActiveDirectorySite ggncloud
Remove-DatabaseAvailabilityGroupServer -MailboxServer 'RAKESH' -Identity 'DAG2
new-DynamicDistributionGroup -Name 'DDG-ITS' -RecipientContainer 'corp.mld/ITS' -IncludedRecipients 'AllRecipients' -OrganizationalUnit 'corp.mld/ITS' -Alias 'DDGits'
Set-AdServerSettings -RecipientViewRoot "corp.mld/its"
Set-AdServerSettings -ViewEntireForest $true -PreferredGlobalCatalogggncloud.corp.mld
update-AddressList -Identity '\All Contacts
New-TransportRule -Name 'TS Rule1' -Comments 'transportrule' -Priority '0' -Enabled $true -From 
'shailendra@msexchangequery.com ' -DeleteMessage $true -ExceptIfFrom'john@msexchangequery.com '
Suspend-MailboxDatabaseCopy -Identity DB1\MBX2 -ActivationOnly
Resume-MailboxDatabaseCopy -Identity DB1\MBX2
Set-MailboxServer -Identity MailboxServer–DatabaseCopyAutoActivationPolicy
Set-MailboxServer -Identity MailboxServer–DatabaseCopyAutoActivationPolicy
Get-DatabaseAvailabilityGroupNetwork -Identity DAG2 | fl name, MapiAccessEnabled
Set-Mailbox "John Doe" -RetentionPolicy "Finance"
Import-PSSession $Session
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://msexchangequery.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential

Set-User rakesh -RemotePowerShellEnabled $True

No comments:

Post a Comment