lihanchuan125 发表于 2018-9-3 09:27:49

PowerShell 2010: Basic SharePoint Cmdlets

  Two important notes for all future PS+SP posts before i begin to give some SharePoint specific cmdlets:
  First, make sure if you've added any of my "V3/2007" Scripts to your environment to remove them! Functions "Outweigh" cmdlets so you'll be getting "strange" behavior if you load these!

  Second, i am doing examples to show you possibilities.Unless i say "always do things this way" or "never do things this way"--then I’m not demonstrating a 'best practice'.Please don't assume that I will always show the "best" way--just one option.I'll happily add any>  With that in mind, here are some starter "SP+PS" samples...
  1. Get the local farm:
  PS> Get-SPFarm
  2. Get All details of the farm (default is a limited "formatted" view):
  PS> Get-SPFarm | Select *
  3. Get all web applications in the farm:
  PS> Get-SPWebApplication
  4. Get all web applications including Central Administration (CA) web applicaiton:
  PS> Get-SPWebApplication -IncludeCentralAdministration
  5. Get all site collections in the farm (across all web applications, but NOT including CA):
  PS> Get-SPSite -Limit All
  *Note the "limit" parameter.By default we limit to 20 site collections as "listing all cmdlets" can be a 'large' operation that you should be very aware of doing...
  6. Use WhatIf to "see what will happen".No more "run and hope"!
  PS> Get-SPSite -Limit All | Remove-SPSite -whatif
  7. "Destructive" cmdlets will prompt by default (provided the Environment's "Prompt" defaults have not been lowered!)
  PS>Remove-SPSite http://contoso
  8. Prompts can be "suppressed" using "-Confirm:$False" (not recommended!):
  PS>Remove-SPSite http://contoso -Confirm:$False
  *NOTE: "Success" in PowerShell is "No" output.When an error or warning occurs it will print to screen--ErrorAction, ErrorVariable, WarningAction, and WarningVariable can be used to "script" handling these outputs.

页: [1]
查看完整版本: PowerShell 2010: Basic SharePoint Cmdlets