SharePoint PowerShell Learn two use PowerShell to manage Web sites

Source: Internet
Author: User
Tags foreach backup

This chapter will explain how to use PowerShell to manage SharePoint sites, and in the previous chapter we introduced more than 500 command statements in SharePoint 2010, some of which are used to manage sites and site collections. The site in a site collection will contain a number of site pages, lists, and document libraries. Let's take a look at the first command to manage the Web site get-spweb This command to get one or more Web site content. For example:

PS > Get-spweb-identity http://SPServer

In the example above, create a URL is Http://localhost/newsite's website, the title is NewSite, site description "Powershellcreatesite", site template used in "sts#0" is a team site template

Use PowerShell to back up and restore a SharePoint site

Let me take a closer look at the backup and restore site, and when we use these commands, we can export the site using the Export-spweb command.

PS > Export-spweb-identity http://SPServer/NewSite

>>-path C:/backup/spwebbackup.bak

This example exports a backup file for a Web site, and it can also output specific content within the site, such as lists, document libraries, or list items. You can use itemurl this parameter to export a list and a list of items from a Web site. The following example describes a command that exports a list of calendars.

PS > Export-spweb-identity http://SPServer/NewSite '

>>-itemurl "Lists/calendar"-path C:/backup/spwebcalendar.bak

The Export-spweb command also enables you to use the Includeusersecurity parameter to export the user's permission information in this list. By default Export-spweb will export the last version of each list item, but you can export all version information through the includeversions parameter.

After you export a backup file for a Web site, you can use the Import-spweb command to restore a Web site. When you restore the site, you need to specify a site collection, and this site collection must have the corresponding template for this site, otherwise there will be error messages.

PS > Import-spweb-identity http://SPServer/NewSite-Path c:/backup/spwebcalendar.bak

We can also use the Updateversions parameter when using the Import-spweb command, which allows updates to existing Web site projects, including Append,overwrite and ignore

Use PowerShell to delete a SharePoint site

At the end of this chapter and then take a look at how to delete a SharePoint site. We can use the Remove-spweb command to delete a specified SharePoint site, and if the site is the primary site in the site collection, the entire site set will also be deleted.

PS > remove-spweb-identity http://SPServer/NewSite-Confirm: $false

In this case, the confirm means "whether or not you want to have a delete message" We mark it here as false.

You can use the Set-spweb command to set many of the site's property information, and in many cases you need to change a lot of attributes at once, which allows you to initialize a variable to store the Set-spweb. Again, set the properties of the site through this variable.

PS > $spWeb = get-spweb-identity http://SPServer

PS > $spWeb. Title = "PowerShell"

PS > $spWeb. treeviewenabled = "True"

PS > $spWeb. Update ()

PS > $spWeb. Dispose ()

In PowerShell we can use simple statements to modify some of the property information common to all sites in the entire site collection, and we can use the Foreach-object method to iterate through all the sites, such as we want to enable the tree view of all sites:

PS > Get-spsite-identity http://SPServer | Get-spweb | Foreach-object {

>> $_. treeviewenabled = "True"

>> $_. Update ()

>>}

Create a Web site using PowerShell

Creating a website in PowerShell will be very simple, we will use the New-spweb command to complete the site creation

PS > New-spweb-url http://SPServer/NewWeb-Template "sts#0"-name "New Site"

>>-description "Powershellcreatesite"

Use PowerShell to modify SharePoint 2010 site Information

If you want to modify the specific properties of the site, we need to use the Set-spweb command, here is how to use this command to modify the site description information.

PS > Get-spweb-identity http://SPServer | Set-spweb-description "PowerShell is cool"

The Get-spweb command only displays the default URL properties for the site, and we can use Format-list to display all the information about the site.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.