Sunday, March 29, 2015

Patching Procedure and Verification Tests-Exchange

Patching Procedure

1.   Login to the server

2.   For Windows Patching

1.   Go to start à All Programs à Windows Update



             2. Click on the blue where it says numbers of updates are available.



             3. Ensure that there is no Exchange rollup/hotfix/ServicePack, if there is a rollup checked then UNCHECK the Exchange rollup/hotfix/ServicePack

             4. Then Click ok and then click on Install Updates

             5. Once completed click finished and restart the server.
 
            6. Once restart the server again check updates, if it available new update, click Install
           
             7. Once completed click finished and restart the server.
            
              8. Verify the all services running working fine.
 
 
Verification Tests

Run the following tests on all Exchange servers

1.Get-queue | ? {$_.MessageCount –gt 5}

Queue should be less than 10 mails

2.Test-ServiceHealth

No service should show in ServiceNotRunning under any role.

        

                 3. Test-ReplactionHealth

                                         Replication should show Passed for all

                 4. Test-OutlookWebServices

                                         No Error should come except the Id 1104

                 5. Test-Mapiconnectivity

                                         This should come success

                 6. Get-mailboxdatabasecopystatus **

                                         Databases should show healthy and mounted.

                 7. Login to OWA using test account and test send and receive of the email.

Active Directory Script

The following table lists all the cmdlets that are available in this release of the Active Directory module in Windows Server 2008 R2.
PS C:\> Get-ADDomain

Retrieve properties for the Administrators group:
PS C:\> Get-ADGroup -Identity Administrators | Get-Member

Retrieve ALL properties for the Administrators group:
PS C:\> Get-ADGroup -Identity Administrators -Properties *| Get-Member

Retrieve the extended properties "Organization" and the default properties for the user: Rakeshc:
PS C:\> GetADUser -Identity rakeshc –Properties Organization

Retrieve the properties with LDAP display names of "hcluser" and "messaging", for the user: rakeshc:
PS C:\> GetADUser -Identity rakeshc -Properties hcluser, messaging |Get-Member

PS C:\> New-ADGroup -Server DC1.msexchangequery.com -Path "OU=Exchange,DC=dc" -Name AccountLeads -GroupScope DomainLocal -GroupCategory Distribution
PS C:\> New-ADGroup -Name "Lync Admins" -SamAccountName RODCAdmins -GroupCategory Security -GroupScope Global -DisplayName "Lync Administrators" -Path "CN=Exchange,DC=dc,DC=Com" -Description "Members of this group are Lync Administrators"

Remove the group that has samAccountName 'messaging':
PS C:\> remove-adgroup messaging

Get all groups whose name starts with 'messaging' and remove them:
PS C:\> get-adgroup -filter 'Name -like "messaging"' | remove-adgroup

Remove a group, the cmdlet will prompt for a name:
PS C:\> remove-adgroup

PS C:\> Get-ADGroup lyncAdmin -Properties Description

Adds the user accounts with SamAccountNames User01 and User02 to the group messaging:
PS C:\> Add-ADGroupMember messaging User1,User2

Get all the members of the administrators groups using the default behavior:
PS C:\> get-adgroupmember -Identity "messaging"

Remove the user with samAccountName 'FredB' from the group 'messaging':
PS C:\> remove-adgroupmember -Identity "messaging" -Member "rakeshc"

Remove the users with samAccountNames 'administrator' and 'rakeshc' from the group 'messaging' and don't ask to confirm:
PS C:\> remove-adgroupmember "messaging" "administrator","rakeshc" -Confirm:$false

Retrieve all the groups the administrator is a member of:
PS C:\> get-adprincipalgroupmembership -Identity Administrator

PS C:\> Get-ADUser rakeshc

PS C:\> Get-ADUser –Filter {Surname –eq “chaturvedi”}

PS C:\> Get-ADUser –Filter {GivenName –eq “Rakesh”}

PS C:\> Get-ADPrincipalGroupMembership –Identity rakeshc

PS C:\> Remove-ADGroupMember –Identity “Group Name” –Member  “rakeshc”

PS C:\> Get-ADPrincipalGroupMembership –Identity khess

PS C:\> New-ADUser –Name “Rakesh Chaturvedi” –GivenName Rakesh –Surname Chaturvedi –UserPrincipalName rakeshc@msexchangequery.com –SamAccountName rakeshc

PS C:\> Get-ADUser rakeshc

PS C:\> Add-ADGroupMember CS-Administrator rakeshc

PS C:\> New-ADUser –Name “Rakesh Chaturvedi” –GivenName Rakesh –Surname Chaturvedi –UserPrincipalName rakeshc@msexchangequery.com –SamAccountName rakeshc –Enabled 1 –AccountPassword (Read-Host –AsSecureString “Password”)

PS C:\> Search-ADAccount –AccountDisabled –UserOnly |FT Name

PS C:\> Set-ADAccountPassword –Identity rakeshc –NewPassword (Read-Host –AsSecureString “New Password”) –OldPassword (Read-Host –AsSecureString “Old Password”)

PS C:\> Enable-ADAccount –Identity rakeshc

PS C:\> Search-ADAccount –AccountDisabled –UserOnly |FT Name

PS C:\> Search-ADAccount –LockedOut –UsersOnly |FT Name

PS C:\> Unlock-ADAccount –Identity rakeshc

PS C:\> Unlock-ADAccount –Identity (Read-Host “rakeshc”)

PS C:\> Disable-ADAccount –Identity rakeshc

PS C:\> Enable-ADAccount -Identity Rakeshc

PS C:\> Remove-ADUser rakeshc

PS C:\> Remove-ADUser rakeshc

PS C:\> Set-ADAccountPassword -Identity rakeshc
PS C:\> $newPassword = (Read-Host -Prompt "Provide New Password" -AsSecureString)

PS C:\> Set-ADAccountPassword -Identity JMarbles -NewPassword $newPassword –Reset

PS C:\> Set-ADAccountPassword -Identity JMarbles -OldPassword (ConvertTo-SecureString -AsPlainText "0ldPaZZw0rd" -Force) -NewPassword (ConvertTo-SecureString -AsPlainText "p@ssw0rd2" -Force)
PS C:\> Get-ADDomain “msexchangequery.com” –Server “DC1” –Credential “msexchangequery.com\Administrator”
PS C:\> Get-ADUser rakeshc –Server “Dc1” –Credential “msexchangequery.com\Administrator”
PS C:\> Add-ADComputerServiceAccount -Computer Computer1 -serviceAccount SvcAc1
PS C:\>  Add-ADComputerServiceAccount  -Computer Computer1 -serviceAccount SvcAc1,SvcAc2

Sunday, October 26, 2014

Lync Powershell Scripts

View the Status of Services Running on a Computer

Ø    To view the status of services running on a computer
To view the status of all the Lync Server services running on all your computers, use the following command:

Get-CsService | Select-Object Role, PoolFqdn | Sort-Object PoolFqdn, Role

To view the services running on a specific computer, use this command, replacing lync-001.msexchangequery.com with the fully qualified domain name of the computer to be checked:

Get-CsService | Where-Object {$_.PoolFqdn –eq "lync-001.msexchangequery.com"} | Select-Object Role, PoolFqdn | Sort-Object PoolFqdn, Role

For More Information

View Details About a Service

Ø  To view details for a service
To view detailed information for a particular Lync Server service or server role, use the Get-CsService cmdlet followed by the service Identity:

Get-CsService –Identity service:Registrar:lync-001.msexchangequery.com

To view detailed information for all your Lync Server services or server roles, call Get-CsService without any parameters:

Get-CsService

For More Information

Start or Stop Lync Server 2010 Services

Ø  To start or stop all Lync Server services on a computer
To start all the Lync Server services on a computer, use the Start-CsWindowsService cmdlet:

Start-CsWindowsService -ComputerName lync-001.msexchangequery.com


Note that the ComputerName parameter is not required if you are starting the Lync Server services on the local computer.

To stop all the Lync Server services on a computer, use the Stop-CsWindowsService cmdlet:

Stop-CsWindowsService -ComputerName lync-001.msexchangequery.com


Ø  To start or stop a specific service
To start a specific service, use the Start-CsWindowsService cmdlet along with the Name parameter:

Start-CsWindowsService –Name "RTCRGS" -ComputerName lync-001.msexchangequery.com

Use the Stop-CsWindowsService cmdlet to stop a specified service:

Stop-CsWindowsService –Name "RTCRGS" -ComputerName lync-001.msexchangequery.com

For More Information
The CsWindowsService Cmdlets at http://go.microsoft.com/fwlink/?LinkId=231028

Prevent Sessions for Services

Ø  To prevent new sessions for all Lync Server services on a computer
To prevent new sessions for all the Lync Server services on a computer use the following command:

Get-CsWindowsService | Stop-CsWindowsService -ComputerName lync-001.msexchangequery.com –Graceful

The Graceful parameter used with the Stop-CsWindowsService cmdlet ensures that all existing sessions will be honored but no new sessions will be allowed.

Ø  To prevent new sessions for a specific service
To prevent new sessions for a specific Lync Server service, use the following command:

Stop-CsWindowsService -Name "RTCRGS" -ComputerName lync-001.msexchangequery.com -Graceful

For More Information
The CsWindowsService Cmdlets at http://go.microsoft.com/fwlink/?LinkId=231028

Managing Users

Search for Lync Server 2010 Users
Ø  To search for one or more users
To search for a user based on the value of a Lync Server-specific attribute, use the Get-CsUser cmdlet and the Filter parameter. 

Get-CsUser -Filter {VoicePolicy -eq $Null}

To search for a user based on the value of a generic Active Directory attribute, use the Get-CsUser cmdlet and the LdapFilter parameter. For example, this command searches for all users who are members of the Finance department:

Get-CsUser -LDAPFilter "Department=Finance"

For More Information
·         21 User Information Cmdlets to Run Before You Die at http://go.microsoft.com/fwlink/?LinkId=231038

Add a New User to Lync Server 2010
Ø  To create a new Lync Server user
To enable a user to use Lync Server, use the Enable-CsUser cmdlet:

Enable-CsUser -Identity "Rakesh" -RegistrarPool "lync-001.msexchangequery.com" -SipAddressType SamAccountName  -SipDomain msexchangequery.com

The preceding command includes the SipAddressType and SipDomain parameters; this causes Lync Server to automatically create a SIP address for the user based (in this case) on the user's SamAccountName and the domain name litwareinc.com. Alternatively, you can use the SipAddress parameter to assign a specific SIP address to a user:

Enable-CsUser -Identity "rakesh" -RegistrarPool "lync-001.msexchangequery.com" –SipAddress "sip:rakesh@msexchangequery.com"

For More Information
·         21 User Information Cmdlets to Run Before You Die at http://go.microsoft.com/fwlink/?LinkId=231038
·         Enabling a User for Microsoft Lync Server 2010 at http://go.microsoft.com/fwlink/?LinkId=231040
·         Enabling a User for Microsoft Lync Server 2010 and Enterprise Voice at http://go.microsoft.com/fwlink/?LinkId=231043
·         The New Communications Server User Dialog at http://go.microsoft.com/fwlink/?LinkId=231044


Enable or Disable Users for Lync Server 2010
Ø  To disable or re-enable a previously enabled user account for Lync Server
To permanently disable a Lync Server user account

Disable-CsUser –Identity "rakesh"

Set-CsUser –Identity "Rakesh" –Enabled $False

·         Disable-CsUser at http://go.microsoft.com/fwlink/?LinkId=231046
·         Set-CsUser at http://go.microsoft.com/fwlink/?LinkId=231047

Finding all the people who have a telephone number set in Lync


Get-CsUser -Filter {LineURI -ne $NULL} | FT Name, LineURI

Change SIP domain for all users


$UserList = Get-CsUser 

foreach ($User in $UserList)

{

   $oldAddress = $User.SipAddress

   $newAddress = $oldAddress -replace "@olddomain.com", "@newdomain.com"

   Set-CsUser -Identity $User.Identity -SipAddress $newAddress

}



Setting the AD office phone number to the TelURI for all users


#Only need to add the AD Powershell instance once

Add-WindowsFeature RSAT-AD-Powershell
Import-Module ActiveDirectory

$users = Get-CSUser

Foreach ($user in $users)
{
   $Tel = $user.LineURI
   $Tel = $Tel.Replace("tel:", "")
   If ($Tel -ne "")
   {
      Set-ADUser -Identity $user.SAMAccountName -OfficePhone $Tel
   }
}

Enable All Users in a Group for Lync Enterprise Voice


#Uses existing office number in AD for Enterprise Voice

Import-Module ActiveDirectory

$Users = Get-ADGroupMember lync_group

ForEach ($User in $Users)
{
    Enable-CsUser $User.SamAccountName -RegistrarPool PHX-Lync15-FE.swc.local -SipAddressType EmailAddress
    $OfficePhone = (Get-CSADUser $User.SamAccountName).Phone
    $OfficePhone = $OfficePhone -replace "\D", ""
    Set-CSUser $User.SamAccountName -EnterpriseVoiceEnabled:$TRUE -LineURI "tel:+$OfficePhone"
}

Move All OCS Users Homed on a Specific Pool to Lync


Also sets conferencing policy and external access policy to automatic, rather than the legacy migrated OCS policies.  Replace items in bold with your environmental specifics.

get-csuser -OnOfficeCommunicationServer | Where {$_.HomeServer -eq "CN=LC Services,CN=Microsoft,CN=OCSPOOLNAME,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=contoso,DC=com"} | Move-CsLegacyUser -Target LYNCPOOLFQDN -ExcludeConferencingPolicy -ExcludeExternalAccessPolicy -Confirm:$FALSE

Count How Many Users are on OCS and Lync
(Get-CsUser -OnOfficeCommunicationServer).Count
(Get-CsUser -OnLyncServer).Count

Get a List of All Lync-Enabled Users Along with Selected AD Properties


$ErrorActionPreference = 'SilentlyContinue'
Import-Module ActiveDirectory
$Output = @()

Foreach ($LyncUser in Get-CSUser -ResultSize Unlimited)
{
$ADUser = Get-ADUser -Identity $LyncUser.SAMAccountName -Properties Department, Title
$Output += New-Object PSObject -Property @{DisplayName=$LyncUser.DisplayName; Department=$ADUser.Department; Title=$ADUser.Title; SAMAccountName=$ADUser.sAMAccountName; SIPAddress=$LyncUser.SIPAddress; EVEnabled=$LyncUser.EnterpriseVoiceEnabled}
}

$Output | Export-CSV -Path .\Output.csv
$Output | FT DisplayName, Title, Department, SAMAccountName, SIPAddress, EVEnabled

Add Enterprise Voice Users to an AD Group


Foreach ($User in get-csuser -filter {EnterpriseVoiceEnabled -eq $TRUE})
{Add-ADGroupMember -Identity -Members $User.SamAccountName}
 


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