6

Scenario

My PowerShell folder contains a library of utility scripts. I have it shared and version controlled with GitHub between my work and home computers. At work I now have a number of projects where I want to take advantage of my script library.

Problem

When I update the a utility script, I don't want to copy it manually to all the work projects where it is used.

Possible solutions

  1. (Simple)

    Write a PowerShell function to copy my whole script library to a 'Dependencies\Scripts' directory under the working directory for each script project. As my script library grows, it may become difficult for others to find the library scripts that are relevant to the script project.

  2. (Overcomplicated?)

    Use some kind of 'requires' function in each work project script file that requires one of library scripts. When a library script is updated a tool can then decide which work projects require that library script and copy the latest version to the work project. If a script is run without the appropriate dependency it will throw an error that reminding the user how to get the latest version from the library.

Questions

  • Has anyone solved this problem before?
  • Are there existing dependency management tools for PowerShell that will do 2?
0

3 Answers 3

2

Have you considered NuGet? It supports package dependencies, updates, and private repositories.

See also: Use Nuget to Share PowerShell Modules in your Enterprise

Sign up to request clarification or add additional context in comments.

Comments

1

I created a solution for you that I think will fit your situation. I created it based off of the song playlist methodology. I created an xml document where you would list each of your scripts individually and in another node in the same document you list the scripts you want to copy for each project. I have created a working example of this below. Though it is not elegant when it comes to managing a few hundred script files or alot of projects but it gets the job done.

PS1 Script

[xml]$XML = gc "C:\XMLFile1.xml"
$Scripts = $XML.Root.Scripts.Script
$Projects = $XML.Root.Projects.Project
foreach($Project in $Projects){
    $ProjectLocation = $Project.CopyPath
    $ProjectScripts = $Project.Script
    foreach($Script in $ProjectScripts){
        $ScriptPath = ($Scripts|?{$_.ID -eq $Script.ID}|Select Path).Path
        Copy-Item -Path $ScriptPath -Destination $ProjectLocation
    }
}

XMLFile

<Root>
  <Scripts>
    <Script ID="1" Path="C:\1.PS1"></Script>
    <Script ID="2" Path="C:\2.PS1"></Script>
    <Script ID="3" Path="C:\3.PSM1"></Script>
  </Scripts>
  <Projects>
    <Project Name="Project1" CopyPath="\\Server\Share\Project1">
      <Scripts ID="1"/>
    </Project>
    <Project Name="Project2" CopyPath="C:\Projects\Project2">
      <Scripts ID="1"/>
      <Scripts ID="3"/>
    </Project>
  </Projects>
</Root>

Comments

0

A simple solution would be to use something like DropBox. You can see how I use it for my PowerShell Scripts here: http://www.ravichaganti.com/blog/?p=1963

You can get a DropBox account with 2GB of free space http://db.tt/1DID1mR. 2GB, in my opinion, is more than enough for simple scripts. There are also other choices in the market. However, I recommend DropBox. The free account supports restoring 30 days old file versions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.