This project has moved and is read-only. For the latest updates, please go here.

Some extensions

Mar 11, 2011 at 7:32 AM

I've been working up a script to do the everything for our new production instance and I thought I'd share some of the custom functions I've made to automate some of the setup tasks.

Outgoing Mail:

Can't actually be done from PS apparently, you have to call stsadm.

function ConfigureOutgoingFarmEmail([xml]$xmlinput)
	$SmtpServer = $xmlinput.Configuration.Farm.Email.OutgoingServer
	$fromEmail = $xmlinput.Configuration.Farm.Email.FromAddress
	$replyToEmail = $xmlinput.Configuration.Farm.Email.ReplyToAddress
	Write-Host -ForegroundColor White " - Setting Outgoing Mail..."
	stsadm -o email -outsmtpserver $smtpServer -fromaddress $fromEmail, -replytoaddress $replyToEmail -codepage 65001

Farm Admins:

More low-hanging fruit, my fellow devs get antsy if they don't automatically have access to everything.

function AddFarmAdmins([xml]$xmlinput)
	$admins = $xmlinput.Configuration.Farm.Administrators.Admin
	$CAURI = "http://"+$env:COMPUTERNAME+":"+$xmlinput.Configuration.Farm.CentralAdmin.CentralAdminPort
	$site = new-Object Microsoft.SharePoint.SPSite($CAURI)
	$web = $site.RootWeb
	$farmadministrators = $web.SiteGroups["Farm Administrators"]
	foreach($AdminUser in $admins)
		Write-Host -ForegroundColor White " - Adding $AdminUser to Farm Admins"


Firewall Ports:

I always forget to do this and keep scratching my head later on.  Adapted from:


function Open-FirewallPort($portName, $portNumber)
	Write-Host -ForegroundColor White " - Opening port $portNumber for $portName"
	$port = New-Object -ComObject HNetCfg.FWOpenPort
	$port.Port = $portNumber
	$port.Name = $portName
	$port.Enabled = $true
	$fwMgr = New-Object -ComObject HNetCfg.FwMgr
	$profile = $fwMgr.LocalPolicy.CurrentProfile


I've also been trying to get this: 

to work without much success.

I should also point out that each of these functions originate as code snippets from other folks.  I'll find references for the unattributed ones later.



Apr 7, 2011 at 3:18 AM

Sorry for the horribly late reply...

Anyhow the latest script release(s) add support for configuring Outgoing Email (via Powershell, no less), and the other functions you posted could be useful in AutoSPInstallerFunctionsCustom.ps1, I just have to find the time to plan & test etc.

I'm really interested in the UPS connection creation one though - been wondering about that possibility for a while. Stay tuned...