Thursday, July 17, 2014



1.  Create file listing of all files or specific files (bare file names with path) from all subdirectories. It can be used to get listing of all such files on a drive letter.

DIR /S/B/A-D | FIND /I "*.xls" >> C:\Temp\XLSFILES.TXT

2. Read one text file for path/location of the files and then move those files to a folder. This may be suitable when you have files scattered all  over the place in multiple sub-directories and you only need to move/copy certain files to certain location

    for /f "delims=########" %a in (C:\Temp\XLSFILES.TXT) do copy /Y "%a" I:\DestFolder

    for /f "delims=########" %a in (C:\Temp\XLSFILES.TXT) do move /Y "%a" I:\DestFolder

3. List file name with path along with its size.
   for %F in ("c:\Users\Rajan\*") do @echo %F ------ %~zF

4. Combine logic to create a file listing of multiple file from different sub-directories and then get size of each file.

DIR /S/B/A-D >> E:\FileName.txt

for /f "delims=########" %F in (FileName.txt) do @echo %F ------ %~zF 
(assumed that user is running second command line from E:\> prompt)

4. If you have large number of text file(s) and you are only interested in certain line (containing specific words) from text file
   (a) Assume you have all your .txt files that are the input test file located in Files folder.
   (b) Create FindText.bat file and add following to it
@echo off
>results.txt (
FOR /F "delims=" %%i IN (TextFind.txt) DO (
FIND "%%i" files\*.txt | FINDSTR /v "^---- ^$"

Note: This example assumed that command prompt is already pointing to location where the BAT file is located and TextFind.txt is the file containing text that you will be searching for all *.txt files within Files folder.

Wednesday, July 16, 2014

Microsoft Windows NLB - Configure Exchange CAS high availability

Although for sites with high volume of network traffic coming to the CAS servers it is recommended to have hardware NLB, for sites that are small in size or do not have hardware NLB in hand Microsoft provides Windows Network Load Balancing as an option.

What I am going to mention below is something I built for my lab running Exchange 2013. You may want to check Microsoft best practices for your version of exchange before you follow this post. 

Legal Stuff: I or anyone related to me would not be responsible for any issue or loss caused if you follow this post.


1. Server names used for CAS Servers e.g. CAS1.katwal.local and CAS2.katwal.local
2. Make sure both CAS servers has TWO NIC cards (network interfaces). 
3. Write down IP addresses of the both CAS servers:
     CAS1.katwal.local =
     CAS2.katwal.local =
4. Dedicated IP address for NLB :
5. NLB/CAS URL name: mail.katwal.local  (I assume you already prepared your CAS servers for this alias e.g. SSL certificates are already having autodiscover.katwal.local and mail.katwal.local in their SAN and certificates are already installed on each CAS server)
6. Rename network interfaces that we are going to use on both CAS servers for NLB (to NLB) to make sure we can differentiate them.

Prepration of network interfaces for NLB configuration:

1. As I mentioned above change the network interfaces names to make sure we can differentiate them. In my case I renamed them to NLB.

2. On both servers assign the IP addresses as mentioned above and subnet mask. Make sure you DO NOT fill any DNS information or WINS information.

3. By going to ADVANCED TCP/IP settings screen, under DNS tab uncheck "Register this connection's addresses in DNS" on both servers. Similarly under WINS tab select "Disable NetBIOS over TCP/IP"

4. Check Network Adapter bindings on both machines to make sure NLB adapters are the first adapters in binding. I will give example from Windows 2008 R2 machine below:
  • Press ALT key to bring up the menu bar, go to ADVANCED menu
  • Select Advanced Settings
  • Under Adapters and Binding section, reorder positions of NIC interfaces to make sure NLB is the first interface and other network interface is second.

By default Network Load Balancing feature is not installed on the servers. Following are the steps to install and configure a NLB cluster:

1. Select START > Administrative Tools> Server Manager

2. Select Features > Add Features,  Select Network Load Balancing Manager, Select Install

3. Close Wizard when Network Load Balancing Manager is installed.

4. On CAS1 server select START > Administrative Tools > Network Load Balancing Manager

5. When NLB Console will start, right click on Network Load Balancing Cluster and select New Cluster.

6. On New Cluster: Connect screen, type FQDN for CAS1 server e.g. CAS1.katwal.local  and select Connect.

7. Select Network Interface with IP and select Next button.

8. On  New Cluster:Host Parameters windows select all default and select Next.

9. On New Cluster: Cluster IP addresses window select ADD button and add IPv4 IP address of NLB cluster which is with subnet mask of, select OK, select NEXT

10. On New Cluster: Cluster Parameters window under Full Internet Name section type the URL name selected above: mail.katwal.local 

11. Leave Cluster Operation Mode to be set to Unicast and select NEXT.

12. On Add/Edit Port Rule window, select Finish.

13. Allow some time for cluster to converge and turn into green colour icon.

14. Now log on to CAS2 server and use PING command to check if mail.katwal.local replies back on IP address that was assigned to NLB (

15. Just in case there is some issue with getting the reply back, check DNS Server configuration.

16. To add CAS2 server to the NLB Cluster open NLB Manager Console

17. Right Click on the cluster (mail.katwal.local) and select  Add Host To Cluster.

18. In Host Field type FQDN for CAS2 server (CAS2.katwal.local) and select Connect.

19. Select NLB interface with IP address of and select Next, Next.

20. Leave everything to default as we did earlier and select Finish.

21. Now you should see second node of CAS2 will start to converge just as CAS1 did earlier and you should see it with the green icon.

22. Verify that when one of the nodes is turned off from NLB Manager we can still get reply for URL (mail.katwal.local) from IP address Additional test will be to turn of both nodes from NLB manager and check if we cannot get to mail.katwal.local and then start only one node at a time.  

23. If using virtual machines you may want to have static MAC address that was provided when cluster was configured. You can get to it by using NLB manager and get to to the properties of Cluster and selecting Cluster Parameter tab. Once you have the MAC address if you are using VMWARE you can go to the properties of NIC we used for NLB and add the MAC address for making it static. Similarly in Hyper-V Manager configure NIC used for NLB and fill  in info under Static section. on Hyper-V also select Enable Spoofing of MAC Addresses.

24. To confirm changes to NIC have not broken anything restart both nodes one at a time and confirm that both nodes converge without issues.

25. Next step is to make sure NIC forwarding is done so that all OWA requests only go to NIC selected for NLB. Following is example of the command I ran on both of my CAS servers. 

netsh interface ipv4 set interface NLB forwarding=enabled

Make sure you start command prompt using Run As Administrator. Reply expected after running above command line is OK.

26. Now you can go ahead and start with Exchange Server 2013 Servers control panel (ECP) to define Internal and external URLs as you want those.

Tuesday, July 8, 2014

Exchange 2013 - Test-OutlookWebServices to verify four services functionality

Problem Description: At times we need to check if any of the following is having an issue


Those who are familiar with old version of Test-OutlookWebServices might have to watch for few changes in Exchange 2013.


1. By default user can run Test-OutlookWebServices. If you get error message similar to the following that means a user mailbox/test mailbox is not provided.

[PS] C:\Windows\system32>Test-OutlookWebServices Unable to find the client accesss monitoring user. Please run C:\Program Files\Microsoft\Exchange Server\V15\Scripts\New-TestCasConnectivityUser.ps1. Exception: Microsoft.Exchange.Monitoring.MailboxNotFoundException: Failed to find the mailbox. Mailbox = 'extest_1d3bbbbcd5f34@katwal.local'. at Microsoft.Exchange.Monitoring.CommonTestTasks.GetDefaultTestAccount(ClientAccessContext context) at Microsoft.Exchange.Monitoring.TestWebServicesTaskBase.GetMonitoringAccount()    
+ CategoryInfo : InvalidData: (:) [Test-OutlookWebServices], TestWebServicesTaskException    
+ FullyQualifiedErrorId : 5322965D,Microsoft.Exchange.Monitoring.TestOutlookWebServicesTask    
+ PSComputerName : exchange2013.katwal.local

 You can create a test user using the PS script mentioned in the error message above. Following are steps:
[PS] C:\Windows\system32>cd $exscripts
[PS] C:\Program Files\Microsoft\Exchange Server\V15\scripts>.\new-TestCasConnectivityUser.ps1

Please enter a temporary secure password for creating test users. For security purposes, the password will be changed regularly and automatically by the system.

Enter password: ***********

Create test user on: EXCHANGE2013.katwal.local
Click CTRL+Break to quit or click Enter to continue.:

UserPrincipalName: extest_1d3bbbbcd5f34@katwal.local WARNING: The command completed successfully but no settings of 'katwal.local/Users/extest_1d3bbbbcd5f34' have been modified.

You can enable the test user for Unified Messaging by running this command with the following optional parameters : [-UM DialPlan -UMExtension ] . Either None or Both must be present.

[PS] C:\Program Files\Microsoft\Exchange Server\V15\scripts>

Now when we will run the Test-OutlookWebServices we should run without issues.

2. Another method is to specify a particular mailbox. Following is an example:

[PS]C:\Windows\System32>Test-OutlookWebServices -identity:rajan@katwal.local -MailboxCredential (Get-Credential)