Skip to content

Instantly share code, notes, and snippets.

@chuckmoore55
Created July 14, 2015 20:20
Show Gist options
  • Save chuckmoore55/def069fff5cf4aaf03c6 to your computer and use it in GitHub Desktop.
Save chuckmoore55/def069fff5cf4aaf03c6 to your computer and use it in GitHub Desktop.
Example of how to code generalized JAMS (file-is-there-or-not) PreCheck Job
# simple test-for-file(s)
param( [string] $tgtdir = '.' ,
[string] $tgtfile = '*.*' ,
[string] $notfoundExit = "CancelJobError" )
$_tgtdir = $tgtdir.trimend( '\' )
$_tgt = ( $_tgtdir + '\' + $tgtfile )
write-host ( "... looking for file '" + $_tgt + "'" )
$_fileCount = ( dir $_tgt -file ).count # old, but infallible, way to see if something's there
if ( $_fileCount -eq 0 ) # nothing found, figure out how to leave
{ $_errMsg = ( ' ... file(s) NOT found in -> ' + $_tgt )
$_notFoundExitUpper = $notfoundExit.toupper()
write-host $_errMsg
write-host ( " ... job ending with JAMS status '" + $_notfoundExitUpper + "'" )
switch ( $_notfoundExitUupper )
{ "CANCELJOBSUCCESS"
{ $host.setshouldexit(<<JAMS.Message.CancelJobSuccess>>) }
"CANCELJOBINFO"
{ $host.setshouldexit(<<JAMS.Message.CancelJobInfo>>) }
"CANCELJOBWARNING"
{ $host.setshouldexit(<<JAMS.Message.CancelJobWarning>>) }
"CANCELJOBERROR"
{ $host.setshouldexit(<<JAMS.Message.CancelJobError>>) }
default { }
}
}
else { write-host ( ' ... ' + $_fileCount.tostring() + ' file(s) found in ' + $_tgt )
dir $_tgt
exit $host.setshouldexit( 0 )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment