Enable tree view in current navigation within SharePoint

Sometime we need to enable tree view in current navigation to help navigate within document libraries.

Traditional Way:

Site Settings -> Look and Feel: Navigation Elements -> Check ‘Enable Tree View’

Programmatic way using PnP Powershell:

try {
    $web = Get-PnPWeb -Includes TreeViewEnabled
    Write-Host "Setting options to enable tree view..."
    $web.TreeViewEnabled = $true        
    $web.Update()
    Invoke-PnPQuery
    Write-Host "Completed."
}
catch {
    $ErrorMessage = $_.Exception.Message
    Write-Host "Error enabling tree view. $ErrorMessage"
}