Share via


Automating config file changes : Part 1 – Installing Microsoft Windows Powershell

In the next few posts, I am going to write about ways to automate configuration file updates using Powershell. The method described in the following posts can be used to update any xml file, including web.config files by passing the required values and updating the desired keys in the file.

 

About Microsoft Powershell: Microsoft Windows PowerShell command line shell and scripting language helps IT professionals achieve greater control and productivity. Using a new admin-focused scripting language, more than 130 standard command line tools, and consistent syntax and utilities, Windows PowerShell allows IT professionals to more easily control system administration and accelerate automation. Windows PowerShell is easy to adopt, learn, and use, because it works with your existing IT infrastructure and existing script investments. More at https://www.microsoft.com/powershell

 

The first task we will do is to install Microsoft Windows Powershell on the machine.

Windows 2008: If you are Running Microsoft Windows 2008 Server OS, installing Powershell is really easy. Powershell comes as a Built-in feature. Follow these steps to install the feature:

  • Open the Server Manager from Start>Administrative Tools
  • Select the feature Windows Powershell if not already installed.image
  • Complete the Add Features Wizard to complete installation.

On earlier versions of Windows: You can install Microsoft Windows Powershell from https://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx 

Configure Powershell to run scripts:

Windows Powershell, by default does not allow execution of unsigned scripts.

The execution policy is part of the security strategy of Windows PowerShell. It determines whether you can load configuration files (including your Windows PowerShell profile) and run scripts, and it determines which scripts, if any, must be digitally signed before they will run.

You can see the current Execution Policy by following these steps:

  • Open Command Prompt (you will need to run Command Prompt as administrator if UAC is enabled).
  • Type Powershell.
  • Type get-executionpolicy and Press Enter to see the current execution policy.image By Default you will see Restricted as the output.

 

  • Change the execution policy to Unrestricted by using the command set-executionpolicy Unrestricted.Verify it by using get-executionpolicy
  • image

You can see detailed information about the executionpolicy and the various level by using the command get-help set-executionpolicy

If you are using a 64 bit OS, Powershell.exe will be installed at two locations:

%Windir%\System32\WindowsPowerShell\v1.0\powershell.exe

%Windir%\SysWoW64\WindowsPowerShell\v1.0\powershell.exe

It is recommended to open Powershell.exe from both these locations and set the execution policy to Unrestricted.

 

Please Note: We are setting the executionpolicy to Unrestricted so that we can run the scripts without signing them. Any script which is unsigned can be executed on the machine if run using an account with Administrator privileges. If you have signed scripts, you must use Allsigned or RemoteSigned execution level.

Comments

  • Anonymous
    April 12, 2009
    Thanks for the information...a bit technical, however insightful.

  • Anonymous
    April 12, 2009
    "Thanks for the information...a bit technical, however insightful." wow im like totly with that slow it n dumb it down instine we aernt all hs grads u no

  • Anonymous
    May 28, 2009
    This post contains the Powershell script to modify already existing config key values in a config file.

  • Anonymous
    May 28, 2009
    This post talks about removing an existing XML element from the config file. Consider a scenario where

  • Anonymous
    May 30, 2009
    After updating and deleting element from an XML config file, lets see how to add new elements at the