title: How can I dispose SharePoint objects safely in PowerShell functions?
body: <p>What is the proper way of disposing objects created inside a function?
  I came across this method on a website.</p>
  
  <pre><code>function get-spweb ([String]$webUrl=$(throw 'Parameter -webUrl is missing!'))
  {
     $site = get-SPSite $weburl
     return $site.OpenWeb()
     $site.Dispose()
  }
  </code></pre>
  
  <p>Does the Dispose method ever get called in this function? </p>