Write your First Desired State Configuration Script using ROLE Resource.

 

1.    Introduction of Windows PowerShell “Desired State Configuration”

2.    Installing Windows PowerShell 4.0 [Windows Management Framework 4.0]

3.    Getting Started With Desired State Configuration: DSC Syntax

4.    Review of Desired State Configuration : The 3 easy steps.

 

a-alphabet-kids-coloring-pictures-printablefter, so much of theory, it is time to write our first real “Desired State Configuration” script. 

 

 I am going to break this blog post in to two parts, in the first part we  will write a simple “DSC” configuration script and in second part we will run the script and see the result.

 

What is the purpose of our this “DSC” script?

 

I have  just installed a fresh windows 2008 Server on my machine, I do install “XPS Viewer” and “PowerShell ISE” in all of servers.  

Our “DSC” script will install these  two windows features for us stated below.

1.      XPS Viewer

2.      PowerShell ISE

 

Note: PowerShell 4.0 is installed on both machines, on the client machine in which  we are going to write the script, and on the Server on which we are going to push the configuration.

 

Machine configurations

Server

Windows 2008 Standard Edition, with PowerShell 4.0 installed.

16-04-2014 19-06-43

 

Client

Windows 8.1 , with PowerShell 4.0 Installed

16-04-2014 19-07-56

 

 

Let’s get started.

Step one: run your PowerShell-ISE as an “Administrator”

 

When you run “PowerShell-ISE” as an “Administrator”, the console path is set to “C:\Windows\System32” by default.

 

16-04-2014 19-25-57

 

Please change the console path

to “C:\users\YourNAME\Documents\WindowsPowerShell\Modules”. The reason for changing the

console path is, “when we execute the DSC configuration script, it creates a folder and generates

MOF file and we don’t want to end up creating files and folders in the “C:\Windows\System32

directory.

16-04-2014 19-27-17

 

Configuration Script.

 

 

 

 

Configuration myServerRoles {

 

    Node ‘Posh-Demo’

     {

   

            #Installing XPS viewer.

 

            WindowsFeature xpsViewer

 

            {

                            

             Name = ‘XPS-Viewer’

 

             Ensure = ‘Present’

           

            }

   

   

            # installing PowerShell ISE to the Server

           

            WindowsFeature ‘powerShellISE’

 

            {

           

            Name = ‘PowerShell-ISE’

 

            Ensure = ‘Present’

           

            }   

     }

 

}

 

myServerRoles 

 

 

 

16-04-2014 19-59-03

 

1. We start  with writing script using “Configuration” keyword followed by the name of the configuration, I am using “myServerRoles. This name can be any string name.

 

2.  I am mentioning the “Node” keyword to providing my sever name “Posh-Demo” for which we are writing the configuration.

 

3. We are using the “Role Resource of the DSC” which had the keyword “Windowsfeature” and followed by the name, this name can be any string.

 

4. The Name can be anything for “WindowsFeature” script block.

 

5 & 6. They are the declrations of the “WindowsFeature” DSC resource.

7.      In “Name” ,we have to provide the “Exact name of the Windows feature or Role which we are planning to install

8.      In “Ensure” , we are provide the value of either “Present” or “Absent”.

 

 

In my next Windowsfeature Script block, I will configure it to install the “PowerShell-ISe” feature. The syntax and declaration is almost same, except the name of the feature to Install.

Note : You can read more about “Role” DSC resource from this link : http://technet.microsoft.com/en-us/library/dn282127.aspx

Our configurations script seems simple and easy to write. What? You have a question?

 

Ok, ask………

 

How to find the name of the windows feature?

 

Very nice question. Let me describe it a bit more. :)

 

To know the list of all Windows Features, go to your server, Open the PowerShell and hit this cmdlet.

 

Get-WindowsFeature , and it will give you the name of all available features and roles; we can use these names in  “WindowsFeature“  resource block in DSC configuration scripts

 

16-04-2014 19-24-43

 

 

Let, me explain few tips regarding window features.

 

  • In Point 1, we are seeing the names of all windows features available, while writing DSC scripts, you have to use these Names, liked “AD-Cerificate”, “ADLDS”, and “DHCP” etc.
  • There are 2 Types of window features, the first type of features are those that have sub features, like you are seeing in point2, “Active Directory Certificate Service” have 4 sub features, if you want to install “active Directory Certificate Service” with sub features, you have to Set  IncludeAllSubFeature = $true in the DSC configuration Script.

     

     

    Sample script with sub features should be look like this.

    clip_image011

  • The second type of windows features are those, which have no “Sub features”, in the point 3, you can see that FAX feature doesn’t have any sub feature.

     

    Our, Configuration Script is ready”!. Smile 

     

    In our next blog post we will see this script in Action.

     

    Thanks for your time and I hope that you will find this post helpful.

     

    i-am-iron-man 

     

    Regards

    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”.

  • Review of Desired State Configuration : The 3 easy steps.

     

    1.      Introduction of Windows PowerShell “Desired State Configuration”

    2.     Installing Windows PowerShell 4.0 [Windows Management Framework 4.0]

    3.      Getting Started With Desired State Configuration: DSC Syntax

     

    155-i-alphabet-kids-coloring-pictures-printableN my previous blog post, I have shared the syntax of the DSC configuration file.

    Today  we are going to review the basic steps of the DSC configurations once again, so that in next blog post we can straight away jump in and start writing the real world DSC configuration scripts.

    “Yayyyy!”

    In my prospective, there are 3 major steps that are involved in a Desired State Configuration.

    These steps are:

    1.      Creating configuration file,

    2.      Running the script,

    3.      Deploying it.

     

    15-04-2014 00-04-53

     

    1.Creating Configuration File

     Picture1

    In my previous post, I had shown you all about how to create a configuration file and what should be the syntax, please visit the post here.

    2.Running Configuration file.

    Picture2

    When we  have finished writing our configuration file, we would execute them, like we execute functions.

    When we run a configuration file, it generates a MOF file. The MOF file contains the information for the Target node; about what to do, what to configure, what to check or so on.

     

    3.Deploying

    Picture3

    The third and final part is deploying the MOF file, there are 2 ways to do it, one is PUSH method and the other is Pull method.

    In “Push method“, we use “Start-DscConfiguration” cmdlet to push MOF file to the target node (computer).

    In “Pull method“, we setup a HTTP server or centralize folder from where configuration files stored are automatically pulled.

    In coming blog post, we may discuss all of these points in details.

    Simple, and easy to remember points. Isn’t it?

    I hope when you would be writing your first DSC file, these big-big boxes appear in front of your eyes and remind you about what to do the next.

    See you in my next blog post.

    Thanks for your time.

     Bird-says-thank-you

    Regards

    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”.

     

    Getting Started With Desired State Configuration: DSC Syntax

    Quotes

    1.  Introduction of Windows PowerShell “Desired State Configuration”
    2.  Installing Windows PowerShell 4.0 [Windows Management Framework 4.0]

    The Windows PowerShell Desired State Configuration is mainly contains three parts.

    1.      Configuration Block

    a.      Support Parameters too using Param( ).

    2.      Node Block

    a.      We can have one or more “Node Blocks”

    3.      Resource Block

    a.      We can have one or more “Resource Blocks”

     

    “Configuration Block”

     

    In Windows PowerShell DSC Microsoft has introduced a new keyword, naming it as “Configuration”.  All magic is doing here.  The Syntax of “Configuration” is almost same as Windows PowerShell “Function”.

    To configure DSC in our environment, we need to define a script block first, starts with keyword “Configuration” then a string Value / Name for the configuration and opening and closing braces ({ }) .

     

    Configuration anyName {

     

     

     

     

    }

     

    clip_image001

     

    Node Block

     

    Inside the “Configuration Block”, we have to define another block name as “Node Block”. In this block we define the name of the computers on which we are going to apply “Desired Stare Configuration” and export MOF file.

    In “Configuration Block”, can have one more Node Blocks.

    The Syntax of “Node Block” is simple, is starts with “Node” keyword, then name of the computer, then opening and closing braces ({ }).

     If we want to deploy DSC on more than one computer, we can use a comma separated list encapsulated in brackets ( ). We can also use variable in computer name position.

    Rest of everything will be goes inside the curly braces of the “Configuration”  script block.

     

         Node “myServer-01″ {

     

     

     

      

         } #closing brace for Node

     

    clip_image001[4]

    Mentioning multiple computers.

       Node (“myServer-01″,“MyServer-02″) {

     

     

     

      

         } #closing brase for Node

     

     

    clip_image002

    It should be look this.

    clip_image001[6]

     

    “Resource Block”

     

    Inside the “Node block”, we have to specify the “Resource Block”. A “Resource Block” starts with a name of Resource like “File”, ”Archive”  etc.,  following the string identifier / name, and then opening and closing braces ({ }).

    We can have multiple Resource Blocks in a “Node Block” . Inside the “Resource Block” we declare the properties and value of the resource.

    “Node Block” can have one or more resources blocks.

     

                WindowsFeature MyExampleFeature 

                    

                 {

     

                       

                       

                 } #Closing brase for WindowsFeature MyExampleFeature

     

    clip_image002

    Normally it will look this with without parameterizing.

    03-04-2014 11-21-00

    “Parameterizing Configuration Script”

     

    We can also parameterizing the DSC configuration script like functions. We just need to use the Param( ) and then we can define our parameters inside it.

     

      Configuration anyName

    {

     

     Param (

     [string[]]$myServer = “Server-01″

     )

     

        Node $myServer

           {

     

                WindowsFeature MyExampleFeature 

                 {

     

                       

                       

                 } #Closing brase for WindowsFeature MyExampleFeature

         

     

          } #closing brase for Node

     

     

     

    } #Closing brase for Configuration

     

    03-04-2014 12-47-19

    That’s all for today, see you in next blog post.

    thank-you-all

     

    Regards

     

    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”.

    Installing Windows PowerShell 4.0 [Windows Management Framework 4.0]

    Quote of the Day :Courage doesn’t always roar. Sometimes courage is the quiet voice at the end of the day saying, “I will try again tomorrow.” – Mary Anne Radmacher”

    Overview of WMF 4.0 : http://www.microsoft.com/en-us/download/details.aspx?id=40855

     

    I have mention in my previous blog post, that to leverage the benefits of the DSC, we have to install the PowerShell Version 4.0.

    Windows PowerShell 4.0 is a part of the “Windows Management Framework 4.0” [WMF 4.0].

    What WMF 4.0 includes

    WMF 4.0 included the following.

    1.      Windows PowerShell

    2.      Windows PowerShell Integrated Scripting Environment (ISE)

    3.      Windows PowerShell Web Services (Management OData IIS Extension)

    4.      Windows Remote Management (WinRM)

    5.      Windows Management Infrastructure (WMI)

    6.      Server Manager WMI provider

    7.      Windows PowerShell Desired State Configuration (DSC)

     

    Note: Make sure, PowerShell 4.0  is required on the both machines where you are going to write configuration scripts and on the Server and nodes where you want to deploy exported MOF files.

    Supporting operating system

     

    PowerShell 4.0 {WMF 4.0} can be installed / available  on the below operating Systems.

    OS

    Built In

    Service Pack

    Edition

    Windows 7

    No

    Service Pack 1

    All

    Windows Embedded 7

    No

     

    All

    Windows Server 2008 R2

    No

    Service Pack 1

    All except IA64

    Windows Server 2012

    No

     

    All except IA64

    Windows 8

    No

     

    You can’t install it on Windows 8, upgrade it to 8.1 , then you can install it.

    Windows 8.1

    Yes

     

     

    Windows Server 2012 R2

    Yes

     

     

     

    Note: WMF 3.0 [PowerShell V3] and WMF 2.0 [PowerShell V2] and not required for the installation of WMF 4.0 [PowerShell 4.0]

     

    Requirements for installation:

    .NET Framework 4.5 must be installed before installing WMF 4.0. Also Try to install all windows update before installing PowerShell 4.0 [WMF 4.0]

     

    Installation on windows 7 or Windows 2008 R2

     

    Windows 7

     

    You can find description on WMF 4.0 at this link :     http://support.microsoft.com/kb/2819745

    1.      Download and Install Service Pack 1 for windows 7,  if it is not already installed.

    a.      http://www.microsoft.com/en-us/download/details.aspx?id=5842

    2.      Download and Install .Net Framework 4.5

    a.      http://www.microsoft.com/en-us/download/details.aspx?id=30653

    3.      Download WMF 4.0 and double click on .msu file to start installation.

    o   X86

    §  Windows6.1-KB2819745-x86.msu 

    §  http://www.microsoft.com/en-us/download/details.aspx?id=40855

    o   X64

    §  Windows6.1-KB2819745-x64-MultiPkg.msu

    §  http://www.microsoft.com/en-us/download/details.aspx?id=40855

    4.      Reboot your computer once installation is finishes.

     

    Windows 2008 r2

    You can find description on WMF 4.0 at this link:      http://support.microsoft.com/kb/2819745

    The installation of PowerShell 4.0 on Windows 2008 R2 Server is same as windows 7.

    I have installed PowerShell 4.0 in one of my freshly installed sever, so it is worth sharing the screenshots of the installation with you.

    1.      Make sure that Service Pac1 is installed on your Windows 2008 R2 Server, if Service Pack is not installed , please install it.

    a.      http://www.microsoft.com/en-us/download/details.aspx?id=5842

    b.       02-04-2014 12-14-07

    2.      Download and install .Net 4.5

                                                                  i.     http://www.microsoft.com/en-us/download/details.aspx?id=30653

                                                                ii.      Accept the Terms

                                                              iii.      Click on Install.

                                                               iv.      02-04-2014 14-35-55

                                                                 v.      02-04-2014 14-36-23

                                                               vi.      After few minute {depends on on your internet connection speed} you will see the finish screen on the .NET installer, click on FINISH.

                                                             vii.      02-04-2014 14-46-49

    3.      Now, our .NET 4.5 is installed successfully, let’s check which version of PowerShell is installed on the server.

    a.      Run $PSVersionTable to check the installed PowerShell version,

                                                                  i.      You can see, currently PowerShell version 2.0 is installed.

    b.      02-04-2014 14-47-19

    4.      Ok’ , let’s run the installation file for WMF 4.0

    a.      X64

                                                                  i.      Windows6.1-KB2819745-x64-MultiPkg.msu

                                                                ii.      http://www.microsoft.com/en-us/download/details.aspx?id=40855

                                                              iii.      Download and run it

                                                               iv.       

                                                                 v.      02-04-2014 14-48-52

                                                               vi.       

                                                             vii.      It will ask you about , that if you want to install the update “KB2819745” , click on YES

                                                           viii.       

                                                               ix.      02-04-2014 14-49-36

                                                                 x.      N

                                                               xi.      Accept the licence Term and click on “I Accept”

                                                             xii.      02-04-2014 14-49-51

                                                           xiii.       

                                                           xiv.      It will start the installation of the WMF 4.0

                                                             xv.       

                                                           xvi.      02-04-2014 14-50-04

                                                         xvii.      A

                                                       xviii.      Once the installation is finishes, it will ask you to reboot the server,  please reboot it.

                                                           xix.      02-04-2014 14-52-29

    b.      Once you reboot the server , and login back, open the PowerShell console and run the $PSVersionTable to check the PowerShell version

                                                                  i.      $psVersionTable

                                                                ii.      And you can see that we have 4.0 installed J

                                                              iii.      02-04-2014 15-05-39

     

     

    Installation on Windows 2012

    Overview of WMF 4.0 :  http://support.microsoft.com/kb/2799888

    Installation of WMF 4.0 on windows 2012 is very simple.

    1.      .Net 4.5 is preinstalled in Windows Server 2012

    2.      Download Windows8-RT-KB2799888-x64.msu

    a.     http://www.microsoft.com/en-us/download/details.aspx?id=40855

    3.      Double click on the .msu file and install it.

    4.      Once it is installed, reboot your server.

    5.      Check the output of $psversionTable

     

     

    Things to remember

     

    Known Issue

     

    Problem: Installing WMF 4.0 on a computer that is not running .NET 4.5 , may report that the installation is successful but PowerShell 4.0 is not installed.

    Solution: Install .NET Framework 4.5 and run the installer again.

     

    That’s all for today, See you in next blog post.

     

    Thank-you (1)

    Regards

    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”.

     

     

    Introduction of Windows PowerShell "Desired State Configuration"

     

    Did you heard about “PowerShell DSC”?  NO?  

    You must me kidding me!!

    Come on, these days it is more famous and in demand compare to “ clip_image002 Justin Bieber” and “clip_image004 Shakira;)

     

    Ok, jokes a part.

     

    PowerShell DSC is the most uber-cool feature in PowerShell v4.

    I love it.

    It is introduced as the part of “Windows PowerShell V4”{wmf 4.0}.

    Why you care? And what it do for you?

     

    If you are lazy administrator, then it is a blessing for you, if you are busy administrator then it is a robot for you to help you out. It is a very good way to manage our IT infrastructure.

    As an example, you can automate the whole process of deploying website using DSC, from installing IIS, configuring them, and copy your website content to the IIS server.

    specs09

    Imagine, you just need to create a script once and that’s all, you can use it with any or many servers.

    DSC a new management platform for windows PowerShell, you just need to declare how you want to configure your software environment and it will do the rest for you.  

    You can also set dependencies, for example, you can set that website won’t be copied, until IIS is not installed).

     DSC syntax is declarative and it make maintaining the configuration much easier.

     

    Convinced? Yes? Good.

     

    DSC work with resource providers, by default there are 12 resource providers in WMF 4.0. You can also create your custom resource and providers too.

    List of Default Resources in WMF 4.0

    Provider

    Description

    Windows PowerShell Desired State Configuration Archive Resource

    Unpacks archive (.zip) files at specific paths on target nodes.

    Windows PowerShell Desired State Configuration Environment Resource

    Manages system environment variables on target nodes.

    Windows PowerShell Desired State Configuration File Resource

    Manages files and directories on target nodes.

    Windows PowerShell Desired State Configuration Group Resource

    Manages local groups on target nodes.

    Windows PowerShell Desired State Configuration Log Resource

    Logs configuration messages.

    Windows PowerShell Desired State Configuration Package Resource

    Installs and manages packages, such as Windows Installer and setup.exe packages, on target nodes.

    Windows PowerShell Desired State Configuration Process Resource

    Configures Windows processes on target nodes.

    Windows PowerShell Desired State Configuration Registry Resource

    Manages registry keys and values on target nodes.

    Windows PowerShell Desired State Configuration Role Resource

    Adds or removes Windows features and roles on target nodes.

    Windows PowerShell Desired State Configuration Script Resource

    Runs Windows PowerShell script blocks on target nodes.

    Windows PowerShell Desired State Configuration Service Resource

    Manages services on target nodes.

    Windows PowerShell Desired State Configuration User Resource

    Manages local user accounts on target nodes.

     

    DSC Resource Kit Waves

     

    To add the extra resources, you can download the DSC Resource Kit Wave1, Wave2, and Wave3 too. These Wave kits has extra configuration resources apart from 12 default resources.

     

    DSC Resource Kit wave 1

    http://blogs.msdn.com/b/powershell/archive/2013/12/26/holiday-gift-desired-state-configuration-dsc-resource-kit-wave-1.aspx

     

     

    Resource

    Description

    xComputer

    Name a computer and add it to a domain/workgroup

    xVHD

    Create and managed VHDs

    xVMHyperV

    Create and manage a Hyper-V Virtual Machine

    xVMSwitch

    Create and manage a Hyper-V Virtual Switch

    xDNSServerAddress

    Bind a DNS Server address to one or more NIC

    xIPAddress

    Configure IPAddress (v4 and v6)

    xDSCWebService

    Configure DSC Service (aka Pull Server)

    xWebsite

    Deploy and configure a website on IIS

     

     

    DSC Resource Kit wave 2

    http://blogs.msdn.com/b/powershell/archive/2014/02/07/need-more-dsc-resources-announcing-dsc-resource-kit-wave-2.aspx

     

    Resource

    Description

    Module Name

    xADDomain

    Create and manage an Active Directory Domain

    xActiveDirectory

    xADDomainController

    Create and manage an AD Domain Controller

    xActiveDirectory

    xADUser

    Create and manage an AD User

    xActiveDirectory

    xWaitForADDomain

    Pause configuration implementation until the AD Domain is available.  Used for cross machine synchronization.

    xActiveDirectory

    xSqlServerInstall

    Create and manage a SQL Server Installation.

    xSqlps

    xSqlHAService

    Create and manage a SQL High Availability Service.

    xSqlps

    xSqlHAEndpoint

    Create and manage the endpoint used to access a SQL High Availability Group.

    xSqlps

    xSqlHAGroup

    Create and manage a SQL High Availability Group.

    xSqlps

    xWaitForSqlHAGroup

    Pause configuration implementation until a SQL HA Group is available.  Used for cross machine synchronization.

    xSqlps

    xCluster

    Create and manage a cluster.

    xFailOverCluster

    xWaitForCluster

    Pause configuration until a cluster is available.  Used for cross machine synchronization.

    xFailOverCluster

    xSmbShare

    Create and manage a SMB Share.

    xSmbShare

    xFirewall

    Create and manage Firewall rules

    xNetworking

    xVhdFile

    Manage files to be copied into a Vhd.

    xHyper-V

    xWebsite

    Added functionality to xWebsite to support configuration of https websites.

    xWebAdministration

    xVhd

    Bug fixes

    xHyper-V

     

    DSC Resource Kit wave 3

    http://blogs.msdn.com/b/powershell/archive/2014/03/28/dsc-resource-kit-wave-3.aspx

     

    Module

    Resource

    Description

    xWebAdministration 

    xWebAppPool

    Create, remove, start, stop an IIS Application Pool

    xWebVirtualDirectory

    Create or remove a virtual directory

    xWebApplication

    Create or remove a web application

    xWebConfigKeyValue

    Configure AppSettings section of Web.Config

    xDatabase 

    xDatabase

    Create, drop & deploy databases

    xDBPackage

    Backup & restore databases

    xSystemSecurity 

    xUAC

    Enable or disable User Account Control prompt

    xIEEsc

    Enable or disable IE Enhanced Security Configuration

    xRemoteDesktopSessionHost 

    xRDSessionDeployment

    Creates and configures a deployment in RDSH. 

    xRDSessionCollection

    Creates a RDSH collection. 

    xRDSessionCollectionConfiguration 

    Configures a RDSH collection. 

    xRDRemoteApp

    Publish applications for your RDSH collection

    xPSDesiredStateConfiguration 

    xWindowsProcess

    Adds ability to run as a specific user to the existing WindowsProcess resource 

    xService

    Update to existing Service resource to include create/configure service

    xRemoteFile

    Download files from a URI

    xPackage

    Adds ability to run as a specific user to the existing resource, includes VS Setup

    xArchive

    Create, update, extract a Zip file

    xEndpoint

    Creates a remoting endpoint

    Updates

    xDscResourceDesigner, xComputer, xVMHyperV, xDNSServerAddress

    Feature additions and bug fixes

     

    Naming conventions,

     

    The resource and modules those names are started with “X” are means they are experimental, and those resource and modules are starts with “c” means, they are supported and provided by community. Microsoft reserve resourced and module name without any prefixed (“x”,”c”) for future use, if you are going to create you own custom resources, make sure, you can add some “prefix” in it for safe side J

     

    How it works.

     

    There are few steps to make DSC working

    1.      Create a DSC Configuration script.

    2.      Execute DSC configuration script.

    a.      When we run the configuration script, it produce a MOF file.

    3.      Deploy it

    a.      Using Pull Method

                                                                  i.      HTTP

                                                                ii.      HTTPS

    b.      Using Push Method

                                                                  i.      Manual Method

     

    When we deploy the MOF files to the node (computers), they will start configuring themselves.  

    Managed Object Format

    DSC is has a dependency on MOF, when we run  the DSC configuration script  it export the “MOF” document file.

    So what is the MOF?

    As per Microsoft documentation “Managed Object Format (MOF) is the language used to describe Common Information Model (CIM) classes.

                Source : http://msdn.microsoft.com/en-us/library/aa823192(v=vs.85).aspx

     

     

    That’s all for today, see you in next blog post.

    Thanks .

    thank you circle sentiment- paulaposts

    Regards

    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”.

     

     

     

     

     

    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)

    Regards

    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”.

    PowerShell Event : Join me at Global Windows Azure BootCamp 2014

    Global Windows Azure BootCamp 2014

    Noida, India
     
    Register here : http://www.eventbrite.com/e/global-windows-azure-bootcamp-2014-tickets-10829554489?aff=es2&rank=1&sid=e7a33c45b3e211e3b5731231391edcec 

    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 (vikas.mangla@globallogic.com) @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 vikas.mangla@globallogic.com for cab facility

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

    Agenda:

    Slots

    Topic

    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, SQLServerGeeks.com

    12:00 PM – 1:00 PM

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

    1:00 PM-2:00PM

    Lunch

    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


    clip_image018

    Regards

    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”.

     

    Book Review : "Confessions of a Public Speaker" Book by Scott Berkun "

    If you are group leader of any technical communities, you often do public speaking in the front of your group or sometime you do speak in the workshops and group events.

    But, do you know , how “Good” are you in speaking or how “Bad” you are? Do you enjoy it? or it is an obligation on you to speak.

    Do, you ever notice that you are using the same phrases again and again while speaking in the events or while giving presentations.?

    Do you afraid from public speaking but still want to  speak in the events but don’t know how to start?

    Do you feel fear and anxiety while delivering speech or presentations? and you don’t know how to get over from it ?

    Confessions of a Public Speaker

                  Scott Berkun 

                                                                 (“Scott Berkun”)

    I think, every public speaker face these problems, but most of   the time, we don’t admit it, we do believe and think that we are perfect and we never confess our mistake in giving presentations.

    I f something went wrong, we start thinking about that we have blow something or either  it’s world end.  

    What it take to be a good speaker? How we can improver our self in public speaking. ?  

    The answers of all these questions are, go and read the book “Confessions of a public speaker” a book by “Scott Berkun“. 

    One of my good fellow friends suggested me to read this book, I do speak at my “PowerShell” user group sometimes, but not much often, but when i started reading this book, i came to know the mistakes i have made in speaking and saw other presenters to do the same mistakes like me.

    For example, when I present slides in my group meeting, I use the phase “Here we go….” repeatedly , and this book suggested that  , these kind of practice make presentation boring and default, you can use the other words to say the same things.

    I have learn a lot form this book, it teaches those techniques and tips which we rarely find it somewhere else.  “Scott Berkun“  had written this book in such a way, that i keep you entertaining till the last page of the book.

    About “Scott Berkun”

    You can know more about the “Scott Berkun” on this website : http://scottberkun.com/about/ and for ordering book, you can check the Amazon link or your local book store or online portal. http://www.amazon.com/Confessions-Public-Speaker-English/dp/1449301959/tag=scottberkunco-20 

    What i have learn from this book.?

    1. If anything went wrong while giving presentation, that’ fine.
    2. If you made any mistake, that’ OK, humans do mistakes.
    3. Use stories in your presentation or while speaking.
    4. Always reach to  venue of event early.
    5. He confess about the mistakes which he make during presentation or speaking and he teaches to be honest with the audience.

    Book Rating : 3.4 / 5

    I hope that you will learn a lot from this book too, now go and grab your copy.

    I do hope you will find my review useful.

    thank you

    Regards

    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”.

    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

     

    J

    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.., “

     

     

     

    }

     

     

    clip_image007

    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”.

     

     

     

     

    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.

     

    KB2692134

    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

    Cause

    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

    Company

    Assistant

    Pager

    Callback

    Business

    Car

    Business 2

    ISDN

    Business Fax

    Other Fax

    Home

    Primary

    Home 2

    Other

    Home Fax

    Radio

    Mobile

    Telex

     

     

     

    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 : http://gallery.technet.microsoft.com/Copy-Other-field-data-of-e35891a0

     

    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

    To

    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 : http://gallery.technet.microsoft.com/Copy-Other-field-data-of-e35891a0

     

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

     

    clip_image018

    Regards

    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”.