PS SharePoSH:\> Random Stuff SharePoint + PowerShell User Group October 17, 2012 http://www.SharePoSH.com @SharePoSH PS SharePoSH:\> Agenda • Hello! • Group Logistics (GoToMeeting/ website / register / email /

Download Report

Transcript PS SharePoSH:\> Random Stuff SharePoint + PowerShell User Group October 17, 2012 http://www.SharePoSH.com @SharePoSH PS SharePoSH:\> Agenda • Hello! • Group Logistics (GoToMeeting/ website / register / email /

PS SharePoSH:\>
Random Stuff
SharePoint + PowerShell User Group
October 17, 2012
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Agenda
• Hello!
• Group Logistics (GoToMeeting/ website /
register / email / twitter)
• Upload Files
• IIS / SharePoint Admin
• Useful Scripts
• Next meeting
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Hello!
Raymond Mitchell
• SharePoint Consultant
– http://www.Rackspace.com
• Author
• Dad
• Information Worker Kid
– http://www.iwkid.com
• SharePoSHing since 2008
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
What about you?
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Uploading Files
• SPFileCollection.Add Method
• File contents as Stream or Byte[]
http://msdn.microsoft.com/enus/library/microsoft.sharepoint.spfilecollection.
add.aspx
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Uploading Files
• SPFileCollection:
$library.RootFolder.Files
• FileStream:
$f = (Get-ChildItem
c:\test.txt).OpenRead()
$f.Close()
$f.Dispose()
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPWebConfigModification
• Manage entries to web.config across multiple
servers in the farm
• Good for:
– Connection Strings / appSettings
• Useless for:
– Things that require specific order, zone-targeted
http://msdn.microsoft.com/enus/library/bb861909.aspx
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPWebConfigModification
• Path – XPath expression where to find the
section you’re modifying
– configuration/appSettings
– configuration/System.Workflow.ComponentModel.WorkflowCompiler/authori
zedTypes
• Probably not…
– configuration/system.web/membership/providers
– configuration/SharePoint/SafeControls
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPWebConfigModification
• Name – Name of the attribute or section
you’re working with
• Owner – Allows you to track ownership of
modifications
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPWebConfigModification
• Type
EnsureChildNode
EnsureAttribute
EnsureSection
Specifies that the web.config modification must ensure the
existence of a child node of the node to which the XPath
expression points. Value = 0.
Specifies that the web.config modification must ensure that
there is a value for a particular attribute. Value = 1.
Ensures a singleton node. This node is only written once, even
if multiple entities register multiple instances of
EnsureSection to ensure the existence of a section. Value = 2.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.spwebconfigmodificationtype.aspx
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPWebConfigModification
• Value – Value of the item, duh
• Sequence – order the change *should* appear
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPWebConfigModification
$mod = New-Object
Microsoft.SharePoint.Administration.SPWebConfigModification
$mod.Name = "add[@key='Sample']"
$mod.Path = "configuration/appSettings"
$mod.Sequence = 0
$mod.Type = 0
$mod.Value = "<add key='Sample' value='Test Value' />"
$mod.Owner = "SharePoSH"
$webapp = Get-SPWebApplication http://localhost
$webapp.WebConfigModifications.Add($mod)
$webapp.Update()
$webapp.WebService.ApplyWebConfigModifications()
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Get-FarmCredentials
• Microsoft.Web.Administration
– Allows access to ApplicationPools, Sites in IIS
• Microsoft.Web.Administration.ServerManager
.Sites
.ApplicationPools
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Get-FarmCredentials
function GetFarmCreds()
{
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Admi
nistration")
$mgr = New-Object Microsoft.Web.Administration.ServerManager
$pool = $mgr.ApplicationPools | ? { $_.Name -eq "SharePoint Central
Administration v4" };
$pool.ProcessModel.UserName;
$pool.ProcessModel.Password;
}
GetFarmCreds
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Alternate Access Mappings
• Site answers to more than one URL
• Configured as zones
• Useful for multiple authentication providers /
extranet scenarios
• Unless you enjoy pain, DO NOT just change
bindings in IIS – extend your site
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Alternate Access Mappings
• SPWebApplication.AlternateUrls
• New-SPWebApplicationExtension
New-SPWebApplicationExtension -Name <Name> HostHeader <HostHeader> -Port <Port> -Zone
<Zone> -URL <URL>
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Host Header Site Collections
• Create a site collection mapped to a specific
host header / address
• New-SPSite in PowerShell – NOT IN CA
•
•
$webapp = Get-SPWebApplication http://localhost
New-SPSite http://SharePoSH.local -OwnerAlias
"rmitchell\iwkid" -HostHeaderWebApplication $webapp Name "TEST" -Template "STS#0"
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
YOUR scripts!
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Next Meeting
• Wednesday, November 21st
• Topic?
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Resources
• PowerShell + SharePoint forum at
PowerShell.org:
– http://powershell.org/discuss/viewforum.php?f=1
2
• PowerShell Summit: April 22-24
http://powershell.org/summit
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Resources
• http://oricode.wordpress.com/2008/03/05/sp
webconfigmodification-configureapplicationsettings-with-a-feature/
• http://didierdanse.net/blogs/dev_en/archive/
2009/09/11/sharepoint-how-to-usespwebconfigmodification-class.aspx
http://www.SharePoSH.com
@SharePoSH