Turn Developer Dashboard on/off via PowerShell

I couldn’t find a simple way to turn the developer dashboard on and off via PowerShell - there’s a STSADM property for it, but who wants to use STSADM anymore? So here’s a function to change the setting quickly.

 

001002003004005006007008009010011012013014015016017018019020 function Set-DevDashboard ( [string] $setting ) {    $dashboardSetting = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings    Write-Host "Setting Developer Dashboard DisplayLevel to $setting." -ForegroundColor Gray    switch -exact ($setting) {        "On" {             $dashboardSetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On         }         "OnDemand" {            $dashboardSetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand         }         "Off" {            $dashboardSetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off         }         Default {            "Valid settings are On, OnDemand, or Off."            break         }    }    $dashboardSetting.Update()}