Some extensions

Mar 11, 2011 at 6: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"
		$farmadministrators.AddUser($AdminUser,"","","")
	}
	
	$web.Dispose()
	$site.Dispose()
} 

 

Firewall Ports:

I always forget to do this and keep scratching my head later on.  Adapted from:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/1173b550-9f19-495f-bf70-ea12e3a73866

 

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
	$profile.GloballyOpenPorts.Add($port)
	
	$profile.dispose
	$fwMgr.dispose
	$port.dispose
}

 

I've also been trying to get this:
http://mosshater.blogspot.com/2010/10/powershell-add-active-directory.html 

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.

Cheers,

Dan

Coordinator
Apr 7, 2011 at 2: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...

Brian