Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

script versions

Posted on 2014-01-30
4
180 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 40

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 40

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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