05-14-2012 10:03 AM
I am on that uphill struggle to adsorbe the syntax of powershell and I am having dubious success in trying to enable a -WAIT option for commandlets. With the sample below, on invoking successfully an Invetory, it is TRUE as soon as the job is accepted, not when it is complete which could be after a few minutes.
I need to check for successfull completion of a job before moving to the next nested loop, or not. I thought it would probably be best to look for a "JobSuccess" flag but testing for this in a loop appears far harder than I expected. I am also concious that in scripting an intensive loop can have considerable overheads so would LIKE to put a delay in there, say a second !
Has anyone the knowledge required to help me query BEMCLI for job success or failure ?
function prompt
{
Write-Host ("BEM " + $(get-date) +">") -nonewline -foregroundcolor White
return " "
}
$M = import-module "c:\program files\symantec\backup exec\modules\bemcli\bemcli"
If ($M -ne ""){
echo "Module Imported OK"
Prompt
If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEInventoryJob){
# I need a wait loop here to check the above job has completed but so far cant get a -wait, do until or while.. method to work !
Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok
echo "Tape Inventory Completed"
# If Successfull Next Loop JOB else ...
# end loop
}
}
Else {
echo "Module Not Imported"
}
Solved! Go to Solution.
05-14-2012 06:21 PM
Use Wait-BEJob to wait for your job to complete. Your script should look like
Get-BETapeDriveDevice -Name "TAPE" | Submit-BEInventoryJob | Wait-BEJob | Write-Host
05-14-2012 06:21 PM
Use Wait-BEJob to wait for your job to complete. Your script should look like
Get-BETapeDriveDevice -Name "TAPE" | Submit-BEInventoryJob | Wait-BEJob | Write-Host
05-15-2012 06:33 AM
I prefer to keep all scripts completely self contained rather than rely on the profile having what is needed. Also makes for greater portability on my part as I can use the base scripts anywhere.
| Wait-BEJob is exactly what I was looking for in terms of pausing until the job ended. Thank you.
Of course it has now thrown up a miriad of new questions... SORRY !
When I run:
$M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok)
Write-Host $M.name
I get $M = 'Job Success' as required
When loading the modules, 'if I force it to fail' my test logic is wrong as $M simply filled with the error output. Any idea how you would test for a successful import or would you try to filter the output for a key word ?
I noted also, if I type EXIT in the console, it will close, within a script it appears to be ignored. That does require more research !
05-15-2012 02:21 PM
You can use Get-Module to test whether a module you've imported is available:
One other note: you shouldn't have to type the full path to BEMCLI in your import-module statement. At install time, the path to the BEMCLI module is added to your environment's PSModulePath variable. You can test that like this:
c:\> $env:PSModulePath C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Symantec\Backup Exec\Modules
05-15-2012 07:43 PM
I am using Server 2003 and I installed Powershell v2.0 after I install BE 2012. Thus I need the full path of the BEMCLI module.
05-15-2012 07:46 PM
You don't really have to test whether the import-module is successful or not. If the import-module is not sucessful, all your BEMCLI commands will fail.
05-16-2012 01:49 AM
OK after everyone input, the end result is:
function prompt
{
Write-Host ("BEM " + $(get-date) +">") -nonewline -foregroundcolor White
return " "
}
#import-module "c:\program files\symantec\backup exec\modules\bemcli\bemcli"
import-module bemcli
if ((get-module bemcli) -ne $null){
Write-Host "BEM Modules Imported OK"
Prompt
Write-Host "Starting Inventory Job"
If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEInventoryJob|Wait-BEJob){
$M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok -Confirm:$false)
If ($M.name -eq "Job Success"){
Write-Host "Inventory:" $M
Write-Host "Starting Erase Job"
If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEEraseMediaJob -Confirm:$false|Wait-BEJob){
$M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok -Confirm:$false)
If ($M.name -eq "Job Success"){
Write-Host "Quick Erase:" $M
Write-Host "#run backup code here"
}
Else {
If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEEraseMediaJob -Confirm:$false -LongErase|Wait-BEJob){
$M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok -Confirm:$false)
If ($M.name -eq "Job Success"){
Write-Host "Long Erase:" $M
Write-Host "#run backup code here"
}
}
}
}
}
}
}
Else {
Write-Host "BEM Modules Not Imported"
}