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

Iron Contributor

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

3 Replies
I may not understand your question correctly. Dispose is available only through Context. You can post the sample to provide you the proper feedback.

So like this?

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