Solved

script versions

Posted on 2014-01-30
4
177 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Seems to be working for what I need...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

8 Experts available now in Live!

Get 1:1 Help Now