Forum Discussion

Jussi Palo's avatar
Jussi Palo
Iron Contributor
Feb 15, 2017

Office PnP PowerShell: How to dispose SPWeb from Get-PnPSubWebs

Having foreach loop with Get-PnPSubWebs, how do I dispose SPWebs at the end of loop cycle?

3 Replies

  • I think this thread will help you http://stackoverflow.com/questions/1999858/how-bad-is-it-to-not-dispose-in-powershell
  • I may not understand your question correctly. Dispose is available only through Context. You can post the sample to provide you the proper feedback.
    • Jussi Palo's avatar
      Jussi Palo
      Iron Contributor

      So like this?

      foreach ($web in Get-PnPSubWebs)
      {
          #Do something with $web
          $web.Context.Dispose() # <<<<<
      }

       

Resources