Solved

script versions

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 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