A nice Exchange 2013 feature is auto resume if a database copy gets a status other than "Healthy".
The sad thing is that it doesn't exist in Exchange 2010.
There's a script for that, something I put together and runs scheduled every 3 hours.
This is enough to check all database copy's and keep them all healthy, and not make the backup stop, Avamar backup stops the backup if the status is failed or suspended.
So here goes:
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “FailedandSuspended”}| Resume-MailboxDatabaseCopy
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Suspended”}| Resume-MailboxDatabaseCopy
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Resume-MailboxDatabaseCopy
About: Exchange 2013-2016-2019-Online - Powershell - Windows 2012-2016-2019 - Teams - Office365 - PKI - Microsoft365
27 August 2013
21 August 2013
Database Seeding cmdlets
Still looking for my resume-mailboxdatabasecopy script, I came across this, it lists the most interesting cmdlets database seeding has to offer.
All credits go to Dame Luthas, as I think he saved me another day of searching.
Database Seeding cmdlets
Get Database Copy Status
Get-MailboxDatabaseCopyStatus -Identity ‘EX10mbx01′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Status for all database copies on the Mailbox server EX10CHM10 by status
Get-MailboxDatabaseCopyStatus -Server EX10CHM01 | Sort-Object -Property Status| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
UPDATE Seed a copy of a database named EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM02 -SourceServer EX10CHM01
UPDATE Seed a copy of a database named EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed (remove existing files)
Update-MailboxDatabaseCopy -Identity EX10mbx48\EX10CHM07 -sourceserver EX10CHM09 -DeleteExistingFiles
Update the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity EX10mbx02\EX10CHM10 -DeleteExistingFiles
Update ONLY the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity EX10mbx06\EX10CHM12 -SourceServer EX10CHM11 -DatabaseOnly -DeleteExistingFiles
Update Catalog Only
Update-MailboxDatabaseCopy -identity EX10mbx01\EX10CHM11 –CatalogOnly
Update Database Only without seeding the content index catalog
Update-MailboxDatabaseCopy -identity EX10mbx07\EX10CHM12 –Databaseonly
UPDATE the Catalog on EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity EX10mbx46\EX10CHM04 -SourceServer EX10CHM05 -catalogonly
Update-MailboxDatabaseCopy -Identity EX10mbx22\EX10CHM05 -DeleteExistingFiles
Resume all Copies in FailedandSuspended
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “FailedandSuspended”}| Resume-MailboxDatabaseCopy
Resume all Copies in Failed state on Server
Get-MailboxDatabase -server EX10CHM03| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Resume-MailboxDatabaseCopy
Resume Database Copy for all Databases located on Server
Get-MailboxDatabaseCopyStatus -Server EX10CHM07 | Resume-Mailboxdatabasecopy
Resume-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM09
Suspend Mailbox Database Copy
Suspend-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM11 -SuspendComment “Maintenance ” -Confirm:$False
Suspend all Copies in Failed state on Server
Get-MailboxDatabase -server EX10CHM10| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Suspend-MailboxDatabaseCopy
Get-MailboxDatabaseCopyStatus -Server EX10CHM01 | Suspend-MailboxDatabaseCopy
Add Mailbox Database Copy
Add-MailboxDatabaseCopy -Identity ‘EX10mbx01′ -MailboxServer ‘EX10CHM09′
Add Mailbox Database Copy (SEEDING POSTPONED)
Add-MailboxDatabaseCopy -Identity EX10mbx01 -MailboxServer EX10CHM11 -SeedingPostponed
MOVE ACTIVE DATABASE
Set Active Mailbox Database Copy
Move-ActiveMailboxDatabase -Identity ‘EX10mbx12′ -ActivateOnServer ‘EX10CHM04′ -MountDialOverride ‘None’
Set Active Mailbox Database Copy with failed Catalog
Move-ActiveMailboxDatabase -Identity ‘EX10mbx01′ -ActivateOnServer ‘EX10CHM01′ -MountDialOverride ‘None’ -SkipClientExperienceChecks
Remove Mailbox Database Copy
Remove-MailboxDatabaseCopy -Identity EX10MBX03\EX10CHM11 -Confirm:$False
Context Index
Disable Indexing on Mailbox Database
Set-MailboxDatabase “EX10MBX07″ -IndexEnabled $false
Enable Indexing on Mailbox Database
Set-MailboxDatabase “Mailbox Database EX10MBX03″ -IndexEnabled $true
Finding the passive Databases with Failed Index (can’t update the index on the active DB)
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | ft -autosize
Fix the Passive databases with Failed Index
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy –CatalogOnly
Fix all Passive databases with Failed Index per Database
Get-MailboxDatabaseCopyStatus -identity EX10mbx01\* | ? {$_.Status -ne “Mounted” -and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy -CatalogOnly
Source
All credits go to Dame Luthas, as I think he saved me another day of searching.
Database Seeding cmdlets
Get-MailboxDatabaseCopyStatus -Identity ‘EX10mbx01′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Status for all database copies on the Mailbox server EX10CHM10 by status
Get-MailboxDatabaseCopyStatus -Server EX10CHM01 | Sort-Object -Property Status| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
UPDATE Seed a copy of a database named EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM02 -SourceServer EX10CHM01
UPDATE Seed a copy of a database named EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed (remove existing files)
Update-MailboxDatabaseCopy -Identity EX10mbx48\EX10CHM07 -sourceserver EX10CHM09 -DeleteExistingFiles
Update the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity EX10mbx02\EX10CHM10 -DeleteExistingFiles
Update ONLY the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity EX10mbx06\EX10CHM12 -SourceServer EX10CHM11 -DatabaseOnly -DeleteExistingFiles
Update Catalog Only
Update-MailboxDatabaseCopy -identity EX10mbx01\EX10CHM11 –CatalogOnly
Update Database Only without seeding the content index catalog
Update-MailboxDatabaseCopy -identity EX10mbx07\EX10CHM12 –Databaseonly
UPDATE the Catalog on EX10mbx08 on EX10CHM01 using EX10CHM04 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity EX10mbx46\EX10CHM04 -SourceServer EX10CHM05 -catalogonly
Update-MailboxDatabaseCopy -Identity EX10mbx22\EX10CHM05 -DeleteExistingFiles
Resume all Copies in FailedandSuspended
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “FailedandSuspended”}| Resume-MailboxDatabaseCopy
Resume all Copies in Failed state on Server
Get-MailboxDatabase -server EX10CHM03| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Resume-MailboxDatabaseCopy
Resume Database Copy for all Databases located on Server
Get-MailboxDatabaseCopyStatus -Server EX10CHM07 | Resume-Mailboxdatabasecopy
Resume-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM09
Suspend Mailbox Database Copy
Suspend-MailboxDatabaseCopy -Identity EX10mbx01\EX10CHM11 -SuspendComment “Maintenance ” -Confirm:$False
Suspend all Copies in Failed state on Server
Get-MailboxDatabase -server EX10CHM10| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Suspend-MailboxDatabaseCopy
Get-MailboxDatabaseCopyStatus -Server EX10CHM01 | Suspend-MailboxDatabaseCopy
Add Mailbox Database Copy
Add-MailboxDatabaseCopy -Identity ‘EX10mbx01′ -MailboxServer ‘EX10CHM09′
Add Mailbox Database Copy (SEEDING POSTPONED)
Add-MailboxDatabaseCopy -Identity EX10mbx01 -MailboxServer EX10CHM11 -SeedingPostponed
MOVE ACTIVE DATABASE
Set Active Mailbox Database Copy
Move-ActiveMailboxDatabase -Identity ‘EX10mbx12′ -ActivateOnServer ‘EX10CHM04′ -MountDialOverride ‘None’
Set Active Mailbox Database Copy with failed Catalog
Move-ActiveMailboxDatabase -Identity ‘EX10mbx01′ -ActivateOnServer ‘EX10CHM01′ -MountDialOverride ‘None’ -SkipClientExperienceChecks
Remove Mailbox Database Copy
Remove-MailboxDatabaseCopy -Identity EX10MBX03\EX10CHM11 -Confirm:$False
Context Index
Disable Indexing on Mailbox Database
Set-MailboxDatabase “EX10MBX07″ -IndexEnabled $false
Enable Indexing on Mailbox Database
Set-MailboxDatabase “Mailbox Database EX10MBX03″ -IndexEnabled $true
Finding the passive Databases with Failed Index (can’t update the index on the active DB)
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | ft -autosize
Fix the Passive databases with Failed Index
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy –CatalogOnly
Fix all Passive databases with Failed Index per Database
Get-MailboxDatabaseCopyStatus -identity EX10mbx01\* | ? {$_.Status -ne “Mounted” -and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy -CatalogOnly
Source
Labels:
Exchange 2010,
Powershell
Location:Utrecht
Utrecht, Nederland
Database Maintenance in Exchange 2010
Today in search of another problem I came across an old blog post over at The Exchange Blog Team.
It's an explanation of the database maintenance tasks in Exchange 2010, and what the several tasks do and how to do it.
Very interesting reading material, every Exchange admin should read (I my opion).
So here goes:
Maintaining a lean database file footprint is important for several reasons, including the following:
In Exchange 2010, database compaction was redesigned such that contiguity is preferred over space compaction. In addition, database compaction was moved out of the online maintenance window and is now a background process that runs continuously.
You can think of the database defragmentation process as a monitor that watches other database page operations to determine if there is work to do. It monitors all tables for free pages, and if a table gets to a threshold where a significant high percentage of the total B+ Tree page count is free, it gives the free pages back to the root. It also works to maintain contiguity within a table set with sequential space hints (a table created with a known sequential usage pattern). If database defragmentation sees a scan/pre-read on a sequential table and the records are not stored on sequential pages within the table, the process will defrag that section of the table, by moving all of the impacted pages to a new extent in the B+ tree. You can use the performance counters (mentioned in the monitoring section) to see how little work database defragmentation performs once a steady state is reached.
Database defragmentation is a background process that analyzes the database continuously as operations are performed, and then triggers asynchronous work when necessary. Database defragmentation is throttled under two scenarios:
With Exchange 2007 RTM and all previous versions, checksumming operations happened during the backup process. This posed a problem for replicated databases, as the only copy to be checksummed was the copy being backed up. For the scenario where the passive copy was being backed up, this meant that the active copy was not being checksummed. So in Exchange 2007 SP1, we introduced a new optional online maintenance task, Online Maintenance Checksum (for more information, see Exchange 2007 SP1 ESE Changes – Part 2).
In Exchange 2010, database scanning checksums the database and performs post Exchange 2010 Store crash operations. Space can be leaked due to crashes, and online database scanning finds and recovers lost space. Database checksum reads approximately 5 MB per second for each actively scanning database (both active and passive copies) using 256KB IOs. The I/O is 100 percent sequential. The system in Exchange 2010 is designed with the expectation that every database is fully scanned once every seven days.
If the scan takes longer than seven days, an event is recorded in the Application Log :
In Exchange 2010, there are now two modes to run database checksumming on active database copies:
For passive database copies, database checksums occur during runtime, continuously operating in the background.
Page patching process
With Exchange 2007 RTM and all previous versions, page zeroing operations happened during the streaming backup process. In addition since they occurred during the streaming backup process they were not a logged operation (e.g., page zeroing did not result in the generation of log files). This posed a problem for replicated databases, as the passive copies never had its pages zeroed, and the active copies would only have it pages zeroed if you performed a streaming backup. So in Exchange 2007 SP1, we introduced a new optional online maintenance task, Zero Database Pages during Checksum (for more information, see Exchange 2007 SP1 ESE Changes – Part 2). When enabled this task would zero out pages during the Online Maintenance Window, logging the changes, which would be replicated to the passive copies.
With the Exchange 2007 SP1 implementation, there is significant lag between when a page is deleted to when it is zeroed as a result of the zeroing process occurring during a scheduled maintenance window. So in Exchange 2010 SP1, the page zeroing task is now a runtime event that operates continuously, zeroing out pages typically at transaction time when a hard delete occurs.
In addition, database pages can also be scrubbed during the online checksum process. The pages targeted in this case are:
You'll find the following page zeroing counters under the MSExchange Database object:
Note that there is a status property available on databases within Exchange 2010, but it should not be used to determine the amount of total whitespace available within the database:
Many assume the answer is to perform an offline defragmentation of the database using ESEUTIL. However, that's not our recommendation. When you perform an offline defragmentation you create an entirely brand new database and the operations performed to create this new database are not logged in transaction logs. The new database also has a new database signature, which means that you invalidate the database copies associated with this database.
In the event that you do encounter a database that has significant whitespace and you don't expect that normal operations will reclaim it, our recommendation is:
Figure 1: Enabling background database maintenance for a database using EMC
Enabling background database maintenance using the Shell:
Figure 2: Running background database maintenance as part of a JetStress test
As part of our storage guidance, we recommend you configure your storage array stripe size (the size of stripes written to each disk in an array; also referred to as block size) to be 256KB or larger.
It's also important to test your storage with JetStress and ensure that the database checksum operation is included in the test pass.
In the end, if a JetStress execution fails due to database checksumming, you have a few options:
Source
It's an explanation of the database maintenance tasks in Exchange 2010, and what the several tasks do and how to do it.
Very interesting reading material, every Exchange admin should read (I my opion).
So here goes:
Database Maintenance in Exchange 2010
Over the last several months there has been significant chatter around what is background database maintenance and why is it important for Exchange 2010 databases. Hopefully this article will answer these questions.
What maintenance tasks need to be performed against the database?
The following tasks need to be routinely performed against Exchange databases:- Database Compaction
- Database Defragmentation
- Database Checksumming
- Page Patching
- Page Zeroing
Database Compaction
The primary purpose of database compaction is to free up unused space within the database file (however, it should be noted that this does not return that unused space to the file system). The intention is to free up pages in the database by compacting records onto the fewest number of pages possible, thus reducing the amount of I/O necessary. The ESE database engine does this by taking the database metadata, which is the information within the database that describes tables in the database, and for each table, visiting each page in the table, and attempting to move records onto logically ordered pages.Maintaining a lean database file footprint is important for several reasons, including the following:
- Reducing the time associated with backing up the database file
- Maintaining a predictable database file size, which is important for server/storage sizing purposes.
In Exchange 2010, database compaction was redesigned such that contiguity is preferred over space compaction. In addition, database compaction was moved out of the online maintenance window and is now a background process that runs continuously.
Database Defragmentation
Database defragmentation is new to Exchange 2010 and is also referred to as OLD v2 and B+ tree defragmentation. Its function is to compact as well as defragment (make sequential) database tables that have been marked/hinted as sequential. Database defragmentation is important to maintain efficient utilization of disk resources over time (make the IO more sequential as opposed to random) as well as to maintain the compactness of tables marked as sequential.You can think of the database defragmentation process as a monitor that watches other database page operations to determine if there is work to do. It monitors all tables for free pages, and if a table gets to a threshold where a significant high percentage of the total B+ Tree page count is free, it gives the free pages back to the root. It also works to maintain contiguity within a table set with sequential space hints (a table created with a known sequential usage pattern). If database defragmentation sees a scan/pre-read on a sequential table and the records are not stored on sequential pages within the table, the process will defrag that section of the table, by moving all of the impacted pages to a new extent in the B+ tree. You can use the performance counters (mentioned in the monitoring section) to see how little work database defragmentation performs once a steady state is reached.
Database defragmentation is a background process that analyzes the database continuously as operations are performed, and then triggers asynchronous work when necessary. Database defragmentation is throttled under two scenarios:
- The max number of outstanding tasks This keeps database defragmentation from doing too much work the first pass if massive change has occurred in the database.
- A latency throttle of 100ms When the system is overloaded, database defragmentation will start punting defragmentation work. Punted work will get executed the next time the database goes through that same operational pattern. There's nothing that remembers what defragmentation work was punted and goes back and executes it once the system has more resources.
Database Checksumming
Database checksumming (also known as Online Database Scanning) is the process where the database is read in large chunks and each page is checksummed (checked for physical page corruption). Checksumming’s primary purpose is to detect physical corruption and lost flushes that may not be getting detected by transactional operations (stale pages).With Exchange 2007 RTM and all previous versions, checksumming operations happened during the backup process. This posed a problem for replicated databases, as the only copy to be checksummed was the copy being backed up. For the scenario where the passive copy was being backed up, this meant that the active copy was not being checksummed. So in Exchange 2007 SP1, we introduced a new optional online maintenance task, Online Maintenance Checksum (for more information, see Exchange 2007 SP1 ESE Changes – Part 2).
In Exchange 2010, database scanning checksums the database and performs post Exchange 2010 Store crash operations. Space can be leaked due to crashes, and online database scanning finds and recovers lost space. Database checksum reads approximately 5 MB per second for each actively scanning database (both active and passive copies) using 256KB IOs. The I/O is 100 percent sequential. The system in Exchange 2010 is designed with the expectation that every database is fully scanned once every seven days.
If the scan takes longer than seven days, an event is recorded in the Application Log :
If it takes longer than seven days to complete the scan on the active database copy, the following entry will be recorded in the Application Log once the scan has completed:Event ID: 733
Event Type: Information
Event Source: ESE
Description: Information Store (15964) MDB01: Online Maintenance Database Checksumming background task is NOT finishing on time for database 'd:\mdb\mdb01.edb'. This pass started on 11/10/2011 and has been running for 604800 seconds (over 7 days) so far.
In addition, an in-flight warning will also be recorded in the Application Log when it takes longer than 7 days to complete.Event ID: 735
Event Type: Information
Event Source: ESE
Description: Information Store (15964) MDB01 Database Maintenance has completed a full pass on database 'd:\mdb\mdb01.edb'. This pass started on 11/10/2011 and ran for a total of 777600 seconds. This database maintenance task exceeded the 7 day maintenance completion threshold. One or more of the following actions should be taken: increase the IO performance/throughput of the volume hosting the database, reduce the database size, and/or reduce non-database maintenance IO.
In Exchange 2010, there are now two modes to run database checksumming on active database copies:
- Run in the background 24×7 This is the default behavior. It should be used for all databases, especially for databases that are larger than 1TB. Exchange scans the database no more than once per day. This read I/O is 100 percent sequential (which makes it easy on the disk) and equates to a scanning rate of about 5 megabytes (MB)/sec on most systems. The scanning process is single threaded and is throttled by IO latency. The higher the latency, the more database checksum slows down because it is waiting longer for the last batch to complete before issuing another batch scan of pages (8 pages are read at a time).
- Run in the scheduled mailbox database maintenance process When you select this option, database checksumming is the last task. You can configure how long it runs by changing the mailbox database maintenance schedule. This option should only be used with databases smaller than 1 terabyte (TB) in size, which require less time to complete a full scan.
For passive database copies, database checksums occur during runtime, continuously operating in the background.
Page Patching
Page patching is the process where corrupt pages are replaced by healthy copies. As mentioned previously, corrupt page detection is a function of database check summing (in addition, corrupt pages are also detected at run time when the page is stored in the database cache). Page patching works against highly available (HA) database copies. How a corrupt page is repaired depends on whether the HA database copy is active or passive.Page patching process
| On active database copies | On passive database copies |
|
|
Page Zeroing
Database Page Zeroing is the process where deleted pages in the database are written over with a pattern (zeroed) as a security measure, which makes discovering the data much more difficult.With Exchange 2007 RTM and all previous versions, page zeroing operations happened during the streaming backup process. In addition since they occurred during the streaming backup process they were not a logged operation (e.g., page zeroing did not result in the generation of log files). This posed a problem for replicated databases, as the passive copies never had its pages zeroed, and the active copies would only have it pages zeroed if you performed a streaming backup. So in Exchange 2007 SP1, we introduced a new optional online maintenance task, Zero Database Pages during Checksum (for more information, see Exchange 2007 SP1 ESE Changes – Part 2). When enabled this task would zero out pages during the Online Maintenance Window, logging the changes, which would be replicated to the passive copies.
With the Exchange 2007 SP1 implementation, there is significant lag between when a page is deleted to when it is zeroed as a result of the zeroing process occurring during a scheduled maintenance window. So in Exchange 2010 SP1, the page zeroing task is now a runtime event that operates continuously, zeroing out pages typically at transaction time when a hard delete occurs.
In addition, database pages can also be scrubbed during the online checksum process. The pages targeted in this case are:
- Deleted records which couldn’t be scrubbed during runtime due to dropped tasks (if the system is too overloaded) or because Store crashed before the tasks got to scrub the data;
- Deleted tables and secondary indices. When these get deleted, we don’t actively scrub their contents, so online checksum detects that these pages don’t belong to any valid object anymore and scrubs them.
Why aren’t these tasks simply performed during a scheduled maintenance window?
Requiring a scheduled maintenance window for page zeroing, database defragmentation, database compaction, and online checksum operations poses significant problems, including the following:- Having scheduled maintenance operations makes it very difficult to manage 24x7 datacenters which host mailboxes from various time zones and have little or no time for a scheduled maintenance window. Database compaction in prior versions of Exchange had no throttling mechanisms and since the IO is predominantly random, it can lead to poor user experience.
- Exchange 2010 Mailbox databases deployed on lower tier storage (e.g., 7.2K SATA/SAS) have a reduced effective IO bandwidth available to ESE to perform maintenance window tasks. This is an issue because it means that IO latencies will increase during the maintenance window, thus preventing the maintenance activities to complete within a desired period of time.
- The use of JBOD provides an additional challenge to the database in terms of data verification. With RAID storage, it's common for an array controller to background scan a given disk group, locating and re-assigning bad blocks. A bad block (aka sector) is a block on a disk that cannot be used due to permanent damage (e.g. physical damage inflicted on the disk particles). It's also common for an array controller to read the alternate mirrored disk if a bad block was detected on the initial read request. The array controller will subsequently mark the bad block as “bad” and write the data to a new block. All of this occurs without the application knowing, perhaps with just a slight increase in the disk read latency. Without RAID or an array controller, both of these bad block detection and remediation methods are no longer available. Without RAID, it's up to the application (ESE) to detect bad blocks and remediate (i.e., database checksumming).
- Larger databases on larger disks require longer maintenance periods to maintain database sequentiality/compactness.
Won’t these background tasks impact my end users?
We’ve designed these background tasks such that they're automatically throttled based on activity occurring against the database. In addition, our sizing guidance around message profiles takes these maintenance tasks into account.How can I monitor the effectiveness of these background maintenance tasks?
In previous versions of Exchange, events in the Application Log would be used to monitor things like online defragmentation. In Exchange 2010, there are no longer any events recorded for the defragmentation and compaction maintenance tasks. However, you can use performance counters to track the background maintenance tasks under the MSExchange Database ==> Instances object:| Counter | Description |
| Database Maintenance Duration | The number of seconds that have passed since the maintenance last completed for this database |
| Database Maintenance Pages Bad Checksums | The number of non-correctable page checksums encountered during a database maintenance pass |
| Defragmentation Tasks | The count of background database defragmentation tasks that are currently executing |
| Defragmentation Tasks Completed/Sec | The rate of background database defragmentation tasks that are being completed |
| Counter | Description |
| Database Maintenance Pages Zeroed | Indicates the number of pages zeroed by the database engine since the performance counter was invoked |
| Database Maintenance Pages Zeroed/sec | Indicates the rate at which pages are zeroed by the database engine |
How can I check whitepace in a database?
You will need to dismount the database and use ESEUTIL /MS to check the available whitespace in a database. For an example, see http://technet.microsoft.com/en-us/library/aa996139(v=EXCHG.65).aspx (note that you have to multiply the number of pages by 32K).Note that there is a status property available on databases within Exchange 2010, but it should not be used to determine the amount of total whitespace available within the database:
Get-MailboxDatabase MDB1 -Status | FL AvailableNewMailboxSpace
AvailableNewMailboxSpace tells you is how much space is available in the root tree of the database. It does not factor in the free pages within mailbox tables, index tables, etc. It is not representative of the white space within the database.How can I reclaim the whitespace?
Naturally, after seeing the available whitespace in the database, the question that always ensues is – how can I reclaim the whitespace?Many assume the answer is to perform an offline defragmentation of the database using ESEUTIL. However, that's not our recommendation. When you perform an offline defragmentation you create an entirely brand new database and the operations performed to create this new database are not logged in transaction logs. The new database also has a new database signature, which means that you invalidate the database copies associated with this database.
In the event that you do encounter a database that has significant whitespace and you don't expect that normal operations will reclaim it, our recommendation is:
- Create a new database and associated database copies.
- Move all mailboxes to the new database.
- Delete the original database and its associated database copies.
A terminology confusion
Much of the confusion lies in the term background database maintenance. Collectively, all of the aforementioned tasks make up background database maintenance. However, the Shell, EMC, and JetStress all refer to database checksumming as background database maintenance, and that's what you're configuring when you enable or disable it using these tools.Figure 1: Enabling background database maintenance for a database using EMC
Enabling background database maintenance using the Shell:
Set-MailboxDatabase -Identity MDB1 -BackgroundDatabaseMaintenance $true
Figure 2: Running background database maintenance as part of a JetStress test
My storage vendor has recommended I disable Database Checksumming as a background maintenance task, what should I do?
Database checksumming can become an IO tax burden if the storage is not designed correctly (even though it's sequential) as it performs 256K read IOs and generates roughly 5MB/s per database.As part of our storage guidance, we recommend you configure your storage array stripe size (the size of stripes written to each disk in an array; also referred to as block size) to be 256KB or larger.
It's also important to test your storage with JetStress and ensure that the database checksum operation is included in the test pass.
In the end, if a JetStress execution fails due to database checksumming, you have a few options:
- Don’t use striping Use RAID-1 pairs or JBOD (which may require architectural changes) and get the most benefit from sequential IO patterns available in Exchange 2010.
- Schedule it Configure database checksumming to not be a background process, but a scheduled process. When we implemented database checksum as a background process, we understood that some storage arrays would be so optimized for random IO (or had bandwidth limitations) that they wouldn't handle the sequential read IO well. That's why we built it so it could be turned off (which moves the checksum operation to the maintenance window). If you do this, we do recommend smaller database sizes. Also keep in mind that the passive copies will still perform database checksum as a background process, so you still need to account for this throughput in our storage architecture. For more information on this subject see Jetstress 2010 and Background Database Maintenance.
- Use different storage or improve the capabilities of the storage Choose storage which is capable of meeting Exchange best practices (256KB+ stripe size).
Conclusion
The architectural changes to the database engine in Exchange Server 2010 dramatically improve its performance and robustness, but change the behavior of database maintenance tasks from previous versions. Hopefully this article helps your understanding of what is background database maintenance in Exchange 2010.Source
20 August 2013
EDGE synchronization not working
For EDGE subscription synchronization to work you need the following ports opened:
445
8815
8816
8817
50389
I will add the directions from-to later.
When EDGE subscription synchronization is not working check the following:
First seen in the eventviewer as event ID:1033
EdgeSync failed to decrypt the credential for Edge Transport server servername.domain.lan using the private key of the default Exchange certificate with exception Bad Data.
. The certificate's thumbprint is XXXXXXXXXXXXXXXXXXXXXX3954C8D6C78B and its subject is CN=servername.domain.lan, OU=ICT, O=Company N.V., L=State, S=Provence, C=NL. Use either Enable-ExchangeCertificate or New-ExchangeCertificate to set the proper Exchange default certificate and re-subscribe the Edge Transport server servername.domain.lan again.
In powershell:
Test-EdgeSynchronization
RunspaceId : b92a6789-50ce-4aec-a37c-95599e35ae52
As you can see the "Syncstatus" is failed.
Get-ExchangeCertificate | fl
AccessRules :System.Security.AccessControl.CryptoKeyAccessRule,
System.Security.AccessControl.CryptoKeyAccessRule, System.Security.AccessControl.CryptoKeyAccessRule}
CertificateDomains : {servername.domain.lan, outlook.domain.lan, mail.domain.lan, webmail.domain.nl, autodiscover.domain.nl, }
HasPrivateKey : True
IsSelfSigned : False
Issuer : CN=Domain-IssuingCA, DC=Domain, DC=lan
NotAfter : 15-8-2013 14:08:18
NotBefore : 4-3-2013 11:11:46
PublicKeySize : 2048
RootCAType : Enterprise
SerialNumber : 537C7FB7000200000BE7
Services : IMAP, POP, IIS, SMTP
Status : Valid
Subject : CN=Servername.domain.lan, OU=ICT, O=Company, L=State, S=Provence, C=Country
Thumbprint : XXXXXXXXXXXXXXXXXXXXXX3954C8D6C78B
Check thumbprint
Set thumbprint as Exchange enabled cert
Enable-ExchangeCertificate -Thumbprint XXXXXXXXXXXXXXXXXXXXXX3954C8D6C78B -DoNotRequireSsl -services:SMTP,IIS,IMAP,POP
7.Create a new Edge subscription in the EMC
Then you have to wait a few minutes.
To check if synchronization works run;
start-edgesynchronization
test-edgesynchronization
Source 1
Source 2
445
8815
8816
8817
50389
I will add the directions from-to later.
When EDGE subscription synchronization is not working check the following:
First seen in the eventviewer as event ID:1033
EdgeSync failed to decrypt the credential for Edge Transport server servername.domain.lan using the private key of the default Exchange certificate with exception Bad Data.
. The certificate's thumbprint is XXXXXXXXXXXXXXXXXXXXXX3954C8D6C78B and its subject is CN=servername.domain.lan, OU=ICT, O=Company N.V., L=State, S=Provence, C=NL. Use either Enable-ExchangeCertificate or New-ExchangeCertificate to set the proper Exchange default certificate and re-subscribe the Edge Transport server servername.domain.lan again.
In powershell:
Test-EdgeSynchronization
RunspaceId : b92a6789-50ce-4aec-a37c-95599e35ae52
SyncStatus : Failed
UtcNow : 20-8-2013 8:35:32
Name : servername
LeaseHolder :
LeaseType : None
FailureDetail : EdgeSync service cannot connect to this subscription because of error "No EdgeSync creden
tials were found for Edge transport server servername.domain.lan on the local Hub Transport
server. Remove the Edge subscription and re-subscribe the Edge Transport server.".
LeaseExpiryUtc : 1-1-0001 0:00:00
LastSynchronizedUtc : 1-1-0001 0:00:00
TransportServerStatus : Skipped
TransportConfigStatus : Skipped
AcceptedDomainStatus : Skipped
RemoteDomainStatus : Skipped
SendConnectorStatus : Skipped
MessageClassificationStatus : Skipped
RecipientStatus : Skipped
CredentialRecords : Number of credentials 0
CookieRecords : Number of cookies 0
As you can see the "Syncstatus" is failed.
Get-ExchangeCertificate | fl
AccessRules :System.Security.AccessControl.CryptoKeyAccessRule,
System.Security.AccessControl.CryptoKeyAccessRule, System.Security.AccessControl.CryptoKeyAccessRule}
CertificateDomains : {servername.domain.lan, outlook.domain.lan, mail.domain.lan, webmail.domain.nl, autodiscover.domain.nl, }
HasPrivateKey : True
IsSelfSigned : False
Issuer : CN=Domain-IssuingCA, DC=Domain, DC=lan
NotAfter : 15-8-2013 14:08:18
NotBefore : 4-3-2013 11:11:46
PublicKeySize : 2048
RootCAType : Enterprise
SerialNumber : 537C7FB7000200000BE7
Services : IMAP, POP, IIS, SMTP
Status : Valid
Subject : CN=Servername.domain.lan, OU=ICT, O=Company, L=State, S=Provence, C=Country
Thumbprint : XXXXXXXXXXXXXXXXXXXXXX3954C8D6C78B
Check thumbprint
Set thumbprint as Exchange enabled cert
Enable-ExchangeCertificate -Thumbprint XXXXXXXXXXXXXXXXXXXXXX3954C8D6C78B -DoNotRequireSsl -services:SMTP,IIS,IMAP,POP
The problem right now is we do not refresh the certificate used by ADAM when issue a new subscription, so if you have created a new certificate, we keep presenting the old one. Ok, so here's what you need to do to get ADAM to present the new one:
1. On the Hub, Remove the Subscription
2. On the Edge, Remove the cert used by ADAM to establish secure
connections. You can do this by following the following steps:
- a. Open up an empty mmc console (Run -> mmc)
- b. Select File -> Add / Remove Snap-in
- c. Hit Add
- d. Select "Certificates" from the List of Snap-Ins available, and
- hit Add.
- e. Select "Service Account" on the "Certificates Snap-In" page,
- click next.
- f. Select "Local Computer" on the "Select Computer" page, click
- next.
- g. Select "Microsoft Exchange ADAM" from the list of services,
- click Finish.
- h. Close the "Add Snap-in" dialog.
- i. Navigate to "Certifcates – Service" ->
- "ADAM_MSExchange\Personal" -> Certificates
- j. You should see a single certificate here. Remove it.
3. On the Edge, Unsubscribe, then create a new subscription file
(you should see a new certificate show up at this point on the ADAM cert container from the step above) by calling new-edgesubscription
New-EdgeSubscription -FileName "Path to file".xml
4. Re-start the "Microsoft Exchange ADAM" service.
5.Export the file to the Hub server.
6.On the Hub server import the new subscription.7.Create a new Edge subscription in the EMC
Then you have to wait a few minutes.
To check if synchronization works run;
start-edgesynchronization
test-edgesynchronization
Source 2
Labels:
Exchange 2010,
Powershell
Location:Utrecht
Utrecht, Nederland
24 June 2013
Modify "Linked","Legacy" and "Shared" mailbox types in Exchange 2010
Every now and then Exchange messes up the mailbox types after moving between databases.
Here's how to change the mailbox types:
Linked;
Set-User "User Name" -LinkedMasterAccount $null
Legacy;
set-Mailbox alias -ApplyMandatoryProperties
Shared;
Set-Mailbox "Alias" -Type Regular
From user type to Shared type
Set-Mailbox "Username" -Type Shared
Here's how to change the mailbox types:
Linked;
Set-User "User Name" -LinkedMasterAccount $null
Legacy;
set-Mailbox alias -ApplyMandatoryProperties
Shared;
Set-Mailbox "Alias" -Type Regular
From user type to Shared type
Set-Mailbox "Username" -Type Shared
Labels:
Exchange 2010,
Powershell
Location:Utrecht
Utrecht, Nederland
17 June 2013
“Upgrade” Distribution Groups after moving from Exchange 2003 To 2010 and find empty distribution lists
When migrating from Exchange 2003 to Exchange 2010, you have to upgrade the distribution groups to 2010 level.
Here's how;
While co-existing Exchange 2003 with 2010, the “membership approval tab” on the distribution groups property page is all grayed out. You can’t manage any settings in that tab at all. The behaviour is the same for universal and global groups.
If you make any change to the group (like editing the name), the console asks whether you want to upgrade the object and that you no longer will be able to manage it with legacy Exchange tools.
Another efficient way of upgrading the distribution group is to use PowerShell. Run the command below to upgrade.
Set-DistributionGroup –identity “groupname” –ForceUpgrade
Get-DistributionGroup –resultsize unlimited | Set-DistributionGroup –ForceUpgrade
After this some cleanup may be required. Deleting the empty DSG's
$dls= get-distributiongroup -resultsize unlimited
$dls |? {!(get-distributiongroupmember $_)}
When the powershell command returns, it shows the distributiongroups that have no members.
Name DisplayName GroupType PrimarySmtpAddress
---- ----------- --------- ------------------
DSGname DSGDisplayname Global,SecurityEnabled DSGSMTPaddress
---- ----------- --------- ------------------
DSGname DSGDisplayname Global,SecurityEnabled DSGSMTPaddress
Labels:
Exchange 2010,
Powershell
Location:Utrecht
Utrecht, Nederland
04 June 2013
Find and reset disconnected RDP Sessions
We have a lot of servers. When I get disconnected, I may leave hanging sessions on those servers which I forget to properly close. Then, after I change the password for my admin account, I sometimes get locked out as a result of what I had open in the now disconnected session.
Tracking this down is always annoying and time consuming.
When users (including administrators) are terminated, you want to find and reset those sessions too.
ServerSessions.vbs is a script for admins to run to track down sessions on servers and optionally reset them. You can list sessions on all servers in a domain, and reset either all or just disconnected sessions
The script in VBS:
'ServerSessions.vbs
'Lists and optionally resets a user's server sessions
'Alan dot Kaplan at VA dot Gov.
'10/24/2011. 10/26 version fixed logging when list only
Option Explicit
dim wshShell
Set wshShell = WScript.CreateObject("WScript.Shell")
Dim retval
Const ADS_CHASE_REFERRALS_ALWAYS = &H20
Dim oConn, oCmd, oRS
Dim strADSPath, strADOQuery
Dim strDomainCN
Dim fso,logfile, appendout
Dim strUser, strSessionID
'Get the default ADsPath for the domain to search.
Dim root: Set root = GetObject("LDAP://rootDSE")
strADSPath = root.Get("defaultNamingContext")
Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If (Not IsCScript()) Then 'If not CScript, re-run with cscript...
dim quote
quote=chr(34)
WshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote, 1, true
WScript.Quit '...and stop running as WScript
End If
If InStr(1,MyOS,"Server",1) = 0 Then
MsgBox "You must run this from server OS",vbExclamation + vbOKOnly,"Error"
'WScript.Quit
End If
retval = MsgBox("This script will identify and optionally logoff disconnected sessions for a user on all of the servers " & _
"in AD within a domain. Do you want to continue?",vbYesNo + vbQuestion,"Get List of all Servers")
If retval = vbNo Then WScript.Quit
strADSPath = InputBox("Get server list from what domain","Domain",strADSPath)
If strADSPath = "" Then WScript.Quit
strUser = InputBox("Search for what username?","User Name",wshShell.ExpandEnvironmentStrings("%USERNAME%"))
If strUser = "" Then WScript.Quit
dim message
message = "Do you want to:" & VbCrLf & _
"1) Get list only" & VbCrLf & _
"2) Reset disconnected sessions" & VbCrLf & _
"3) Reset all sessions for user" & VbCrLf & _
"0) Quit"
Dim iActionType
iActionType = InputBox(message,"Choose Action",1)
iActionType = CDbl(iActionType)
If iActionType = 0 Then WScript.Quit
GetServerList
wshShell.Run "notepad.exe " & quote & logfile & quote
' =========== Functions and Subs ==========
Sub GetServerList()
'--- Set up the connection ---
Set oConn = CreateObject("ADODB.Connection")
Set oCmd = CReateObject("ADODB.Command")
oConn.Provider = "ADsDSOObject"
oConn.Open "ADs Provider"
Set oCmd.ActiveConnection = oConn
oCmd.Properties("Page Size") = 50
ocmd.Properties("Chase referrals") = ADS_CHASE_REFERRALS_ALWAYS
logfile = Replace(strADSPath,",","_")
logfile = Replace(logfile,"DC=","")
logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\" & strUser & " In " & logfile & ".txt"
If fso.FileExists(logfile) Then fso.DeleteFile logfile,True
set AppendOut = fso.OpenTextFile(logfile, ForAppend, True)
strDomainCN = DomainCN(strADSPath)
'--- Build the query string ---
strADOQuery = "<LDAP://" & strDomainCN & "/" & strADSPath & ">;" & "(&(OperatingSystem=*Server*)(objectClass=computer))" & ";" & _
"Name;subtree"
oCmd.CommandText = strADOQuery
'--- Execute the query for the object in the directory ---
Set oRS = oCmd.Execute
If oRS.EOF and oRS.Bof Then
MsgBox "No Servers AD entries found!",vbCritical + vbOKOnly,"Failed"
appendout.WriteLine "Query Failed"
Else
While Not oRS.Eof
SessionQuery oRS.Fields("Name")
oRS.MoveNext
Wend
End If
oRS.Close
oConn.Close
End Sub
Sub SessionQuery (strServer)
WScript.Echo "Checking " & strServer
dim objEx, data
Set objEx = WshShell.Exec("QWinsta /server:" & strServer)
'one line at a time
While Not (objEx.StdOut.AtEndOfStream)
data = objEx.StdOut.ReadLine
If InStr(1,data,strUser,1) Then
strSessionID = GetSession(data)
if iactionType = 1 then
EchoAndLog strServer & ",found session for " & strServer
Else
Wscript.echo strServer & ",found session for " & strServer
End if
'always logoff
If iActionType = 3 Then ResetSession strServer, strSessionID
'Logoff disconnected
If iActionType =2 And InStr(1,data,"disc",1) Then
ResetSession strServer,strSessionID
End If
End If
Wend
End Sub
Sub ResetSession(strServer, ID)
Dim strCommand, oExec
strCommand = "reset session " & id & " /server:" & strServer
Set oExec = WshShell.Exec(strCommand)
wscript.sleep 500
'this is typically empty
While Not (oExec.StdOut.AtEndOfStream)
EchoAndLog oExec.StdOut.ReadLine
Wend
If oExec.ExitCode <> 0 Then
EchoAndLog strServer & ",Problem resetting session " & ID & " on server " & strServer & ", Non-zero exit code, " & oExec.exitcode
Else
EchoAndLog strServer & ",Reset session " & ID & " on server " & strServer
End If
End Sub
Function DomainCN(strPath)
DomainCN = Replace(strPath,",",".")
DomainCN= Replace(DomainCN,"DC=","")
End Function
Function MyOS()
Dim oWMI,ColOS,ObjOS, OSver
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set ColOS = oWMI.ExecQuery("SELECT Caption, version FROM Win32_OperatingSystem")
For Each ObjOS In ColOS
MyOS = objOS.caption & Space(1) & objos.version
Next
End Function
Function GetSession(text)
text = strip(lcase(Text))
Dim tArray, i
tArray = Split(text,Space(1))
i = 0
While tArray(i) <> lCase(strUser)
i = i +1
Wend
GetSession = tArray(i+1)
End Function
Function Strip(text)
text = Replace(text,vbtab,Space(1))
While InStr(text,Space(2)) > 0
text = replace(text,Space(2),Space(1))
Wend
Strip = text
End Function
Sub EchoAndLog (message)
'Echo output and write to log
Wscript.Echo message
AppendOut.WriteLine message
End Sub
Function IsCScript()
If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then
IsCScript = True
Else
IsCScript = False
End If
End Function
Source
Tracking this down is always annoying and time consuming.
When users (including administrators) are terminated, you want to find and reset those sessions too.
ServerSessions.vbs is a script for admins to run to track down sessions on servers and optionally reset them. You can list sessions on all servers in a domain, and reset either all or just disconnected sessions
The script in VBS:
'ServerSessions.vbs
'Lists and optionally resets a user's server sessions
'Alan dot Kaplan at VA dot Gov.
'10/24/2011. 10/26 version fixed logging when list only
Option Explicit
dim wshShell
Set wshShell = WScript.CreateObject("WScript.Shell")
Dim retval
Const ADS_CHASE_REFERRALS_ALWAYS = &H20
Dim oConn, oCmd, oRS
Dim strADSPath, strADOQuery
Dim strDomainCN
Dim fso,logfile, appendout
Dim strUser, strSessionID
'Get the default ADsPath for the domain to search.
Dim root: Set root = GetObject("LDAP://rootDSE")
strADSPath = root.Get("defaultNamingContext")
Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If (Not IsCScript()) Then 'If not CScript, re-run with cscript...
dim quote
quote=chr(34)
WshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote, 1, true
WScript.Quit '...and stop running as WScript
End If
If InStr(1,MyOS,"Server",1) = 0 Then
MsgBox "You must run this from server OS",vbExclamation + vbOKOnly,"Error"
'WScript.Quit
End If
retval = MsgBox("This script will identify and optionally logoff disconnected sessions for a user on all of the servers " & _
"in AD within a domain. Do you want to continue?",vbYesNo + vbQuestion,"Get List of all Servers")
If retval = vbNo Then WScript.Quit
strADSPath = InputBox("Get server list from what domain","Domain",strADSPath)
If strADSPath = "" Then WScript.Quit
strUser = InputBox("Search for what username?","User Name",wshShell.ExpandEnvironmentStrings("%USERNAME%"))
If strUser = "" Then WScript.Quit
dim message
message = "Do you want to:" & VbCrLf & _
"1) Get list only" & VbCrLf & _
"2) Reset disconnected sessions" & VbCrLf & _
"3) Reset all sessions for user" & VbCrLf & _
"0) Quit"
Dim iActionType
iActionType = InputBox(message,"Choose Action",1)
iActionType = CDbl(iActionType)
If iActionType = 0 Then WScript.Quit
GetServerList
wshShell.Run "notepad.exe " & quote & logfile & quote
' =========== Functions and Subs ==========
Sub GetServerList()
'--- Set up the connection ---
Set oConn = CreateObject("ADODB.Connection")
Set oCmd = CReateObject("ADODB.Command")
oConn.Provider = "ADsDSOObject"
oConn.Open "ADs Provider"
Set oCmd.ActiveConnection = oConn
oCmd.Properties("Page Size") = 50
ocmd.Properties("Chase referrals") = ADS_CHASE_REFERRALS_ALWAYS
logfile = Replace(strADSPath,",","_")
logfile = Replace(logfile,"DC=","")
logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\" & strUser & " In " & logfile & ".txt"
If fso.FileExists(logfile) Then fso.DeleteFile logfile,True
set AppendOut = fso.OpenTextFile(logfile, ForAppend, True)
strDomainCN = DomainCN(strADSPath)
'--- Build the query string ---
strADOQuery = "<LDAP://" & strDomainCN & "/" & strADSPath & ">;" & "(&(OperatingSystem=*Server*)(objectClass=computer))" & ";" & _
"Name;subtree"
oCmd.CommandText = strADOQuery
'--- Execute the query for the object in the directory ---
Set oRS = oCmd.Execute
If oRS.EOF and oRS.Bof Then
MsgBox "No Servers AD entries found!",vbCritical + vbOKOnly,"Failed"
appendout.WriteLine "Query Failed"
Else
While Not oRS.Eof
SessionQuery oRS.Fields("Name")
oRS.MoveNext
Wend
End If
oRS.Close
oConn.Close
End Sub
Sub SessionQuery (strServer)
WScript.Echo "Checking " & strServer
dim objEx, data
Set objEx = WshShell.Exec("QWinsta /server:" & strServer)
'one line at a time
While Not (objEx.StdOut.AtEndOfStream)
data = objEx.StdOut.ReadLine
If InStr(1,data,strUser,1) Then
strSessionID = GetSession(data)
if iactionType = 1 then
EchoAndLog strServer & ",found session for " & strServer
Else
Wscript.echo strServer & ",found session for " & strServer
End if
'always logoff
If iActionType = 3 Then ResetSession strServer, strSessionID
'Logoff disconnected
If iActionType =2 And InStr(1,data,"disc",1) Then
ResetSession strServer,strSessionID
End If
End If
Wend
End Sub
Sub ResetSession(strServer, ID)
Dim strCommand, oExec
strCommand = "reset session " & id & " /server:" & strServer
Set oExec = WshShell.Exec(strCommand)
wscript.sleep 500
'this is typically empty
While Not (oExec.StdOut.AtEndOfStream)
EchoAndLog oExec.StdOut.ReadLine
Wend
If oExec.ExitCode <> 0 Then
EchoAndLog strServer & ",Problem resetting session " & ID & " on server " & strServer & ", Non-zero exit code, " & oExec.exitcode
Else
EchoAndLog strServer & ",Reset session " & ID & " on server " & strServer
End If
End Sub
Function DomainCN(strPath)
DomainCN = Replace(strPath,",",".")
DomainCN= Replace(DomainCN,"DC=","")
End Function
Function MyOS()
Dim oWMI,ColOS,ObjOS, OSver
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set ColOS = oWMI.ExecQuery("SELECT Caption, version FROM Win32_OperatingSystem")
For Each ObjOS In ColOS
MyOS = objOS.caption & Space(1) & objos.version
Next
End Function
Function GetSession(text)
text = strip(lcase(Text))
Dim tArray, i
tArray = Split(text,Space(1))
i = 0
While tArray(i) <> lCase(strUser)
i = i +1
Wend
GetSession = tArray(i+1)
End Function
Function Strip(text)
text = Replace(text,vbtab,Space(1))
While InStr(text,Space(2)) > 0
text = replace(text,Space(2),Space(1))
Wend
Strip = text
End Function
Sub EchoAndLog (message)
'Echo output and write to log
Wscript.Echo message
AppendOut.WriteLine message
End Sub
Function IsCScript()
If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then
IsCScript = True
Else
IsCScript = False
End If
End Function
Source
Labels:
Windows 2008,
WIndows 2008 R2,
Windows 2012,
windows 7,
Windows 8
Location:Utrecht
Utrecht, Nederland
How to and why block Linkedin access to your organization
This comes from Adam Fowler from www.adamfowlerit.com
Some more indepth view and testing was done by Paul Cunningham from www.exchangeserverpro.com
Recently Linkedin added a new feature to their site.
It gives you the abillity to search for contacts on your company address book.
How handy that may seem, the other side of this is that Linkedin is given your login credentials to the corporate Exchange environment.
I case of a security breach or hack over at our friends at Linkedin, your username, password, email address and webmail url are in the wrong hands posing a serious security issue.
So, here's how to stop Linkedin from accessing your Exchange servers:
First, under the Set-OrganizationConfig area, you'll need to check that EwsApplicationAccessPolicy is set to 'EnforceBlockList'
[PS] C:\Windows\system32>Get-OrganizationConfig | fl ews*
EwsEnabled :
EwsAllowOutlook :
EwsAllowMacOutlook :
EwsAllowEntourage :
EwsApplicationAccessPolicy :
EwsAllowList :
EwsBlockList :
If it shows up empty like above, you have to enable the blocklist.
[PS] C:\Windows\system32>Set-OrganizationConfig -EwsApplicationAccessPolicy enforceblocklist
[PS] C:\Windows\system32>
Next, you need to add LinkedIn into the BlockList.
[PS] C:\Windows\system32>Set-OrganizationConfig -EwsBlockList LinkedInEWS
Lets see how that looks.
[PS] C:\Windows\system32>Get-OrganizationConfig | fl ews*
EwsEnabled :
EwsAllowOutlook :
EwsAllowMacOutlook :
EwsAllowEntourage :
EwsApplicationAccessPolicy : EnforceBlockList
EwsAllowList :
EwsBlockList : {LinkedInEWS}
Adam Fowler's source
Paul Cunninham's source
Some more indepth view and testing was done by Paul Cunningham from www.exchangeserverpro.com
Recently Linkedin added a new feature to their site.
It gives you the abillity to search for contacts on your company address book.
How handy that may seem, the other side of this is that Linkedin is given your login credentials to the corporate Exchange environment.
I case of a security breach or hack over at our friends at Linkedin, your username, password, email address and webmail url are in the wrong hands posing a serious security issue.
So, here's how to stop Linkedin from accessing your Exchange servers:
First, under the Set-OrganizationConfig area, you'll need to check that EwsApplicationAccessPolicy is set to 'EnforceBlockList'
[PS] C:\Windows\system32>Get-OrganizationConfig | fl ews*
EwsEnabled :
EwsAllowOutlook :
EwsAllowMacOutlook :
EwsAllowEntourage :
EwsApplicationAccessPolicy :
EwsAllowList :
EwsBlockList :
If it shows up empty like above, you have to enable the blocklist.
[PS] C:\Windows\system32>Set-OrganizationConfig -EwsApplicationAccessPolicy enforceblocklist
[PS] C:\Windows\system32>
Next, you need to add LinkedIn into the BlockList.
[PS] C:\Windows\system32>Set-OrganizationConfig -EwsBlockList LinkedInEWS
Lets see how that looks.
[PS] C:\Windows\system32>Get-OrganizationConfig | fl ews*
EwsEnabled :
EwsAllowOutlook :
EwsAllowMacOutlook :
EwsAllowEntourage :
EwsApplicationAccessPolicy : EnforceBlockList
EwsAllowList :
EwsBlockList : {LinkedInEWS}
Adam Fowler's source
Paul Cunninham's source
Labels:
Exchange 2010,
Linkedin,
Powershell
Location:Utrecht
Utrecht, Nederland
30 May 2013
Powershell script to check for stopped "Automatically started" services for multiple servers
The powershell script below checks for services that are automatically started when the system starts.
If a service is found stopped, the scripts starts the service and sends a notification email to an admin or a group.
Multiple servers are supported, and services that stop automatically because they have no need to run al the time (software protection for instance) are filtered out.
Modify the following to adjust for your environment:
The script:
#####################################################################
# Author: Edwin van Brenk #
# date: 23-05-2013 #
# Purpose: Check if auto start services for a number of #
# servers are running, if not send a notification #
# email and start the service #
#####################################################################
$Computers = "server1","server2","server3","server4"
foreach ($Computer in $Computers)
{
#$exclusion = "clr_optimization"
Write-Host "checking server: $computer"
#Create an array of all services running
$GetService = Get-WmiObject win32_service -ComputerName $Computer | where {($_.startmode -eq "Auto") -and ($_.state -ne "Running")}
foreach ($service in $GetService)
{
if ($service.name -match "clr_optimization*")
{
Write-Host "`tService exclusion: " $service.name
}
elseif ($service.name -match "MMCSS")
{
Write-Host "`tService exclusion: " $service.name
}
elseif ($service.name -match "sppsvc")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "BMR Boot Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup SAN Client Fibre Transport Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "SysmonLog")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "Mapsvc")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup Vault Manager")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup SAN Client Fibre Transport Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup Key Management Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "RtcSrv")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "ShellHWDetection")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
else
{
$servicename = $service.name
Send-Mailmessage -to "admin1@domain.com","admin2@domain.com" -Subject "$servicename is stopped on $Computer" -from ServicesCheck@domain.com -Body "The $servicename service was found stopped on $computer. Check if the script started the service" -SmtpServer smtp.domain.lan
Write-Host "`tStarting service " $service.name ".." -NoNewline
$service.StartService()
Write-Host "Done!" -BackgroundColor Green
}
}
}
If a service is found stopped, the scripts starts the service and sends a notification email to an admin or a group.
Multiple servers are supported, and services that stop automatically because they have no need to run al the time (software protection for instance) are filtered out.
Modify the following to adjust for your environment:
- The service name you want to exclude
- The server array server names
- The email receipients
- The smtp server
The script:
#####################################################################
# Author: Edwin van Brenk #
# date: 23-05-2013 #
# Purpose: Check if auto start services for a number of #
# servers are running, if not send a notification #
# email and start the service #
#####################################################################
$Computers = "server1","server2","server3","server4"
foreach ($Computer in $Computers)
{
#$exclusion = "clr_optimization"
Write-Host "checking server: $computer"
#Create an array of all services running
$GetService = Get-WmiObject win32_service -ComputerName $Computer | where {($_.startmode -eq "Auto") -and ($_.state -ne "Running")}
foreach ($service in $GetService)
{
if ($service.name -match "clr_optimization*")
{
Write-Host "`tService exclusion: " $service.name
}
elseif ($service.name -match "MMCSS")
{
Write-Host "`tService exclusion: " $service.name
}
elseif ($service.name -match "sppsvc")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "BMR Boot Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup SAN Client Fibre Transport Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "SysmonLog")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "Mapsvc")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup Vault Manager")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup SAN Client Fibre Transport Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "NetBackup Key Management Service")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "RtcSrv")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
elseif ($service.name -match "ShellHWDetection")
{
Write-Host "`tService exclusion: " $Computer $service.name
}
else
{
$servicename = $service.name
Send-Mailmessage -to "admin1@domain.com","admin2@domain.com" -Subject "$servicename is stopped on $Computer" -from ServicesCheck@domain.com -Body "The $servicename service was found stopped on $computer. Check if the script started the service" -SmtpServer smtp.domain.lan
Write-Host "`tStarting service " $service.name ".." -NoNewline
$service.StartService()
Write-Host "Done!" -BackgroundColor Green
}
}
}
Labels:
Exchange 2010,
Powershell,
Windows 2008,
WIndows 2008 R2
Location:Utrecht
Utrecht, Nederland
23 May 2013
How to delete an activesync partnership
Over time users buy new phones, add tablets or Windows 8 mail apps to their corporate mail.
This clutters the ActiveSync partnership as only 10 devices are max supported.
This shows how to delete the unwanted ActiveSync partnership(s).
This clutters the ActiveSync partnership as only 10 devices are max supported.
This shows how to delete the unwanted ActiveSync partnership(s).
Get-ActiveSyncDeviceStatistics –Mailbox alias | Format-Table DeviceID, DeviceType, DeviceOSOutput:DeviceID DeviceType DeviceOS
-------- ---------- --------
Appl82XXXXT6A4S iPhone iOS 6.1.3 10B329
XXXX99427EA69C4070E3A9FFA5D7EA84 WindowsMail WINDOWS
XXXX59A3A6CE935CA7A176D6616793E2 WindowsMail WINDOWS
XXXX66426C02FEFAD9A8E189F7CB4746 WindowsMail WINDOWS
XXXX1D99A11C747C075A0828FD1F0358 WindowsMail WINDOWS
XXXXF213DACD1001CA7B97AF346F4C47 WindowsMail WINDOWS
XXXX6F8CDBB2D75B3C32898543996CAB WP8 Windows Phone 8.0.10211Delete the Windows 8 Phone:Get-ActiveSyncDeviceStatistics -Mailbox alias | ? {$_.DeviceOS -match "windows phone 8.0.10211"} | Remove-ActiveSyncDevice
Subscribe to:
Posts (Atom)
