Using PowerShell to update a local folder from a central location

Share this:

In this Tutorial we will use PowerShell to update a local folder from a central repository using versioning control. You may be wondering what is the benefits, well it all depends of the scenario. In the customer that requested this feature is a large company with several sites and they want the ability for the local administrators to have some basic scripts and tools locally, and that is the idea of this Tutorial.

Another good example is for Exchange Administrators, let’s say we want to keep consistency with all scripts + CU locally before performing a troubleshoot, this script could be used for that as well.

Solution


Let’s keep it simple, first let’s use only two files at the Domain Controllers in the NETLOGON which is replicated among all Domain Controllers. We will use a file for control named WindowsServer.info and a second file which will be the script that the administrator will run locally to update his local copy with a central location and that file will be called Script-Update.ps1.

image[23]

In order to keep consistency, we could use Group Policies to create a folder o the C: root of each Server, for this example we will use the folder yOperations to be the location to be local folder with all scripts and tools. Another thing that we can do is to copy the Script-Update.ps1 file to the C:yOperations folder using the administrator logon script.

The WindowsServer.info file…

This file is the responsible for versioning control, we will have two columns initially: Version and Repository. The first one is self-explanatory and the second one is the location of the central repository, this way we don’t need to touch the script in case we change the central location.

image[36]

The Script…

Bear in mind that I’m an IT Pro and not a developer :), so any improvements you can use the comments area and I will be glad to update this post to reflect the changes. Basically we test to see if the local and remote version of the WindowsServer.info exist and if they are different then we will trigger a copy from the central location to the local folder.

Note: For this Tutorial the administrator is the responsible to run the Script-Update.ps1 to update the local folder on the server.

image[11]

How to use the script…

We made it simple as possible, and there are only two outputs. The first one is when the local version is up-to-date, then the following message will be displayed.

image[14]

The second is when there is a newer version, then the following output will be displayed and the local folder will receive the new files.

image[17]

How it works…

Let’s say that our corporate team added 3 new tools to be used by the administrators (which are the Tool01, Tool02 and Tool03).

image[26]

Now, the administrator just need to go to the control file (WindosServer.info) and update the value for the version, in this case we replace the previous value which was 4 to 5, then save the file.

image[29]

Now, when an administrator is logged on the server, he can run the Script-Update.ps1 and the message below will be displayed and all the tools in the central repository will be copied locally.

image[32]

Conclusion


In this Tutorial we show a simple script that uses a control file to copy files from a central location, a similar process can be used for several other tasks.

Written by Anderson Patricio

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).

Related Post

Performing Backup on your DHCP Server In this Tutorial we will be checking the process to protect the DHCP Server database using the automatic configuration, Graphical User Interface and P...
Checking if a mailbox is valid using Exchange Mana... In some scenarios we need to check if a mailbox database is valid on Exchange Server, this kind of validation is useful when migrating/transitioning m...
Hyper-V 2012 Hotfixes: Where I can find it and how... After my session at TechEd about Best Practices for Virtualizing and Managing Microsoft SharePoint 2013 with Microsoft System Center 2012 R2 and Windo...
How to install Microsoft Azure PowerShell In this Tutorial we are going over the process to install Microsoft Azure PowerShell and we can use the same procedure to update several other compone...