Created
July 14, 2015 20:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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