Today my second guest blog article on “Hey, Scripting Guy!” was published:
Thanks for publishing, Scripting Guy!
Today my second guest blog article on “Hey, Scripting Guy!” was published:
Thanks for publishing, Scripting Guy!
Let me say this in PowerShell language 🙂
$infinite=∞
"I'm $(for($i=0;$i -lt $infinite; $i++){'very'}) happy about the possiblity to publish "+`
"a guest article on Microsofts ""Hey, Scripting Guy"" blog today. Thanks to the "+`
"Microsoft Scripting Guy, Ed Wilson, for the invitation!"
Here it is:
It’s an article about my both projects “RoboPowerCopy” and “PS2EXE”.
Here is a script I used to add some web.config modifications with PowerShell. In this case I want to add a custom authentication provider. – The following script I used for setup purpose.
# Load SharePoint PowerShell PSSnapIn and the main SharePoint .net library Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $sharePointDLL = $ENV:CommonProgramFiles+("Microsoft SharedWeb Server Extensions14ISAPIMicrosoft.SharePoint.dll") [System.Reflection.Assembly]::LoadFile($sharePointDLL) | out-null # Show Farm BuildVersion to ensure the SharePoint .net library is loaded $localFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local $localFarm.BuildVersion # store some settings and objects in variables $webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url) $farmServices = @($webapp.Farm.Services | where-object { $_.TypeName -eq "Microsoft SharePoint Foundation Web Application" } )[0] $assembly = "MyAuthenticationProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx" # Remove old web.config modifications of MyAuthenticationProvider $oldMods = @(); $webapp.WebConfigModifications | where-object { $_.Owner -eq "MyAuthenticationProvider" } | foreach-object { $oldMods = $oldMods + $_} $oldMods | foreach-object{ $webapp.WebConfigModifications.Remove($_) } # update the Web Application and apply all existing web.config modifications - this executes the "remove" actions from above $webapp.Update() $farmServices.ApplyWebConfigModifications() # New web.config modifications for MyAuthenticationProvider $myModification1 = new-object "Microsoft.SharePoint.Administration.SPWebConfigModification" $myModification1.Path = "configuration/system.web/membership/providers" $myModification1.Name = "add[@name='MyAuthenticationProvider'][@type='MyAuthenticationProvider.MyMembershipProvider, " + $assembly + "']" $myModification1.Sequence = 0 $myModification1.Owner = "MyAuthenticationProvider" $myModification1.Type = 0 #for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode" $myModification1.Value = "<add name='MyAuthenticationProvider' type='MyAuthenticationProvider.MyMembershipProvider, " + $assembly + "' />" $webapp.WebConfigModifications.Add($myModification1) $myModification2 = new-object "Microsoft.SharePoint.Administration.SPWebConfigModification" $myModification2.Path = "configuration/system.web/roleManager/providers" $myModification2.Name = "add[@name='MyAuthenticationProvider'][@type='MyAuthenticationProvider.MyRoleProvider, " + $assembly + "']" $myModification2.Sequence = 0 $myModification2.Owner = "MyAuthenticationProvider" $myModification2.Type = 0 #for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode" $myModification2.Value = "<add name='MyAuthenticationProvider' type'MyAuthenticationProvider.MyRoleProvider, " + $assembly + "' />" $webapp.WebConfigModifications.Add($myModification2) # Update the Web Application and apply all exisiting web.config modifications including the new from above $webapp.Update() $farmServices.ApplyWebConfigModifications()
Please notice my disclaimer in the right sidebar!
Hi,
I’m Ingo. Sometimes I do some SharePoint. I’d like to share some knowledge with you. I hope, you’ll respond to it. May be you have questions. I have much of it. May be you have answers for me. I’d be glad to hear it!
See you!
Ingo