Windows PowerShell is a command-line scripting tool for administrators to fully access the applicable Application programming interface (API), and for interacting directly with SharePoint 2010 products to manipulate Web applications, site collections, sites, lists, and so on. Can unlock. In addition, administrators can write a cmdlet (pronounced "command-let") script to improve the experience of previous product versions.
Windows PowerShell 2.0 is the prerequisite software for installing SharePoint 2010 products. If necessary, you will install it when you run the Microsoft SharePoint product Preparation Tool. By default, Windows PowerShell is located in the following path: <%systemroot%>/system32/windowspowershell/v1.0/powershell.exe.
Access Windows PowerShell for SharePoint 2010 Products
After you complete the installation of the SharePoint 2010 product, the applicable Windows PowerShell cmdlet can be accessed through the SharePoint Management Shell or Windows PowerShell Console. With the command-line manager, you can manage all aspects of the SharePoint 2010 product. You can create new site collections, Web applications, user accounts, service applications, agents, and so on. commands from the command line manager output SharePoint objects based on the Microsoft. NET platform. These objects can be used as input objects for subsequent commands, or stored in local variables for later use.
Using the command line manager, you do not have to register the snap-in that contains the cmdlet. Registering the Microsoft.SharePoint.PowerShell.dll module for the SharePoint cmdlet is done automatically by the%commonprogramfiles%/microsoft shared/ Add-pssnapin in Sharepoint.ps1 files under Web Server extensions/14/config/powershell/registration Microsoft.SharePoint.PowerShell line execution. If you choose to use the Windows PowerShell console, you must manually register the snap-in.
$ver = $host | Select version
if ($ver. Version.major-gt 1) {$Host. runspace.threadoptions = "Reusethread"}
Add-pssnapin Microsoft.SharePoint.PowerShell
Set-location $home
The above command registers SharePoint administrative commands in Windows PowerShell.
SharePoint 2010 Command
With more than 500 commands in the SharePoint PowerShell snap-in, you can use it to accomplish a number of administrative tasks. We can get a list of commands through Get-command. Single Get-command gets all the underlying commands for all Windows PowerShell, such as: Features, aliases, filters, scripts, and applications. The first letter in all commands to the SP is the command that SharePoint applies. If you want to know what the SharePoint commands have, we can get them by using the following commands.
PS > Get-command-noun sp*
The following figure indicates the command information obtained by using commands.
If you use commands such as sp*, you get a lot of information. We can refine the following our commands. For example, using SPSite
PS > Get-command-noun SPSite
Get the result:
Using the SharePoint PowerShell command
Let's take a look at how the Get-spsite command is used, try to use this command in SharePoint PowerShell, and see the information returned by the command.
PS > Get-spsite
Url
---
Http://spservername
This command returns the URL of all site collections, but what if we need to know more about a single site collection?
We can use the Select-object command to display additional attribute information. For example, we can use –identity to specify the name of a site collection, and then use Select-object to get some information about this site collection
PS > Get-spsite-identity http://localhost | Select-object-property Url, Zone, Port
Of course, I can also change some of the specific properties of a site collection by command, first let's learn how to use the Set-spsite command to add a second administrator to a site collection to a website set.
PS > Get-spsite-identity http://SPServer | Set-spsite-secondaryowneralias Domain/user
If we use the Select-object command again, we can explicitly secondarycontact this attribute information. Let's take this command to see the name of the second administrator just added.
PS > Get-spsite-identity http://localhost | Select-objec Secondarycontact
You can save SPSite as an object in a variable, such as:
PS > $spSite = get-spsite-identity http://SPServer
So that we can add its second admin to this variable, we can also pass Microsoft.SharePoint.SPUser to return to a site already have the user as the site collection of the second administrator, we can use the command:
PS > $spSite = get-spsite-identity http://SPServer
PS > $spSite. secondarycontact = (get-spuser-web http://SPServer-Identity domain/user)
If we need to add a user in AD, but not a user in the site set, become the second administrator of the site collection. We need to add a user to the site collection through the New-spuser command and add it as the second administrator of the site using the command.
PS > $spUser = New-spuser-web http://SPServer-UserAlias domain/newuser
PS > $spSite. secondarycontact = $spUser
When we initialize an object in PowerShell, we must use the Dispose () method to free this memory space.
PS > $spSite. Dispose ()
Why are we using the Dispose () command? Because a similar Spweb,spsite,spsiteadministration object can use a large amount of memory resources, we use the PowerShell command to effectively reduce the memory footprint. In general, we initialize an object by using command Get-spsite, which automatically releases resources after the call is complete. But this is so that the object is not saved in a variable. When initializing an object, we can use the Dispose () method to free up memory, or we can use the start-spassignment and Stop-spassignment commands to create and release the storage area. We can use the Get-help start-spassignment or get-help stop-spassignment command in PowerShell to view its descriptive information and the methods used.