programming4us
 
Applications Server
 

Microsoft Sharepoint 2013 : Using SharePoint Commands (part 4) - Working with Webs

1/14/2015 8:34:24 PM

Working with Webs

Site collections contain webs, or SPWebs if you are speaking about SharePoint PowerShell commands. Like the other main objects in the SharePoint hierarchy, you can list, add, modify, and remove webs. Administrators tend to spend a lot of time working with webs because they are so numerous and this is where end users actually do their work. The SPWeb object contains many items that end users work with, such as lists and libraries. Now is probably a good time to let you know that there are no cmdlets to access objects below the SPWeb object. This means that there are no commands for lists, libraries, or files, to name a few objects, below the SPWeb object. However, that does not mean you cannot access them via PowerShell — just that you will not find cmdlets specific to these objects. You are free to access these objects via the object model.

Listing all the webs of the farm is slightly different from listing SPWebApplications or SPSites. The Get-SPWeb cmdlet requires at least one parameter. It will not list all SPWebs on the farm if you omit the parameters; there’s just too many SPWebs in a farm for that to make sense. On the plus side, you are allowed wildcards, regular expressions (with the use of the –RegEx switch parameter), and filters (with a script block), similar to Get-SPSite. The -Identity parameter will also accept a relative path if the -Site parameter is used.

Let’s look at a few ways to list SPWebs, starting with a single web. To access a single SPWeb object, use the -Identity parameter, passing in the URL, as demonstrated in Figure 13.

FIGURE 13

image

The next example returns all the SPWebs in the farm, including any Central Administration webs, sorted by URL and displaying only the Title and URL:

Get-SPWebApplication –IncludeCentralAdministration | Get-SPSite | 
Get-SPWeb |
Sort-Object Url | Format-Table Title, Url

Figure 14 displays the results of the attempt to display all the SPWebs on the farm. As discussed earlier, the cmdlet will limit the number of objects returned to 20 for performance reasons. If the number of objects is greater than 20, a warning will be displayed. To display all the SPWebs, you need to add the -Limit property set to All for both Get-SPSite and Get-SPWeb:

FIGURE 14

image
Get-SPWebApplication –IncludeCentralAdministration | Get-SPSite –Limit All | 
Get-SPWeb –Limit All | Sort-Object Url| Format-List Title, Url

Creating a new web is similar to creating new site collections. You use the New-SPWeb command and a host of parameters to define the new SPWeb. One of these parameters, -Url, is required, but the rest are optional, such as -Name and -Template. The following command creates a new SPWeb based on the Team Site template. Once the web has been created, the SPWeb object is returned and displayed on the screen:

New-SPSWeb –Url http://portal.contoso.com/teams/IT/SP2013, -Template "STS#1" 
–Name "SP 2013 Implementation"

You cannot back up or restore an individual web; that is reserved for the site collection and farm. You can work around this limitation, however. SharePoint has content deployment functionality that enables you to automate the process of copying content from one farm to another. It does this at the SPWeb level. PowerShell has two cmdlets, Export-SPWeb and Import-SPWeb, that are built on that framework. While you can’t back up and restore webs, we can export them and import them. Be careful — these exports are not full fidelity, as their focus is on content. They won’t contain non-content pieces such as alerts, workflows, or permissions.

You just created a new web, so go ahead and export it. Use the Export-SPWeb command, passing in the -Identity and -Path parameters. The -Path parameter indicates where the exported web file will be placed, and it must include both a filename and the path:

Export-SPWeb http://portal.contoso.com/ops -Path c:\ExportWeb\opsExport.cmp

You can import the web into an existing or new web. The Import-SPWeb command requires the identity of the web to import to and the path to the exported web file. The command to import your exported site to a new web is as follows:

Import-SPWeb http://portal.contoso.com/DemoImport -Path c:\ExportWeb\opsExport.cmp

Finally, you can remove your web by using the Remove-SPWeb command. This command is similar to the Remove-SPSite command. It removes one web at a time, prompting users for confirmation along the way. You can pipe an unlimited number of SPWebs into the remove command. Don’t forget the earlier discussion of the -WhatIf parameter. As shown in Figure 15, use the -WhatIf parameter to see what would happen if you ran this command:

FIGURE 15

image
Get-SPSite | Get-SPWeb –Limit All | Remove-SPWeb –WhatIf

As you can see, the pipeline is very powerful. Be careful when you pipe objects into destructive commands. The -WhatIf parameter and PowerShell’s confirm message will help to keep you out of trouble — that is, if you pay attention.

 
Others
 
- Microsoft Sharepoint 2013 : Using SharePoint Commands (part 3) - Working with Site Collections
- Microsoft Sharepoint 2013 : Using SharePoint Commands (part 2) - Web Applications
- Microsoft Sharepoint 2013 : Using SharePoint Commands (part 1) - Working with the Farm, Working with the Farm Configuration
- Microsoft LynServer 2013 : Dependent Services and SQL - Office Web Apps Server
- Microsoft LynServer 2013 : Dependent Services and SQL - Network Dependencies (part 2) - Defining Network Sites
- Microsoft LynServer 2013 : Dependent Services and SQL - Network Dependencies (part 1) - Supporting Lync Phone Edition with DHCP
- Microsoft Exchange Server 2013 : Designing a Successful Exchange Storage Solution (part 3) - Selecting the Right Storage Hardware, Storage Validation Using Jetstress
- Microsoft Exchange Server 2013 : Designing a Successful Exchange Storage Solution (part 2) - Making Sense of the Exchange Mailbox Server Role Requirements Calculator
- Microsoft Exchange Server 2013 : Designing a Successful Exchange Storage Solution (part 1) - Requirements Gathering
- Microsoft Exchange Server 2013 : Designing a Successful Exchange Storage Solution - Storage Improvements in Exchange Server 2013
 
 
REVIEW
 
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- Sigma 24mm f/1.4 DG HSM Art

- Canon EF11-24mm f/4L USM

- Creative Sound Blaster Roar 2

- Alienware 17 - Dell's Alienware laptops

- Smartwatch : Wellograph

- Xiaomi Redmi 2
 
VIDEO TUTORIAL
 
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
 
Top 10
 
- Setup Free Media Server To Stream Videos To DLNA Compatible TV, Xbox 360 & PS3 (Play Station 3)
- How To Install Android Market & Google Apps On Kindle Fire
- How To Make Ubuntu Look Like Windows 7
- How To Add A New Account in MS Outlook 2013
- Get Android & Mac OS X Style Gadgets For Windows 7 & Windows 8 With XWidget
- How To Activate Microsoft Office 2013
- How To Install Actual Facebook App On Kindle Fire
- How To Create, View And Edit Microsoft Office Files On Kindle Fire
- Download Attractive Business PowerPoint Templates For Free At SlideHunter
- How To Use And Enable Hibernate & Sleep Mode In Windows 8