Thursday, March 27, 2014

PowerShell Tips : Joining paths using Join-Path cmdlet


Quote of the Day : "“Many of life’s failures are people who did not realize how close they were to success when they gave up” – Thomas Edison."

I am hoping that while using PowerShell , you have seen the  "Join-Path" cmdlet.

It is a very cool cmdlet and I have seems not much of the PowerShell scripters using it ( I was one of them ), to be honest even I was not much using it. But it is very useful and neat way to join to paths.

If you want to join two different path, there are two ways to do that, one is the dirty way (which you can see in my very old scripts) and the other one is using Join-Path cmdlet, neat and clean way.

The Dirty way.

If i want to join a path to my desktop folder using environment variable "UserProfile". I can use concatenation and concatenate it with $env:userprofile and adding "\" and adding Desktop.


$userDesktop = $env:USERPROFILE + "\" + "Desktop"


"26-03-2014 23-20-34

and you can see it give us a desirable result but it look dirty and it is a bad practice.

The Neat way.

Using Join-Path cmdlet.

$userDesktop = Join-Path $env:USERPROFILE -ChildPath "Desktop"

26-03-2014 23-25-07

 You can compare the result, the result is same, but, it looks clean and it is proper way to join two paths. and it is consider as good and best practice.

In both, ways, using concatenation or using "Join-Path" you will get the same result, but it is always good to use the neat and best way in scripting. 


thank-you-1 (1)


Aman Dhally



If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Tuesday, March 25, 2014

PowerShell Event : Join me at Global Windows Azure BootCamp 2014

Global Windows Azure BootCamp 2014

Noida, India
Register here : 

Event Details

Welcome to Global Windows Azure Bootcamp- 2014 !

We invite you to join us on Saturday, March 29, 2014 for a 1 day deep dive class on developing Cloud Computing Applications for Windows Azure. Join us for a full day session with lunch, high tea and a chance to network with fellow windows enthusiasts. 

Register for the event above or contact: Vikas Mangla ( @9810219770 for more information.

Event Details:

Venue: GlobalLogic India Limited, Noida

Timings: 9 am to 5 pm

Transport: To & Fro cab facility for all participants from Noida city centre metro station. Send in your details via email to for cab facility

Participant take aways: Windows Azure licenced software, Goodies powered by Windows Azure and GlobalLogic.




9 AM - 9:45 AM

Introduction to Windows Azure
Manu Sinha, Senior Solution Architect, GlobalLogic

9:50 AM - 10:45 AM

Cloud Architectures
Sandeep Mishra, Solution Architect, GlobalLogic

10:45 AM -11:00 AM

Tea Break

11:00 AM - 12:00 PM

Cloud Hybrid Features in forthcoming release of SQL Server 2014
Sarabpreet Singh Anand, SQL Server - MVP, Vice President,

12:00 PM - 1:00 PM

Windows Azure Access Control Service
Vikas Yadav, Technical Architect, GlobalLogic

1:00 PM-2:00PM


2:00 PM - 3:00 PM

Overview on how to connect to Windows Azure using PowerShell
Aman Dhally, Powershell MVP

3:00 PM - 4:00 PM

Service Bus - Introduction
Vikas Mangla, Senior Manager-Engineering, GlobalLogic

4:00 PM -4:15 PM

Tea Break

4:15 PM - 5: 00 PM

Virtual Machines - Introduction
Vikas Yadav, Technical Architect, GlobalLogic



Aman Dhally



If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.


Friday, March 14, 2014

PowerShell Tips: Change The Foreground Colour of PowerShell console using .net and PowerShell. and ,Happy Holi


Quote of the day Start where you are. Use what you have.  Do what you can. –Arthur Ashe


So, it’s nearly weekend.


On Monday we have a HOLI festival in India. The festival of colours.


Wishing you a very Happy Holi, , May, Your life, be colourful with the colours of joy, fun , happiness and love.


That’s all? , arrrrrrrr!!!


Let’ me wish you in a PowerShell way.


14-03-2014 19-27-10


Let’s learn how to change the foreground colour of Windows PowerShell Console.

There are two ways to change the foreground colours of the Console using code, {I know these two ways only for now, the third once is to, go to the properties off Powershell.exe, click on Colours and choose the colour.}.

1.    The PowerShell way.

2.    The .Net way


In PowerShell way, you can use $Host.UI.RawUI  and use ForegroundColour properties to change the text colour of the console.

$Shell = $Host.UI.RawUI

$Shell.ForegroundColor = "Green"


14-03-2014 20-38-54



And In our .Net way, you can use  [System.Console]::ForegroundColor  class

  to set the foreground colour.

[System.Console]::ForegroundColor = “Magenta”


14-03-2014 20-40-25



14-03-2014 20-40-57


Cool and lovely isn’t?


That’s all for now., I hope you liked this video.


Happy Holi. Enjoy it.


And,,,, this is the code of the happy Holi  script.


$myColours = "Green","Red","Blue","Yellow","Cyan","Magenta", "White"


foreach ( $colour in $myColours ) {

    [System.Console]::ForegroundColor = $colour

    Write-Output ">===> Happy Holi!!!'May your life be colourful  with the colors of joy, Fun, Happiness, Friendship and Love.., "








With best wishes.

Aman Dhally


If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.





Thursday, March 13, 2014

PowerShell Script : KB2692134 - Copy Outlook Contact's Other field data to other contact fields using PowerShell.


Quote of the Day: All our dreams can come true – if we have the courage to pursue them. – Walt Disney


If you remember, few days ago I have uploaded a script to which access “Outlook” contact’s using PowerShell and I also wrote a blog article on it.

In that post, I have also mention that, Why I need this kind of script to retrieve contacts from the outlook, you may know the answer in my coming blog posts.


Now please let me describe to you why I have written that script.


If you are an “Exchange 2007, Exchange 2010” administrator, then you must be aware of Microsoft knowledge base article number “KB 2692134”.


In “KB2692134” knowledge base Microsoft has mention this.



Consider the following scenario:

·         Your mailbox is hosted on a server that is running Microsoft Exchange Server 2007 or Microsoft Exchange Server 2010.

·         You create a new contact in Microsoft Office Outlook 2007.

·         Under Phone numbers, you type a telephone number in the Home and Mobile fields.

·         You click Business, click Other, and then type a telephone number in the Other field.

·         You synchronize your mobile device that uses Microsoft Exchange ActiveSync over-the-air.

In this scenario, the information in the Home and Mobile fields is synchronized as expected. However, the information in theOther field does not synchronize as expected


This issue occurs because the Exchange ActiveSync protocol does not support synchronizing some contact information.

More Information

The behaviour that is mentioned in the "Symptoms" section can occur if you change the field name for any of the default fields. For example, if you click Business, Home, Business FAX, or Mobile, and then change the field name to Other, the data is not synchronized as expected.

The following table summarizes the field names that will synchronize and that will not synchronize as expected:

Field names that will synchronize

Field names that will not synchronize







Business 2


Business Fax

Other Fax



Home 2


Home Fax







In nutshell, if you are running “Microsoft Exchange Server 2007” or “Microsoft Exchange Server 2012” , and if some of you user has telephone  number on there “Other” field of  Outlook contacts, they can’t see them on any device  which they has configure their email account using Active Sync.


Note: I am not sure, but I do believe “office 365 Exchange Online has a same issue too. {I tested this on iPhone + Office 365}”


Here comes the problem, if that user is your BOSS or Manager and he/she has an important telephone numbers in his/her Outlook contact’s  “other” , now what you will do? Show him/her the KB article? Do you think that going to work?

No! I am right, you have to do that.


If you check the above table, in the table “Field Names that will synchronize” we have two fields which normally most of the person won’t use, “Business 2” and “Home 2”.

What if? If we move the data from “Other” field to “Business 2” or “Home 2”.field.

Sound interesting? Yes it is. You like it, yes? Cool, now go and write a script to do it.  ;o) 


Don’t worry, I already done that for you too. You can download the script from the below link:

Download link :

How this script work.


This script run on a user’s laptop, it use the Outlook’s “Outlook. Application” as com object and bind it with PowerShell and do the further task.

How to use it.


Note: Before running it on a user’s laptop, make sure you backup his contact’s first.

I have tested this script on “windows 8.1” and with “Outlook 2013” installed and I do hope it worked well on “Windows 7” and with “Outlook 2010”.

In the screenshots, the script name is different, don’t worry, I have just renamed it after taking the screenshot.


You can see, in below screenshot that contact “Gobind”,”Aman” and Romy” has a data in there “Other Phone” field.

13-03-2014 17-04-17

Figure 1 Screenshot of  Outlook contacts, you can, see some has phone numbers in “Other Phone” , and some in “Business 2” and some in “Home 2”


Run the script, and you can see that, it will show you the list of all contacts, with their “other TelephoneNumber”, “FullName” , “First Name” and “Email Address field”.

13-03-2014 17-08-53

Figure 2 Script run, but no change has made, because “Edit-OtherOutlookContact” function is commented in the original script.”


Now open the script and uncomment the below “Edit-OtherOutlookCOntact” function and save the script file.


13-03-2014 17-10-37

Figure 3 Screenshot of the commented function


13-03-2014 17-11-33

Figure 4 Screenshot of the Function after un-commenting. {# removed from front of it}


Now run the script again, you can see, it done some changes on “Aman”, “Romy”, and “Gobind” contact names.


13-03-2014 17-13-16

Figure 5 , we run the script again, and you can see, that it is showing that, it is changing the comments and it also opened a text file, which has the name of the contacts which we have just changed.


When this script run, it saved the list of all users name those other fields are moved to either “Home 2” or “Business 2”.  This files open automatically when It changes anything, by default this file saves at:  "$env:APPDATA\ChangedContactList.txt"   , and the name of the file is ChangedContactList.txt”.


Let’s check our Outlook contacts.

You can see that. All or number from “Other” fields are either move to “Home 2” or Business 2”.


13-03-2014 17-27-03

Figure 6 Changes are made by the script. You can see that,


Remember: before moving number to “Home 2” or “Business 2”, this script check for existing data in any of these contact fields.

In-case if data is exists in “Home 2”, it will move the “Other” field data to “Business 2”, if “Business 2” has some data, then it try to save the data to “Home 2” fields.


What if? Home 2 and Business 2 both have the data.

In that case, it will create a text file named NotChangedContactList.txt" and open it for you , so that you can decide what to do next.

13-03-2014 17-29-03

Figure 7 If “Home 2” and “Business 2” fields are not blank, it will save the name of those contacts which has data in there “Other” filed and save it in to a file.


This file saves in the same location: "$env:APPDATA\NotChangedContactList.txt"


If you want to retain the data of the “Other” field. Then delete or uncomment the below scipt code in the script.


$name.OtherTelephoneNumber = $null ;


That’s all for toady and happy scripting.


clip_image016Download link :


Thanks for reading this post, I hope you will find it useful.




Aman Dhally



If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.