遇到损坏的数据库后,Powershell 中的 $db.CheckTables('None') 无法继续

$db.CheckTables('None') in Powershell doesn't continue on after encountering corrupt database

可能是一个菜鸟问题,但就到此为止。所以我正在用 powershell 制作这个备份测试脚本,我在控制台中显示 DBCC 的结果,当 $db.CheckTables('None') 循环遍历数据库集合并遇到损坏的数据库时,它不会' 继续检查其余的数据库。这是我的代码

foreach($db in $dbs) {

    if ($db.Name.EndsWith("_test")) {
      Write - Host "Checking database:"
      $db.Name - BackgroundColor "Yellow" - ForegroundColor "Black"
      $dbname = $db.Name# database check
      $db.CheckTables('None')

要么这样压制它:

 $db.CheckTables('None') -ErrorAction SilentlyContinue

或者用try/catch包裹起来:

try {
  $db.CheckTables('None')
} catch {}