Sunday, June 3, 2012

PowerShell – Understanding pipeline and extending pipeline to more than one line

When writing PowerShell script one command which goes in a long line reduces the readability of the command, this normally happens when you are taking output object of one cmdlet and passing it to another cmdlet. 

You would like to extend a long line command in multi-line to improve the readability:- 

First let me clarify what does pipeline means in PowerShell, as you know object returned by a cmdlet can be stored in a variable for later use or piped to a subsequent cmdlet as input for the subsequent cmdlet. A pipeline is a channel through which the output of a cmdlet can be passed to following cmdlet, the pipeline is represented by pipe char ‘|’

Here is an example of pipeline: - Output of Get-Service cmdlet which is SPTimerV4 service is piped to the next cmdlet Stop-Service which stops the SpTimerV4 service.

Get-Service SPTimerV4 | Stop-Service

Below are the ways how you can extend the pipeline to more than one line to improve readability.

Use Tick Mark (‘): You can use tick mark to break the line and continue the command in next line, PowerShell assumes that the subsequent line is the continuation of the current line.


Get-Service –DisplayName *SharePoint* |

Use Pipe Symbol (|) as last character of the line: When Pipe symbol is the last character of a line, it indicates that the command is not complete so Windows PowerShell continues the command with the subsequent line


Get-Service –DisplayName *SharePoint* |

Use a left curly brace ({): Curly braces are normally used to enclose the structure such as expression or a procedure. A left curly brace suggests that a structure follows.

Site Collection Administrators defined from Central Administration and from site collection top level site

As you know when creating a Site Collection from the SharePoint central administration you can specify Primary and secondary site collection administrators. And these two site collection administrators are added automatically in owners on the top level site. Central administration limits you to add only two site collection administrators, if you want to add more site collection administrators, you can add them from the site collection top level site.

Now the common question is:-

What are the differences between the site collection administrators as defined in central administration and site collection administrators as defined in site collection itself??

Here are the differences:-

Site collection administrators defined from the Central Administration receive email notification including quota and use confirmation messages. Site collection administrators defined from the site collection do not receive those email notifications.

When you change owners by using Central Administration, the list of site collection administrators will be updated automatically. However if you change site collection administrators from the site settings of the top level site, changes are not always reflected in the owners properties for example:- adding a second site collection administrator to the site does not make the user secondary owner.

The best practice is to use Central Administration to manage the primary and secondary owners as they are automatically site collection administrators and receives email notifications.

Note: Both sets of site collection administrators defined from Central Administration or from the site setting of top level site have full control permission to the site collection.

How to change SharePoint 2010 Central Administration site port

Changing central administration web site port is not a frequent job but in some scenarios when facing port related issues or IT security issues related to ports, you might decide to change the port number of your existing SharePoint central administration web site to some other port number:-

Below are the ways how you can perform this task:-
1)   Using SharePoint product configuration wizard:-

When you run the SharePoint Product Configuration Wizard from Psconfigui.exe, you can specify the port to which the Central Administration port is bound.
2)   Using Stsadm commands:-

You can use the setadminport operation of Stsadm to modify the port to which Central Administration is bound

Stsadm –o setadminport –port <PortNumber>

<PortNumber> is the available port number you can specify
3)   Using Windows PowerShell

You can use Set-SPCentralAdministration cmdlet –Port parameter to modify the Central administration web site port

Set-SPCentralAdministration –Port <PortNumber>

<PortNumber> is the available port number you can specify

Note: Port number cannot be changed from the Central Administration web site itself