?
Solved

script versions

Posted on 2014-01-30
4
Medium Priority
?
185 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
[X]
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
  • 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

771 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