使用 SharePoint 2010 Management Shell 管理服务应用程序

上次修改时间: 2015年3月9日

适用范围: SharePoint Foundation 2010

本文内容
将 SharePoint 管理单元添加到 Windows PowerShell 中
使用 Windows PowerShell 命令管理服务应用程序
创建 Cmdlet 的最佳做法

SharePoint Foundation 2010 中的 SharePoint Management Shell 提供了一组广泛的 Windows PowerShell cmdlet,使开发、部署和管理 SharePoint 2010 更加简单、高效。

SharePoint Management Shell 取代了 Stsadm.exe 管理工具。有关 Microsoft SharePoint Foundation 2010 命令行工具和管理文件的现在和将来的开发都应使用这种新脚本技术。

备注

用于创建、枚举和管理共享服务提供程序 (SSP) 的 Stsadm 命令不适用于 Service Application Framework。

将 SharePoint 管理单元添加到 Windows PowerShell 中

若要从 Windows PowerShell 命令窗口内使用 SharePoint Foundation 2010 cmdlet,可将 SharePoint 2010 管理单元添加到 Windows PowerShell 中。

将 SharePoint 管理单元添加到 Windows PowerShell 中

  1. 打开 Windows PowerShell。

  2. 在 Windows PowerShell 窗口中,键入 get-PSSnapin – Registered。将列出 SharePoint Foundation 2010 管理单元。

  3. 在 Windows PowerShell 窗口中,键入 Add-PSSnapin Microsoft.SharePoint.Powershell。

还可以将 Windows PowerShell 管理单元永久添加到 Windows PowerShell $profile 中。

使用 Windows PowerShell 命令管理服务应用程序

下表介绍 Service Application Framework 应用程序的开发人员最常用来管理服务、服务实例和服务应用程序的 Windows PowerShell 名词和动词。

表 1. 用于服务应用程序框架的 Windows PowerShell 名词和动词

名词

Windows PowerShell 命令

SPService

  • Install-SPService

SPServiceInstance

  • Get-SPServiceInstance

  • Start-SPServiceInstance

  • Stop-SPServiceInstance

SPServiceApplication

  • Get-SPServiceApplication

  • Publish-SPServiceApplication

  • Remove-SPServiceApplication

  • Set-SPServiceApplication

  • Unpublish-SPServiceApplication

SPServiceApplicationProxy

  • Get-SPServiceApplicationProxy

  • Remove-SPServiceApplicationProxy

SPIisWebServiceApplicationPool

  • Get-SPServiceApplicationPool

  • New-SPServiceApplicationPool

  • Remove-SPServiceApplicationPool

  • Set-SPServiceApplicationPool

这些 cmdlet 的文档在 SharePoint Management Shell 中提供。

创建 Cmdlet 的最佳做法

开发服务时,可以替代特定于 SharePoint 2010 的 Windows PowerShell 动词,以添加自己的参数。但是,此类自定义参数必须与 SharePoint 2010 遵循相同标准。下面是在创建或修改 cmdlet 时建议采用的最佳做法:

  • 如果要从现有 对象中派生,请将名词中的 SP 前缀替换为服务或功能的名称。

  • 如果要从现有 SharePoint 2010 对象中派生,请对所有常用操作调用基对象的方法。

  • 尽可能重用现有的参数名称。

请参阅

概念

SharePoint Management Shell 的 Cmdlet 介绍

SharePoint Management Shell 中的 Windows PowerShell