Logo
programming4us
programming4us
programming4us
programming4us
Windows XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
 
Windows Server

Managing SharePoint 2010 with Windows PowerShell : Managing SharePoint 2010 Web Applications

12/4/2012 6:22:12 PM
Four Windows PowerShell cmdlets are available for working with web applications in SharePoint 2010. You can retrieve a list of all the web application cmdlets using the Get-Command cmdlet with the noun SPWebApplication:
PS > Get-Command -Noun SPWebApplication

CommandType Name                    Definition
----------- ----                    ----------
Cmdlet      Get-SPWebApplication    Get-SPWebApplication [[-Identity] <
Cmdlet      New-SPWebApplication    New-SPWebApplication -Name <String>
Cmdlet      Remove-SPWebApplication Remove-SPWebApplication [-Identity]
Cmdlet      Set-SPWebApplication    Set-SPWebApplication [-Identity] <S

We’ll look at each of these cmdlets, starting with Get-SPWebApplication.

Getting Web Applications in SharePoint 2010

The Get-SPWebApplication cmdlet returns the web applications in SharePoint 2010. You can use the Identity parameter to return a specific web application. If you don’t specify a web application, all web applications are returned:

PS > Get-SPWebApplication

DisplayName                    Url
-----------                    ---
SharePoint - 80                http://spserver01/

By default, Central Administration is excluded from the set of returned web applications. Using the IncludeCentralAdministration switch parameter forces the Central Administration web application to be included:

PS > Get-SPWebApplication -IncludeCentralAdministration

DisplayName                    Url
-----------                    ---
SharePoint - 80                http://spserver01/
SharePoint Central Administ... http://spserver01:23815/

Modifying Web Applications in SharePoint 2010

To configure web applications in SharePoint 2010, use the Set-SPWebApplication cmdlet. This cmdlet supports a variety of parameters corresponding to different configuration settings of web applications, such as e-mail addresses, SMTP server, and time zone.

First, let’s look at how to configure the From and Reply-to e-mail addresses. When configuring the e-mail addresses used by the web application, you must specify an SMTP server to use.

PS > Get-SPWebApplication -Identity http://SPServer01 |
>> Set-SPWebApplication -OutgoingEmailAddress from@nima.com `
>> -ReplyToEmailAddress reply@nima.com -SMTPServer ExcServer01

In this example, we use Get-SPWebApplication to retrieve a specific web application, and then pipe the object to the Set-SPWebApplication cmdlet, where we use the SMTPServer parameter to specify which SMTP server to use. We also specify the From and Reply-to e-mail addresses that should be used by the web application. Figure 1 shows what the configuration looks like in Central Administration.

Figure 1. Setting the From e-mail address, Reply-to e-mail address, and SMTP mail server through PowerShell


It is also possible to allow anonymous access with the Set-WebApplication cmdlet. Allowing anonymous access at the web application level enables individual site collection administrators to turn on anonymous access.

PS > Get-SPWebApplication -Identity http://SPServer01 |
>> Set-SPWebApplication -AllowAnonymousAccess -Zone Default

To disable anonymous access, use the same switch parameter followed by :$False:

PS > Get-SPWebApplication -Identity http://SPServer01 |
>> Set-SPWebApplication -AllowAnonymousAccess:$False -Zone Default

Caution

If anonymous access is turned off when using Forms-based authentication, Formsaware client applications may fail to authenticate correctly.


Use the Set-SPWebApplication cmdlet’s DefaultTimeZone parameter to set the time zone that should be used for new site collections:

PS > Get-SPWebApplication -Identity http://SPServer01 |
>> Set-SPWebApplication -DefaultTimeZone 4

In this example, we use the DefaultTimeZone parameter to set the time zone used by new site collections to 4, which corresponds to Western Europe Standard Time. You can list the other values for time zones using the SPRegionalSettings class as demonstrated below.

PS > [Microsoft.SharePoint.SPregionalSettings]::Globaltimezones

Creating a New Web Application in SharePoint 2010

You can create new web applications in SharePoint 2010 with the NewSPWebApplication cmdlet. This cmdlet has several parameters for configuring the new web application, including the following:

  • The Name parameter specifies the name of the new web application.

  • The Port parameter sets the port from which the web application can be accessed.

  • The ApplicationPool parameter specifies the application pool to use. If the application pool does not exist, a new application pool will be created.

  • When creating new application pools with the New-SPWebApplication cmdlet, an application pool account must be specified. You can specify the account through the ApplicationPoolAccount parameter.

Here is a basic example showing how to create a web application through Windows PowerShell:

PS > New-SPWebApplication -Name "My WebApplication" -Port 5077 `
>> -ApplicationPool "MyAppPool" `
>> -ApplicationPoolAccount (Get-SPManagedAccount powershell\managedaccount)

DisplayName                    Url
-----------                    ---
My WebApplication              http://spserver01:5077/

In this example, we use the Get-SPManagedAccount cmdlet to retrieve an account that is registered in the configuration database.

When the command is run, a content database is also created. Since we didn’t specify a name for the content database in this example, a name will be autogenerated in the format WSS_Content_<GUID>. Alternatively, you can specify a custom name through the DatabaseName parameter.

Removing a Web Application in SharePoint 2010

The Remove-SPWebApplication cmdlet removes an existing web application. You can use the Zone parameter to remove a specific zone. If the zone is not specified, all zones are removed. The cmdlet also supports switch parameters that allow you to delete the IIS web site associated with the target zone (or all zones) and the content database associated with the web application. Here’s an example:

PS > Remove-SPWebApplication -Identity http://SPServer01:5077 '
>> -DeleteIISSite -RemoveContentDatabases

Confirm
Are you sure you want to perform this action?
Performing operation "Remove-SPWebApplication" on Target "My WebApplication".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"): Y


					  

In this example, we remove the web application that we previously created. We also add the DeleteIISSite and RemoveContentDatabase switch parameters to remove the IIS web site and content database associated with the web application. As with the other removal cmdlets, Windows PowerShell prompts for a confirmation before the command is executed.

Other -----------------
- Managing SharePoint 2010 with Windows PowerShell : Managing Permissions in SharePoint 2010, Managing Content Databases in SharePoint 2010
- BizTalk 2010 : ASDK SQL adapter examples (part 4) - Composite Operations
- BizTalk 2010 : ASDK SQL adapter examples (part 3) - Query notification and multiple result sets
- BizTalk 2010 : ASDK SQL adapter examples (part 2) - Select, Table Valued Function, and Execute Reader
- BizTalk 2010 : ASDK SQL adapter examples (part 1) - TypedPolling and debatching
- Microsoft Dynamics AX 2009 : Integration with Microsoft Office - Sending email using Outlook
- Microsoft Dynamics AX 2009 : Integration with Microsoft Office - Exporting data to Microsoft Project
- Microsoft Content Management Server : The ASP.NET Stager Application (part 3) - Staging Attachments
- Microsoft Content Management Server : The ASP.NET Stager Application (part 2) - Staging Channels and Postings
- Microsoft Content Management Server : The ASP.NET Stager Application (part 1) - The DotNetSiteStager Project, Recording Messages to a Log File
 
 
Video tutorials
- How To Install Windows 8 On VMware Workstation 9

- How To Install Windows 8

- How To Install Windows Server 2012

- How To Disable Windows 8 Metro UI

- How To Change Account Picture In Windows 8

- How To Unlock Administrator Account in Windows 8

- How To Restart, Log Off And Shutdown Windows 8

- How To Login To Skype Using A Microsoft Account

- How To Enable Aero Glass Effect In Windows 8

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen
programming4us programming4us
Popular tags
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 windows Phone 7 windows Phone 8
programming4us programming4us
 
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
programming4us programming4us
 
programming4us
Girls
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone