方式一:PowerShell
powershell.exe -noexit "c:\devdash.ps1"
------------------------------------------------
write-host
write-host "Loading PowerShell environment for SharePoint" -foregroundcolor Green
write-host
# unload & load the sharepoint powershell snapin
$snapin = Get-PSSnapin | where-object { $_.Name -eq
'Microsoft.SharePoint.PowerShell' }
if ($snapin -ne $null){
write-host "Unloading SharePoint PowerShell Snapin..." -foregroundcolor Blue
remove-pssnapin "Microsoft.SharePoint.PowerShell"
write-host "SharePoint PowerShell Snapin unloaded." -foregroundcolor Green
}
$snapin = Get-PSSnapin | where-object { $_.Name -eq
'Microsoft.SharePoint.PowerShell' }
if ($snapin -eq $null){
write-host "Loading SharePoint PowerShell Snapin..." -foregroundcolor Blue
add-pssnapin "Microsoft.SharePoint.PowerShell"
write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
}
write-host "Enabling the developer dashboard..." -foregroundcolor Blue
$contentService =
[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboardSetting = $contentService.DeveloperDashboardSettings
$dashboardSetting.DisplayLevel =
[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$dashboardSetting.Update()
write-host "Developer dashboard enabled." -foregroundcolor Green
方式二:STSADM
stsadm -o setproperty -pn developer -dashboard -pv ondemand
方式三:Code
if you want to write code, here’s a little code snippet that will turn on the developer
dashboard. Note that this code requires that you run it in a web part; you can use the new visual
web part template in VS to create it. You will need a using reference to Microsoft.SharePoint
.Administration in your code, and the web part must run in your Central Administration site,
because the developer dashboard is a farmwide setting. If you attempt to run the code in a normal
SharePoint site, then you will get a security exception, which is the correct default behavior.
SPWebService cs = SPWebService.ContentService;
cs.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.On;
cs.DeveloperDashboardSettings.Update();