Solved

script versions

Posted on 2014-01-30
4
178 Views
Last Modified: 2014-02-09
I'm tasked with automating a lot of tools this year and will be developing multiple scripts for various scenarios.
As I've found in the past, these can get passed around and stored in multiple locations.
When I created vbscripts, I would always head off my script to contact a source share to verify the version was correct before launching.
I was toying with the idea of doing this in my powershell scripts...have a function that reads a specific source server share for a definition file.  Perhaps one file with two columns: the script name and the latest version.  Then have a start function in each script to read that file and check for the latest version, and if it doesn't match, don't run...
I doubt I'm the first to run across this scenario, so I'm curious what others may use, if this sounds like a good idea, and if so, how to successfully implement it, or any other solution.
I thought briefly about a sql table too, but figured that might be overkill...
0
Comment
Question by:sirbounty
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:footech
ID: 39823207
Interesting concept.  I don't know how I would handle that as it's not a situation I've faced yet.  I wonder if an SVN repository would be the way to go.  Then you could always check out the latest version.
If your method with VBScripts worked, I don't see any reason why it wouldn't for PowerShell.  My only concern would be properly updating the version info in the script and the definition file and making sure something doesn't get out of sync there.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 0 total points
ID: 39832368
This is what I've come up with for the verify section of each script...
The version file would simply be a csv with the script name and the version.  The function should compare and take action based on the results, true/false/not found (in which case I have another script to add new script details to the version file).

$global:version=1.0
$scriptname = $Myinvocation.mycommand.name

function verifylatestversion {
	$sourcefile = '\\serverpath\sharepath\versionfile'
	$versiontable = import-csv $sourcefile
	$sourceversion = $versiontable | where-object {$_.scriptname -eq $scriptname} | select-object -expandproperty scriptversion
    if ($sourceversion -eq $null) {
        write-warning "Unable to verify script version against the master version table.  Source script version not found." 
    } else {
	    if ($sourceversion -gt $version) {
		    return $true
	    } else {
		    return $false
        }
    }
}

if ((verifylatestversion) -eq $true) {write-host "You are not running the latest version of this script." -f yellow -b red ;break}

Open in new window

0
 
LVL 39

Expert Comment

by:footech
ID: 39843303
Only mod I think I would make is to line 11 (or line 7).  As is, $sourceversion will be a string, whereas $version will be a double, so you can get into issues with the comparison.  Here's an example:
PS C:\test\ps> ("10.5" -gt 2.0)
False

Open in new window

The following would work.
	    if ([double]$sourceversion -gt $version) {

Open in new window

or you could explicitly cast the $sourceversion variable to [double] in line 7.
0
 
LVL 67

Author Closing Comment

by:sirbounty
ID: 39845140
Seems to be working for what I need...
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
A short film showing how OnPage and Connectwise integration works.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now