IT tutorials
 
Applications Server
 

Microsoft Sharepoint 2013 : Using SharePoint Commands (part 5) - Working with Objects Below the Web Level

1/14/2015 8:38:32 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Working with Objects Below the Web Level

As mentioned earlier, SharePoint PowerShell commands generally work from the SPWeb object and above. That means you will not find commands such as Get-SPList or New-SPLibrary in the out-of-the-box commands. However, with a little digging, and liberal usage of the Get-Member cmdlet, you can use PowerShell and the object model to list a web’s lists and libraries, as well as add and then remove a SharePoint list. That provides you with the foundation to move beyond the commands supplied by SharePoint 2013.

Lists and libraries are child objects of the SPWeb object you just looked at. The SPWeb object contains a single property, Lists, which is a collection of all its lists and libraries. To retrieve all the lists and libraries of a specific web, you can use the following command, as shown in Figure 16, within the Management Shell or a host with the SharePoint commands registered:

FIGURE 16

image
(Get-SPWeb http://portal.contoso.com/team/blog).Lists

In all likelihood, a lot of text is flying across your screen now as all the properties of all the lists and libraries are displayed. Unlike the previous SharePoint objects you have worked with, the SPList list object that is returned from the preceding command does not have a defined default format; therefore, PowerShell dumps all the properties.


NOTE Ctrl+C will exit the current processing and return you to your prompt.

None of us can read that fast. Fortunately, you can control how each list is formatted and slow down some of that flying text. Run the same command, but this time send the lists and libraries out to Format-Table, another PowerShell formatting command, shown in Figure 17:

FIGURE 17

image
(Get-SPWeb http://portal.contoso.com/team/blog).lists | Sort-Object Title | 
Format-Table Title, Id, ItemCount, hasUniqueRoleAssignments,
EnabledAttachments, EnableThrottling

NOTE Many of the lower-level objects such as SPList and SPListItem do not save their changes to the content database until the Update method is called on the object.

Now that you know how to retrieve all the lists and libraries contained within a SharePoint web, the following example demonstrates how to get just one specific list. The Lists property on the SPWeb object returns a collection of lists, like many of the properties associated with SharePoint objects. You can retrieve any list by using the index, ID, or title. For example, to get the third item in the lists collection, use the following:

(Get-SPWeb http://portal.contoso.com/team/blog).lists[2] | 
Format-Table Title, Id,
ItemCount, hasUniqueRoleAssignments,
EnabledAttachments, EnableThrottling

In the preceding example, note that the value 2 is used, rather than 3, because developers like to start counting at 0. Therefore, the first item in a collection is number 0, so the third item is 2.

As mentioned previously, you can also get a list by using the ID or list title. Simply replace the number 2 with the ID or Title:

(Get-SPWeb http://portal.contoso.com/team/blog).lists["Posts"] | 
Format-Table Title, Id, ItemCount, hasUniqueRoleAssignments,
EnabledAttachments, EnableThrottling

At this point, you know how to get down to the list level and enumerate all of your lists and libraries. Creating a new list is a little tricky. First, you need to decide what type of list you will create. To keep it simple, the next example creates a Links list. The Links list template has an ID of 103, which is information you can find by looking in the SharePoint documentation. You can also get this information by running the following command:

(Get-SPWeb http://portal.contoso.com/team/blog).ListTemplates | 
Where-Object {$_.Name –eq "Links"}

To create the Links list, you need to call the Add method of the List collection you have already been working with. The Add method requires three parameters for this example: Title, Description, and ListTemplateId. Armed with all this information, add that list using the following command:

(Get-SPWeb http://portal.contoso.com/team/blog).Lists.Add("Demo Links List", 
"This is the description", 103)

Figure 18 shows the new, improved list of lists — now sporting a new Links list.

FIGURE 18

image

Finally, to close out this section you will delete your list. Yes, delete; not remove. The Delete method is a method of the SPListCollection object (the Lists property), not a command in PowerShell, which is why you can use it. The Delete method of the List collection requires the list ID, so you are going to use a variable this time to grab the list ID in one line and use it in the Delete on the next line. Following are the two lines needed to delete the list you just created (Figure 19 shows what it looks like):

FIGURE 19

image
$listId = (Get-SPWeb http://portal.contoso.com/team/blog).
lists["Demo Links List"].Id

(Get-SPWeb http://portal.contoso.com/team/blog).lists.Delete($listId)

Again, you can verify that you did indeed remove the list by using the following command to list all your lists.

(Get-SPWeb http://portal.contoso.com/team/blog).lists | Sort-Object Title | 
Format-Table Title, Id, ItemCount, hasUniqueRoleAssignments,
EnabledAttachments, EnableThrottling

A USEFUL RESOURCE
This section can’t close without at least pointing new admin developers to the key documentation that will help you with these more interesting creations: the SharePoint 2013 developer reference site, currently located at http://msdn.microsoft.com/en-us/library/jj193038.aspx. This set of web pages provides documentation on the various objects in SharePoint. PowerShell uses the SharePoint 2013 object model, so any references about it, regardless of the target language, will be helpful.
 
Others
 
- Microsoft Sharepoint 2013 : Using SharePoint Commands (part 4) - Working with Webs
- 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
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us