title: PowerShell - Loop through all SharePoint Website & continue when an error occurred
body: <pre><code>$ErrorActionPreference = "Continue"
  Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction "SilentlyContinue"
  $webApp = "Https://SharePointSite.com"
  $wa = Get-SPWebApplication -identity $webApp
  foreach ($site in $wa.Sites) {
     foreach ($web in $site.AllWebs) {
         $siteURL = $web.Url
       Write-Host $siteURL
     }
  }
  </code></pre>
  
  <p>The problem is that when it hits the statement <strong><em>foreach ($site in $wa.Sites)</em></strong>, and it cannot get the site due to access denied or any error, it would stop.  I would like to continue. I tried to TRY CATCH FINALLY, and it still stops when it encounters an error.</p>
  
  <p>I tried to put in <strong><em>-ErrorAction Continue</em></strong>, but it gives me an error message as 
  you must provide a value expression on the right-hand side of the '-' operator </p>
  
  <p>How do I get around it so it would continue to the site?</p>
  
  <p>I really appreciate your help.
  Thanks</p>