How's it Work?: Codeplex AutoInstaller Script

So since we’re expert at beginner PowerShell Scripts, maybe we should take a look at the AutoInstaller on CodePlex. Download it and you’ll find it’s got an AutoSPInstaller.ps1 script inside.

It takes about two seconds to see we got work to do. First, there’s this issue of the:

param
(
    [string]$InputFile = $(throw 'need parameter input file
    (e.g. "c:\SP2010\Scripted\SetInputs.xml")')
)

So I can’t quite crack this but when you look at get-help throw, you see it looks like they’re making the path a required parameter or bailing on the script.

The second issue is that of iterating through an XML file. Now I imagine we’re going to put all our configurations in an XML file and the script will read it and call the SharePoint Management Shell commands that use them to build your whole farm with one click. Groovy.

So how do we iterate through an XML file? Well, our new best friend, Dan, covers it pretty good here. He’s got the best line of the day:

With some practice you actually can drive nails with a screwdriver and then you only need to learn how to use one tool to build a house.

I gotta tell you guys and gals, I see alot of myself in that one-tool group. So maybe Dan will help. The problem is that his example is a grocery list and it’s almost supper time so, I’m heading out to:

  1. Buy Groceries
  2. Make Dinner
  3. Iterate…

Sound like an exciting evening for a robot.

-robot

Got PowerShell Figured Out Yet?

Here’s the answer from our new best friend Gary.

His post covers:

  • -loops
  • -variables
  • -arrays
  • -math
  • -string concatenation
  • -output

In this post, he shows us how adding:

> .\filename.txt

to a command writes the output to a file in the current directory and also how adding:

 | format-list 

to a command converts our output from a nice table with headers and everything to a list with space to be more verbose. For example, try these two:

get-process winlogon

and this:

get-process winlogon | format-list

This is the most I’ve learned in the shortest amount of time in a long time. Especially if you count the fact that I now know there’s only four perfect numbers less than 200,000.

-robot

Continuing with SharePoint Management Shell

First of all, to echo a point we made a few days ago, our new best friends at Acme Solutions talk about SMS here. They agree that it will be the tool of choice for the SharePoint 2010 administrator.

Then, since we’re still trying to get our feet under us in this environment, we found this from our new best friend, Gary. He confirms we we had said earlier that SMS is just MS PowerShell with SharePoint 2010 library added in and he proves it by looking at the shortcut properties when you right click on Start | Programs |SharePoint 2010 | SharePoint Management Shell.

Here we see the target is just:

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe 
-NoExit  " & ' C:\Program Files\Common Files\Microsoft Shared\
Web Server Extensions\14\CONFIG\POWERSHELL\Registration\
\sharepoint.ps1 ' "

Here we see that the shortcut is just a PowerShell Script of it’s own:

$ver = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home

We looked at the Add-PSSnapIn command previously and turns our PowerShell environment into a SharePoint Management Shell environment by adding the microsoft.sharepoint.powershell library. But this also shows us that we can set variables using the $VariableName = Value format.

Prove that to yourself by opening PowerShell and enter:

$robot = "I Love Robots"

and then do:

$robot 

So we’re checked out on setting PowerShell variables.

Finally, the SharePoint.ps1 script includes a largish #sig block of apparently random characters. I presume this has something to do with signing scripts. Recall in our create and delete script that we did last week, we included a   line that said:

Set-ExecutionPolicy RemoteSigned

Now, obviously, I plagerized this from somewhere becasue you all know as much about this or more than I do. And I apologize to my source, whoever you are, because I also try to credit you guys when we benefit from your genius. But, since it’s escaped me, I can only say that I recall reading that this command will allow local scripts to run unsigned but still require remote scripts to have a signature. I’m guessing this big block of characters has something to do with that kind of signature.

hth

-robot

Create and Delete Web App, Site, and Web using PowerShell

SharePoint 2010 retains the ambiguous naming of the various containers so that anyone new to the technology will end up getting confused. As a result, I feel compelled to explain, as best I can, everytime the subject comes up, the relationships using the appropriate terms: Web Apps, Sites and Webs. At the same time, we can hook them in our head to the SMS commands that we use to work with them.

Web Apps are an IIS entity. Consequently, while web apps can share ApplicationPools, everything in a single web app shares a single Application Pool. Also, while a single web app can support any number of site collections, it can only have one host header. This means that one site collection can own the host header url : http://<host header> while all the other will have a url: http://<host header>/SiteCollectionTopLevelSiteName.

In SMS we use new-SPWebApplication and remove-SPWebApplication to create and destroy web apps.

From the SharePoint administrators’ point of view, a “Site” is really a “Site Collection” which is a single top-level site and zero or more sub-sites. Interactively, Site Collections are created in Central Admin and are assigned to a specfic web app and have their own content database. If there’s already a Site Collection using the web app’s host header, Central Admin will make you give it a URL under that host header.

In SMS we use new-SPSite and remove-SPSite to create and delete a site collection.

Finally, a Web, aka Team Site, is a single SharePoint site. It uses a site template and can support any number of sites below it. Webs are either a top level site or a sub-site.

In SMS, we use new-SPWeb and remove-SPweb to create and delete webs.  

So, after you install SharePoint, if you can open Central Admin and if you can open the SharePoint Management Shell, you can create and delete Web Apps, Sites and Web at will. While it’s easy enough using Central Admin, I was thinking the script that does all of this might be interesting.

I came up with this:

function Pause ($Message="Press any key to continue...")
{
Write-Host -NoNewLine $Message
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}

Set-ExecutionPolicy RemoteSigned

New-SPWebApplication -Name MyHostHeader -Port 80
   -HostHeader MyHostHeader -URL http://MyHostHeader
   -AllowAnonymousAccess -ApplicationPool MyHostHeaderAppPool
   -ApplicationPoolAccount (Get-SPManagedAccount MyServer\SVC_SPAppPool03)
ECHO "Web Application Created"
ECHO ""
PAUSE

New-SPSite -Url http://MyHostHeader -OwnerAlias MyServer\Administrator
   -Name MyHostHeader -Template "STS#0"
ECHO "Site Collection Created"
ECHO ""
PAUSE

New-SPWeb -Url http://MyHostHeader/TeamSite -Template "STS#0"
ECHO "Team Sub-Site Created"
ECHO ""
PAUSE

Remove-SPWeb http://MyHostHeader/TeamSite
ECHO "Team Sub-Site Deleted"
ECHO ""
PAUSE

Remove-SPSite -Identity http://MyHostHeader
Echo "Site Collection Deleted"
ECHO ""
PAUSE

Remove-SPWebApplication -Identity http://MyHostHeader
   -DeleteIISSite -RemoveContentDatabase
Echo "Web Application Deleted"
ECHO ""
PAUSE

To see it work, copy it to Notepad and delete the line breaks I added to help with formatting here on the page.  Save it as MyScript.ps1. Open your SharePoint Management Shell and run it by using the full path and filename. If you navigate to the folder where you saved it, you have to call it with:

 .\MyScript.ps1

This will create a web app, site and web and then delete the web, the site and the web app, each time, pausing so you can browse out an see it. I got the PAUSE function from the PowerShell Team blog here.

hth

-robot

Windows PowerShell 2.0

So, we’re looking at this SharePoint Management Shell and learning a bit about it. One thing for sure, if you’re a SharePoint admin you’re going to want to run Windows PowerShell locally.

Here’s the download page from TechNet

This is what Microsoft calls its “Core Management Framework” which includes the Remote Manager and the Background Intelligent Transfer Service (BITS.) The download I chose for my XP laptop did not include the BITS component. When it’s installed, you get the command line interface and the “Integrated Scripting Environment.” They appear under Start | Programs | Accessories | Windows PowerShell.  

Also, there’s a decent intro to PowerShell scripting from our new best friend Todd on TechNet here.

-robot

Windows PowerShell and the SharePoint Management Shell

If you’re an expert at this then you’re ahead of me here. My new install of Server 2008 R2 includes a Windows PowerShell (WPS) and my SharePoint install includes a SharePoint Management Shell (SMS).

I found this on MSDN where they explain that SMS is just WPS with the SharePoint PowerShell snap-in added. Also, this is part of the move away from the Shared Service Provider to a more generic Service Application Framework that will support all of Office 14. Here, we can see that Microsoft claims this approach will improve development, integration, load balancing, authentication and back-up\restore.

There’s also a discussion of the PowerShell and SharePoint Foundation here where you’ll find links to the beginner guides for WPS.

I also found the help file for the SMS Cmdlets here. This page is labeled for the Search Server 2010 Express but the SharePoint 2010 Beta commands are included in the third of the three help files listed.

Finally, our new best friend David explains here that cmdlets can be written into a .psl file and run from the PS> prompt as well as where to find your $profile so you can add the SharePoint cmdlets into your generic PowerShell environment.

-robot

Okay, we know not to try to browse to web applications with non-standard host headers from the server because the loop back restrictions Windows places on us. Here, they explain that we can hack the registry to eliminate the problem but that’s not really necessary for our purposes now.

So let’s look at the SMS command for our new web application:

New-SPWebApplication
-Name "Contoso Internet Site"
-Port 80
-HostHeader sharepoint.contoso.com
-URL https://www.contoso.com
-ApplicationPool ContosoAppPool
-ApplicationPoolAccount (Get-SPManagedAccount MyServer\Administrator)

Now, I’ve added line breaks for readability so we’ll have to delete them to make it work. I’ve also created the managed account on Central Admin’s Security | Configure Managed Accounts.

It runs for a minute and I get a return of:

DisplayName               Url
-----------               ---
sharepoint.contoso.com    http://www.contoso.com

Now, I can’t browse to it locally, but I can from another computer. Of course, there will be an issue with DNS, but I added www.contoso.com to my hosts file and pointed it to the SharePoint server.

So I browse to the site and I get prompted to login, but then I get The webpage cannot be found. This makes sense because there’s no site collection installed there yet. When we did this interactively in CA, it gave us a popup window that told us to go create a site collection.

Let’s go back to CA and look at Application Management | Manage Web Applications and you’ll see the new web application listed. What we need to do is go back to the Application Management pages and click Create Site Collections. Here, our new web application will appear in the web app pull down; if not, pull it down and select the new web app. We give it a name, select a template, specify an owner and click OK. After it processes, we can get a link to our new site collection’s home page. Click it and it will prompt us to login and there it is.

We can back out by moving to the Application Management page and, in the Delete a Site Collection. Pull down the Site Collection pick list and click on Change Site Collection. Here, we get another pull down to select the site collection we just created. Now, we also get an option to select any additional site collection we may have created in the selected web application. When we can click OK, we go back to the delete page and we click Delete. We get a dialog box to confirm and click OK.

We go back to the Application Management page and we can click on Manage Web Applications, select our web application and click Delete. This time we get a DHTML popup where we dot the options to delete the content database and the IIS web site and click Delete and then OK on the confirmation popup.

So, next, what we want to do is add to our new web app command to allow anonymous access and then we’ll add the command to create the site collection creating our first SMS script to do both at once. Then we’ll do another script to work the delete.

 hth!

-robot

SharePoint 2010 Creating Web Applications pt. 2

SharePoint 2010 provides a number of ways to create a new web application. We looked at the instructions on TechNet here.

Yesterday, we created a new web app using the pages in Central Admin and a non-standard port number. The TechNet page tells us we can use the new SharePoint Management Shell (SMS) application that is intended to replace stsadmin.exe. It’s available on the server under Start | Programs | SharePoint 2010 Products | SharePoint Management Shell.

TechNet also tells us the SMS command to create a new web app is:

New-SPWebApplication -ApplicationPool <Name of the application pool>
-Name <Name of the new Web application>
[-Port<Port on which the Web application can be accessed>]
[-HostHeader<Valid URL assigned to the Web application that must correlate
to the alternate access mapping configuration>]
[-URL<Load-balanced URL for the Web application>]
[-ApplicationPoolAccount<User account that this application pool will run as>]

So I composed mine like this:

New-SPWebApplication
-Name "Contoso Internet Site"
-Port 80
-HostHeader http://sharepoint.contoso.com
-URL https://www.contoso.com
-ApplicationPool ContosoAppPool
-ApplicationPoolAccount (Get-SPManagedAccount MyServer\Administrator)

And, obviously, we need to look into managed accounts in a little more detail because the error is:

Get-SPManagedAccount : No matching accounts were found.

In fact, I’m not sure I know what a managed account is.

For my money, no one explains it better than our new best friend Furuknap here. Furuknap tells us that SharePoint 2010 can take over the management of the password of accounts used as application pool IDs. This is convenient because every IIS web site will refer to an app pool and every app pool refers to an ID. When these scale out, managing the passwords can be difficult, particularly when they expire. This new SharePoint 2010 feature eliminates this headache.

So we need a managed account for our SMS create web app script to work.

So we go into Central Admin and visit the Security page. Here, there’s a linkgroup for General Security. I click Configure Managed Accounts.

There’s a Register Managed Account link at the top. I click it and enter an account I made earlier for this purpose MyServer\ManagedAccount. Furuknap explains the benefits of letting SharePoint now support your password requirement but I leave them blank all the same.

Now, I return to my SMS session and change my command to reflect the new managed account. I press Enter and it runs and runs and returns some output indicating my Site name and URL. I enter the URL in my browser and press Enter. It runs for a second and prompts me for a user name and password.

I try the only accounts on the machine: The Administrator account and the managed account. Neither works.

So I tracked down some input on Technet here. They pointed me to the KB article here talking about the trackback loops when trying to hit web sites on the local server with non-standard host headers.

-robot

SharePoint 2010 Depoloyment Issues\86 SSP

With the server up and running, at least in Stand Alone mode, we’re beginning to encounter some issues.

First of all, we had trouble with our installation on a domain controller. The wizard did not offer a “Complete” option and barfed on Stand Alone. Then, on a non-domain server, it barfed on Complete. Hence we’re currently at stand alone SharePoint on a stand alone server. There’s a thread in TechNet that’s tracking a similar issue.

Next, sometimes, when we create a web application, we’re having trouble logging in. We’ll be looking at that in more detail here today.

I expect we’ll find more as we work to resolve these and encounter all the new functionality of SharePoint Server offers. No doubt, one of the first things you’ll notice is that we’ve lost our Shared Service Providers. Instead, these services are integrated more tightly into Central Administration on the Application Management page where you get a Service Applications linkgroup. In that  group there’s the Manage Service Appliations link.

I gotta admit, while this looks a little familiar, the User Profile Service, for example, there a number of new toys in here. It’s going to take some doing to nail these down but we’ll make a list and see if we can get them one at a time.

TTYS

-robot

Creating SPS 2010 Web Applications

I tried one yesterday but after it finished, it wouldn’ t let me log ono it.

So today, I’ve gone out and found this on Technet.

Now, like any good robot, there’s nothing I like more than following good instructions nor less, bad. So here goes.

Now the Technet page is good in that it sets some expecations. Our new web application will have it’s own database and when we create it, we’ll need to specify an anthenication type, Classic (Windows) or Claim-Based (Windows or Form Based.) Also, it points out that the new PowerShell environment will let you create web apps programatically so we’ll have to get a good look at that later.

So, Central Administration has an Application Management page where there’s a link to the Manage Web Applications page:

../_admin/webapplicationlist.aspx. 

Here, there’s a New link on the ribbon. This loads a Create New Web Application page:

../admin/extendvs.aspx.

Now a note here. My CA web site actually loads this page in a dialog box centered over the shaded page. When I right click on it I can see the properties and get the URL for the dialog box:

http://myserver:<myCAPortNumber>/_admin/extendvs.aspx?IsDlg=1

The ?IsDlg=1 query string is what makes it the shaded dialog; if you delete the query string, the page will load in the browser window without the shading effect.

Following TechNet’s instructions, I select Classic Mode authentication and Create New IIS Web Site.  I leave the website name unchanged. The host header value is optional. I’ve always preferred to route to web sites using the host header but for this first attempt, I’ll leave it blank.

I leave the default website path unchanged. I’m also going to leave the authentication method as NTLM. At this point I’m checking Yes for Allow Anonymous. TechNet tells us this is required if you want any content to be accessible anonymously and, later, you can restrict anonymous access. This cannot be changed later.

I am not going to use SSL and I’m going to leave the default URL and zone unchanged.

I’m going to use an existing application pool, the same on I’m using for my existing site.  I dot the option and pull down the list and select SharePoint – 80 (Network Service). The option to create a new one will also let you create a new managed account by opening up a new window. I may try that later.

It gives me default database server and name. The name has a GUID suffix. I usually change it to something more easily deciphered like the port number of web app name used above. I leave the default Windows Authentication unchanged in the database authentication section.

At this point, I don’t have a failover database server and, I presume since I’m a stand alone inststallation, I don’t get to select a search server; it simply says that search is provided by SharePoint Server Search.

Next, we have a new Service Application Selection section. This can be default or custom. If we select custom, we can selectfrom the list of available services. I’m leaving the default value unchanged.

Lastly, we have some ugliness about the Customer Experience Improvement Program. I’m going to leave it as No and click OK. The dialog box indicates that it’s Processing and shows me an orbiting ball. Then I get a dialog box that says Web Application Created with a link about forms based authentication configurations and another to Create Site Collection.

I click Create Site Collection and end up at:

../_admin/CreateSite.aspx?WebApplicationID=<GUID>

and I get the &IsDlg=1 query string as well. I give it a name and make myself the owner. I leave the rest unchanged and click OK.  

The dialog box says the top-level site is created and gives me a link. I click it.

I end up with a new site called Home and it got a great picure of some new dorks.

So what did we miss? First, there’s alternative authentication options. We could look at creating new Application Pools and then there’s the PowerShell options. We’ll look at those next.

-robot