Remove a Authentication provider from a Web Application


Remove/Delete a Authentication provider from a Web Application…this can feel a bit tricky…not very intuative at all…

If you find yourself having more than one Authentication provider on your Web application, then you have(remember doing it or not) extended the Web Application and added a different Authentication provider for this particular extension. To remove it, remove the extension…

But…I cant even see my extended Web Application, you think…no, you cant, unless you do the following:

– In ‘Central Administration’ – ‘Manage Web Applications’, select your Web Application(default ‘SharePoint – 80’)
– Click on the Delete dropdown Arrow in the ribbon.

– Click ‘Remove SharePoint from IIS Web Site.’
– In the ‘Remove SharePoint from IIS Web Site.’ dialog select the extended Web Application in the drop down(example: SharePoint – 443)
– Delete IIS Web Site Yes/No, usually you would want to delete it as well, so click yes.
– Click Ok.
– Do an iisreset /noforce on all SharePoint Web Servers when done.

Done!

_________________________________________________________

Enjoy!

Regards

Twitter | Technet Profile | LinkedIn

Advertisement

Truesec SharePoint Security Health Check – Delivered in Sweden


Hi all.

Truesec SharePoint Security Health Check

This post is for the Swedish Community only…apologize the rest of you. (Short description in English below)

För de svenska läsarna, mitt härliga bolag Truesec har idag lanserat en tjänst som jag är riktigt stolt över. Vi kommer under hösten att hos kunder börja genomföra en Säkerhets hälsocheck speciellt framtagen för SharePoint miljöer. Läs gärna litet mer om tjänsten på länken nedan.

Truesec SharePoint Security Health Check

Tjänsten innebär en djupgående analys med fokus på säkerhet, vi kommer även att titta på lite best practises och performance parametrar med huvudfokus är att lyfta fram existerande brister och risker. Hör gärna av er via sidan om ni skulle vara intresserade.

Tjänsten är idag anpassad för SharePoint Server 2010 eller SharePoint Foundation 2010. Efter att SharePoint 2013 släppts på marknaden kommer vi även att stödja den.

(English: My outstanding Company, Truesec, announced today that we as of today are offering a brand new service: SharePoint Security Health Check. The service is described in the link above but unfortunately only in Swedish. In short, we will do a deep analyzes of the entire farm with all of its components and the result will be a report of any risks or vulnerabilities.
If you are a non-Swedish speaking customer and you are interested, add a comment to this page with contact information and I will get back to you with details in English, or just fill out the form on the Swedish link above)

_________________________________________________________

Enjoy!

Regards

Twitter | Technet Profile | LinkedIn

Change your PassPhrase using PowerShell


Changing the Farm’s PassPhrase, is it difficult and something that canb possible screw Everything up? Or is it an easy and pretty trival task?

I’d say the latter, changing it is easy, what is important and hard, is to make sure that dokumentation and possibly secure stores and such are updated to reflect the change. Remember, as long as you have at least one SharePoint server still connected/joined to the farm, you can Always reset the PassPhrase again. It’s when you have a single Config Database without a single server that you really really want to have the PassPhrase documented and in order.

So, how to do it practically? There is really only one way, and that is using PowerShell:

Open a PowerShell Prompt as Administrator.
Load the SharePoint Module:

Add-PSSnapin Microsoft.SharePoint.PowerShell

Enter this at the PowerShell prompt:

$passphrase = ConvertTo-SecureString -asPlainText -Force

Input the new passphrase and hit Enter


Enter this at the PowerShell prompt:

Set-SPPassPhrase -PassPhrase $passphrase -Confirm

You will be asked to confirm the passphrase by re-entering it in cleartext
Re-enter the passphrase and hit Enter
You will be asked if you are sure that you want to perform this action, type Y (for Yes) and hit Enter


Your farm passphrase has now been reset!

Next time, use the new PassPhrase when joining the farm.

!! And remember to update any documentation !!

Why I had to do this now? Well, this is, I’m currently helping a customer setting up Resporting Services for SharePoint, that requires an extra server joined to the farm with SSRS and SP installed on them. I installed the server and added all the SP’s and LP’s and CU’s and soon, until we were good to go to join it into the farm. Now, I got prompted for the PassPhrase…hmm. This farm was setup some time ago by a different firm and they are not around anymore…
My customer sent me the documentation on the farm setup but no luck. The PassPhrase was forgotten and gone…
So, instead of panicking and screaming for a complete reinstall, I started to look for the way to retrieve it or reset it. Turns out, you can reset it but never retrieve it. You must have one server still in the farm to be able to reset it, this server is wehere you run the Powershell commands from.

So, now my PassPhrase is reset, I quickly added it to textfile on the server and also emailed it to my customer. Later, I will also add it to the Farm documentation for future reference.

_________________________________________________________

Enjoy!

Regards

Twitter | Technet Profile | LinkedIn

Login for ‘Sharepoint_Config’, Login failed for user ‘Domain\ComputerName$’ – SCOM agent


This is about a recurring error in the event log, that does not really affect SharePoint but stirs up a lot of fuss…

(Update added 2012-12-11 – permissions needed for the agent account, see note below)

Perhaps you have encountered this error in your event logs:

database login for ‘Sharepoint_Config’ on instance ‘SQLServer\SharePointInstance’ failed. Additional error information from SQL Server is included below.
Login failed for user ‘Domain\ComputerName$’.

I have seen this a couple of times and in both cases it was due to the MOM/SCOM Agent that has a SharePoint management pack installed, the agents Windows Service runs as ‘Local System’ and thus causes this. The agent tries to access some information from the Configuration database and when accessing the database as the SharePoint Server’s ‘Local System’ account, it gets access denied, this is as it should be, the local system account must never get access outside of the server and especially to the config database.

The workaround in the cases I have seen this so far, is to either kill the SCOM agent service, or set it to run as a dedicated service account. The later is the one that sound better to me, so I will try and add info on how exactly this is done in an update to this post later.
What probably should be done when installing the Management pack, and this my personal guess so far, is that the service account for the agent, should be given the Add-SPShellAdmin permission on the Config database. This is completely unconfirmed, but if any of you would confirm that this is required, please post me a note.

On a personal note, this error caused by the monitoring agent, has been the cause of a lot of comotion and has in the end had me spend hours of unnessesary hours on finding it and mitigating its effects and also calming down the operations people that think my farms have broken…

(Updated 2012-12-11)
Note:
The required permissions for the configured run as account on an individual SharePoint farm are:
•Local admin on all SharePoint 2010 Front End and Application Servers
•Local admin on all SQL machines that host SharePoint 2010 databases
•Full Farm Administrator rights within SharePoint 2010
•DBO for all SharePoint databases
(From: http://support.microsoft.com/kb/2690744)

Enjoy!

Regards

 

A guide to Branding and SharePoint Foundation part 1


A guide to Branding and SharePoint Foundation
Part 1

Part 1 | Part 2 |

SharePoint branding is something that most everyone wants to do, the default design is pretty good and stylish but it get dull and it does not fit in with any organizations brand book or design policy. A lot of posts have been written on the subject of SharePoint branding, many books have been published and most of what can be covered has been covered. What I found though during my work with the SharePoint Branding Project, is that there is a lack of information about branding and Foundation. Lots of organizations run Foundation, the reasons for doing so are many but the facts remains, SharePoint Foundation 2010 has a very large installed base. So, can’t we just buy the book on SharePoint branding and implement it in our Foundation farm? The answer to that question is most of the time no, or rather, not very likely. SharePoint Server has one vital component that Foundation lacks, it has a publishing infrastructure feature. In most cases the publishing components are used for some vital parts of a branding package, the most common one that you will see in almost every post is the

<% $SPUrl:~sitecollection/pathtosomething/%>

The SPUrl token is very handy when storing files in a centralized location in SharePoint, like for example the ‘sites/mycompany/style library/’. Lets use the FavIcon as an example in the first part.

<link rel=’shortcut icon’ href='<% $SPUrl:~sitecollection/Style Library/My Branding/Images/favicon.ico %>’/>

This tag would in Server farm pick the FavIcon image out from the site collection root. In Foundation you would see an error similar to this:

‘The expression prefix ‘SPUrl’ was not recognized. Please correct the prefix or register the prefix in the <expressionBuilders> section of configuration.’

Accessing CSS or Image files in the Style Library is easy using the $SPUrl expression builder to get the relative Site Collection Root URL(/sites/mycompany) or even the current Web Root URL. In Foundation the SPUrl token can’t be used so we need something else. One solution is pretty easy, just enter the relative path:

<link rel=’shortcut icon’ href=’sites/mycompany/style library/my branding/Images/favicon.ico’/>

For the Site Collection Root the path would resolve to:

http://webapplication/sites/mycompany/Style Library/My Branding/Images/favicon.ico

Perfectly allright, the favicon would be loaded. This is a great solution, with one huge flaw. If you have the branding implemented in all of your subsites then the path will be correct only in the root. Since the path is relative, it would in an example subsite look like this in the master:

<link rel=’shortcut icon’ href=’sites/MyCompany/Style Library/My Branding/Images/favicon.ico %>’/>

For my SubDivision subsite the path would resolve to:

http://webapplication/sites/mycompany/subdivision/Style Library/My Branding/Images/favicon.ico

Not ok! The load would fail since the favicon.ico is not located there. So, the permanent relative is only good for a site collection root with no subsites. You could obviously add the file to every subsite so that the path would work, but that is not really an option in most cases. So, how do we do it then…? In my own SharePoint branding project I use this workaround to replace the <link rel=’shortcut icon’ token:

<asp:literal runat=”server” Text=”&lt;link rel=’shortcut icon’ href='”/>
<SharePoint:ProjectProperty Property=”SiteUrl” runat=”server” />
<asp:literal runat=”server” Text=”/style library/my branding/images/favicon.ico’/&gt;”/>

It is a workaround, but it works. This will in reality build a relative path to the Site Collection Root even in the subsites and it will build up the <link> token by using 2 literal asp controls and the SharePoint:ProjectProperty control that is available in Foundation. The result in runtime will be the same as for a URL built on the $SPUrl expression builder.

<link rel=’shortcut icon’ href=’sites/mycompany/style library/my branding/Images/favicon.ico’/>

Add this to your Masterpage and you will have a functional FavIcon that uses a relative path.

Stay tuned!

Best regards

SharePoint Branding Project


SharePoint Branding Project

Download: http://visualstudiogallery.msdn.microsoft.com/7237a2e1-a7b5-4b12-bc56-c62c805c01e7

– Please review the project if you download and use it, use the above link! –

This template is used to create a new SharePoint branding solution wsp package, the package includes custom masterpage, stylesheet, logo and favicon. The wsp includes an activation and deactivation feature as well as a childweb eventreciever to apply branding on all subsites when created.

The SharePoint Branding Project is created by
Thomas Balkeståhl
Technical Specialist SharePoint
Enfo Zipper

BLKSTHL – Blog

Version 1.15 (NEW! Now also with minimal master and search styles. Added in 1.15 full support for SharePoint Foundation added)
Revision 1.0

Facts:
This project is built for SharePoint Server 2010, SharePoint Foundation 2010 and Visual Studio 2010. It is a Site Collection Feature and activation will replace the master and the site logo, it will also add a favicon and a custom css.

Version:

1.1. Included is a minimal masterpage and basic Search classes. The minimal masterpage are used in a search center instead of the normal master. The MyBrandingMinimal.master will be deployed to the masterpage library and will be available to select in the site settings/Masterpage settings for a search site. Added to the MyStyles.css are also classes to support basic Search and Search Results styles. The included styling can easily be edited to suit your own needs. Deploy the solution as normal and then manually change the masterpage for the search site to the mybrandingminimal.master.

1.15 Now included support for Foundation. Because of the limitation in SharePoint Foundation that makes $SPUrl unavailable when getting a relative URL to the current sitecollection, code for foundation that replaces $SPUrl has been added. Instructions on how to configure this in included in the project inline and in the readme file. The SharePoint component affected are the custom CSS, the Favicon and the site logo. These can now be placed in the site collection root and still be accessable in the subsites that uses the same masterpage.

Usage:
After installing the vsix template to your Visual Studio 2010, Start a new project, select a new SharePoint 2010 Branding project, give it a name and create the project. Then enter a URL to your SharePoint 2010 sitecollection in the Project Properties, under Site URL.

(remember, the template will only be installed to the user that executed the vsix file.)

Farm vs. Sandboxed
The project is by default configured as a sandboxed code, so If your farm is running in Sandboxed mode or if your site is an Office365 then you can deploy it as is. If your farm does not have the sandboxed code service running, then you need to configure this project to be deployed as a farm solution. This setting is available in the project properties. To deploy as a farm solution – Set the value ‘Sandboxed solution’ to False. (requires the user to have SharePoint administrator privileges to deploy the solution)

SharePoint Foundation 2010
The project support usage on SharePoint Foundation with slight modifications, the $SPUrl has to be replaced with a relative or absolute link, or a different approach that uses a similar method to the $SPUrl that is available on Foundation.
The reason for this is that the $SPUrl in a publishing function and as such it is only available on SharePoint Server 2010.
See Version 1.15 above.

Deployment
To deploy the project to the designated site, Build menu – Deploy Solution (requires Visual Studio to run with elevated privileges, ‘Run as Administrator’).
To deploy in production, build the project in Build menu – Deploy Package. The wsp package will be located under <Your Projects folder>\ProjectName\ProjectName\Bin\Debug\ProjectName.wsp
Deploy the wsp to your farm using PowerShell(Requires Add-PSSnapin Microsoft.SharePoint.Powershell):

Add-SPSolution -LiteralPath <SolutionPath>
(Add-SPSolution -LiteralPath c:\solutions\ ProjectName.wsp)

Install-SPSolution -Identity <SolutionName> -WebApplication <URLname>
(Install-SPSolution -Identity ProjectName.wsp -WebApplication http://www.company.com)

Redeploy:

Update-SPSolution -Identity ProjectName.wsp -LiteralPath c:\solutions\ProjectName.wsp -GACDeployment

A deployed solution will show as a Site Collection feature, this will have the same name as you r Visual Studio Project, activating it enabled all of the branding, deactivating it will replace the master with v4.master and remove the logo.

Customizing:
Modify the existing components to get the design and branding that is required. The components that can easily be edited and/or replaced are:

Logo
favicon
StyleSheet
Master Page

Logo : The logo is in this version placed as a URL property in the ‘Title, Description, and Icon’ section of Site settings. This can be changed to have the logo in the masterpage, look up the SharePoint:SIteLogoImage> section in the master and follow the instructions inline. Remember to comment out the logo adding in the featureactivated section in the main.EventReceiver.cs

<SharePoint:SPLinkButton runat=”server” NavigateUrl=”/” id=”onetidProjectPropertyTitleGraphic”>
<SharePoint:SiteLogoImage name=”onetidHeadbnnr0″ id=”onetidHeadbnnr2″ style=”padding-left: 15px;padding-top: 10px;padding-bottom: 10px” LogoImageUrl=”<% $SPUrl:~sitecollection/Style Library/My Branding/Images/Logo.png %>” runat=”server”/></SharePoint:SPLinkButton>
(sample code for server, available in the readme file)
This will make the masterpage always show the logo, remember that the logo setting in site settings may override the masterpage SiteLogoImage. USing this method will also allow you to set a fixed link on the logo, so that it always points to the site collection root for instance.
(Code modification to the master needed to work on SharePoint Foundation)

Favicon : Replace the favicon.ico file in the ‘Style Library/My Branding/Images/ catalog. The ico file should be a real ico image and have a size of 32×32.
(Code modification to the master needed to work on SharePoint Foundation)

StyleSheet : Edit the styles in the included stylesheet MyStyles.css located in the ‘Style Library/My Branding/’ catalog. Or replace the file with your own using the same name. You can also add another CSS and refer to it in the master(se comments in master on how).
Add to this file the classes you need to style. (You can use F12 developer toolbar to find out which class to style.)
(Code modification to the master needed to work on SharePoint Foundation)

MasterPage : Edit the included master to suit your needs. The included master is a very lightly modified copy of the V4.master. Do not replace it or change its name, if you do, then you have to know what references in other places have to be changed as well.

The SharePoint Branding Project by BLKSTHL is licensed under a Attribution-NonCommercial-ShareAlike
3.0 Unported (CC BY-NC-SA 3.0) License

Description: Description: Creative Commons-licens

Site Settings by PowerShell part 1.1 Delete navigation nodes


This time I will give you a sample script that will enumerate all of your subwebs and remove a node from the current navigation.
A very useful script if you have a large and complec site structure and when you want to change the global or current navigation.

In my example, I am enumerating all subwebs of my sitecollection, and in the current navigation of every subweb, I remove the ‘Ste Pages’ link that you get from enabling publishing. If you want to remove a different link, find the ID of that link and replace or add a $currentnode… to the script.

Since my users have no use for the ‘site pages’ link, I’ll simply remove it from navigation.

# get a sitecollection object(SPSite) 
$SPSite = Get-SPSite -Identity “http://farm.company.local/sitecollection“ 
# loop through all the subwebs(SPWebs) in the site collection 
foreach ($SPWeb in $SPSite.AllWebs) 
{   
# Get a navigation node object and delete it   
$currentnode = $SPWeb.Navigation.GetNodeByID(2001)   
$currentnode.Delete()   
# Make it stick...   
$SPWeb.Update()   
Write-Host “Removing the Node: ” $currentNode.URL 
}

A comlex way of finding out a nodes ID, is to do as follows:

$SPWeb = Get-SPWeb "http://farm.company.local/sitecollection/Web"

(Check in site settings/Navigation what the url for the node is, for example:)

$currentnode = $web.Navigation.GetNodeByUrl 
("site/Web/SharedDocuments/Forms/AllItems.aspx") 
$currentnode.ID

That will probably give you the ID 2002 for ‘Shared Documents’

Thats it!

Good luck.

Create a new ‘State Service’ Service Application using Powershell


I encountered this issue and had some trouble finding the correct info on it, so I thought that I’s share a good guide with all of you.

If you have made the correct choice to not run the configuration wizard to install all of the Service Applications…then you may encounter that you are missing the State Service Application. It can also be from deleting it after it was created by the wizard…
This Service Application is not available for creation in the New dialog in Central Administration, Manage Service Application, so it requires some special treatment.

An example of how it can look when this service Application is missing can look like this (in Health analyzer):

Title : InfoPath Forms Services forms cannot be filled out in a Web browser because no State Service connection is configured.
Severity : 2 – Warning
Category : Configuration
Explanation : InfoPath Forms Services is not functional on the following Web applications because there is no service connection configured for the State Service: SharePoint – 80
Remedy : If a State Service application doesn’t exist, create one by using the new-SPStateServiceApplication Powershell commandlet. For more information on configuring the State Service, see Help. For more information about this rule, see “http://go.microsoft.com/fwlink/?LinkID=142645“.
Failing Servers: XXXXXXXX
Failing Services: SPTimerService (SPTimerV4)

The obvious command new-SPStateServiceApplication  gives you this:

PS C:\Media\ConfigScript> New-SPStateServiceApplication  -Name “State Service Application” -Database “SharePoint_Service _State” New-SPStateServiceApplication : The pipeline has been stopped. At line:1 char:30 + New-SPStateServiceApplication <<<<   -Name “State Service Application” -Database “SharePoint_Service_State”     + CategoryInfo          : InvalidData: (Microsoft.Offic…plicationCmdlet:NewStateServiceApplicationCmdlet) [New-S    PStateServiceApplication], PipelineStoppedException     + FullyQualifiedErrorId : Microsoft.Office.Server.Administration.NewStateServiceApplicationCmdlet

New-SPStateServiceApplication : The specified object was not found. Parameter name: Database At line:1 char:30 + New-SPStateServiceApplication <<<<   -Name “State Service Application” -Database “SharePoint_Service_State”     + CategoryInfo          : InvalidArgument: (Microsoft.Offic…plicationCmdlet:NewStateServiceApplicationCmdlet) [N    ew-SPStateServiceApplication], ArgumentException     + FullyQualifiedErrorId : Microsoft.Office.Server.Administration.NewStateServiceApplicationCmdlet

Do not let this put you down, the correct way to create a new State Service Application is a bit different, no thanks to the get-help command…the syntaxt to use is as follows:

1. $serviceApp = New-SPStateServiceApplication -Name “State Service Application”
2. New-SPStateServiceDatabase -Name “SharePoint_Service_State” -ServiceApplication $serviceApp
3. New-SPStateServiceApplicationProxy -Name “State Service Application Proxy” -ServiceApplication $serviceApp -DefaultProxyGroup

Thats it!

Good luck.

Site Settings by Powershell part 1 – Navigation


Configuring your site settings is really something that you want to do using PowerShell, this is for many reasons but the most obvious ones are that you get more control. You can test your script with settings in a test environment and see the effect, when it is perfected you simply run the script against a different URL and the result is moved to the proper target environment.
One more benefit is repeatability, you can do one configuration and repeat it for every site or web in your farm. Doing the same thing manually would take time and would increase the risk of making mistakes.
(See more Site settings by Powershell in my Whitepaper that can be downloaded from here: SharePoint 2010 Site Settings explained. I have tried to cover most every site setting and how it can be done using Powershell only. )

All of these settings can also be configured during site creation, in order to do that, get your publishingweb object of the websites you are creating, set the values and same as always, finish off with an update().

In this post I will try to cover most of the settings you can do in the Navigation part of your site settings. The Navigation settings are available only in sites in a site collection that has the SharePoint Server Publishing Infrastructure Site Collection Feature activated.

Activating this feature gives you among many other things, control over the global and current navigations. These settings are available in Site Settings under Look and Feel.

The settings that I will show how to configure using PowerShell are as shown in the below image. There are also ways to add and remove items from the navigations in the same dialog, but these will not be covered here.

First off, we need an object to work with. In this case we need a Publishing Web object, so first we create a spweb object, then a publishing web object:

$SPWeb = Get-SPSPWeb http://server/sitecoll/spweb/spweb
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb] 
::GetPublishingWeb($SPWeb)

Some changes, like unchecking the Show subsites, require that you first allow unsafe updates. You can set the show subsites to false, but it will never be reflected unless you first allow unsafe updates. This is done on the SPWeb object by:

$SPWeb.AllowUnsafeUpdates = $true

Using our Publishing Web object, we can now configure the different settings, from the top in the graphical user interface:

Global Navigation

Display the same navigation items as the parent site:

$SPPubWeb.Navigation.InheritGlobal = $true

Display the navigation items below the current site:

$SPPubWeb.Navigation.InheritGlobal = $false

Show subsites:

$SPPubWeb.Navigation.GlobalIncludeSubSites = $true

Show pages:

$SPPubWeb.Navigation.GlobalIncludePages = $true

Maximum number of dynamic items to show within this level of navigation:

$SPPubWeb.Navigation.GlobalDynamicChildLimit = 20 (int32)

Current Navigation

Display the same navigation items as the parent site: (both values in combination)

$SPPubWeb.Navigation.InheritCurrent = $true
$SPPubWeb.Navigation.ShowSiblings = $false

Display the current site, the navigation items below the current site, and the current site’s siblings: (both values in combination)

$SPPubWeb.Navigation.InheritCurrent = $false
$SPPubWeb.Navigation.ShowSiblings = $true

Display only the navigation items below the current site: (both values in combination)

$SPPubWeb.Navigation.InheritCurrent = $false
$SPPubWeb.Navigation.ShowSiblings = $false

Show subsites:

$SPPubWeb.Navigation.CurrentIncludeSubSites = $true

Show pages:

$SPPubWeb.Navigation.CurrentIncludePages = $true

Maximum number of dynamic items to show within this level of navigation:

$SPPubWeb.Navigation.CurrentDynamicChildLimit = 20 (int32)

Sorting

Sort automatically:

$SPPubWeb.Navigation.OrderingMethod = "Automatic"

Sort manually:

$SPPubWeb.Navigation.OrderingMethod = "Manual"

Sort sites manually and pages automatically: (This is option is only available with publishing pages)

$SPPubWeb.Navigation.OrderingMethod = "ManualWithAutomaticPageSorting”

When Sort automatically is selected

Sort by Title (shown left):

$SPPubWeb.Navigation.AutomaticSortingMethod = "Title"

Sort by Created Date:

$SPPubWeb.Navigation.AutomaticSortingMethod = "CreatedDate"

Sort by Last Modified Date:

$SPPubWeb.Navigation.AutomaticSortingMethod = "LastModifiedDate"

Sort in ascending order (shown left):

$SPPubWeb.Navigation.SortAscending = $true

Sort in descending order:

$SPPubWeb.Navigation.SortAscending = $false

 

That’s it, that covers all of the settings I meant to show and this will hopefully be useful to you when scripting the creation and configuration of your sites.
In order to help you get started, you can modify the script included below and that will allow you to configure all of the above settings the same way on all sites in a designated site collection.

Sample script

# get a sitecollection object(SPSite)
$SPSite = Get-SPSite -Identity “http://farm.company.local/sitecollection“
# loop through all the subwebs(SPWebs) in the site collection
foreach ($SPWeb in $SPSite.AllWebs)
{
  # check so that this is not the root web
  if (!$SPWeb.IsRootWeb)
  {

 # Save AllowUnsafeUpdates setting and set it to allow.
    $AllowUnsafeUpdatesStatus = SPWeb.AllowUnsafeUpdates
 SPWeb.AllowUnsafeUpdates = $true
 # Get a PublishingWeb object for the current web
    $SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]
 ::GetPublishingWeb($SPWeb)

    # UnComment the setting you will use:
    # Global settings
    # $SPPubWeb.Navigation.InheritGlobal = $true
    # $SPPubWeb.Navigation.InheritGlobal = $false
    # $SPPubWeb.Navigation.GlobalIncludeSubSites = $true
    # $SPPubWeb.Navigation.GlobalIncludeSubSites = $false
    # $SPPubWeb.Navigation.GlobalIncludePages = $true
    # $SPPubWeb.Navigation.GlobalIncludePages = $false
    # $SPPubWeb.Navigation.GlobalDynamicChildLimit = 20
    # Current settings
    # See combination of the two below
    # $SPPubWeb.Navigation.InheritCurrent = $true
    # $SPPubWeb.Navigation.ShowSiblings = $false
    # $SPPubWeb.Navigation.CurrentIncludeSubSites = $true
    # $SPPubWeb.Navigation.CurrentIncludePages = $true
    # $SPPubWeb.Navigation.CurrentDynamicChildLimit = 20
    # Sorting
    # $SPPubWeb.Navigation.OrderingMethod = "Automatic"
    # $SPPubWeb.Navigation.OrderingMethod = "Manual"
    # $SPPubWeb.Navigation.OrderingMethod = "ManualWithAutomaticPageSorting”
    # $SPPubWeb.Navigation.AutomaticSortingMethod = "Title"
    # $SPPubWeb.Navigation.AutomaticSortingMethod = "CreatedDate"
    # $SPPubWeb.Navigation.AutomaticSortingMethod = "LastModifiedDate"
    # $SPPubWeb.Navigation.SortAscending = $true
    # $SPPubWeb.Navigation.SortAscending = $false
    $SPPubWeb.Update()
  }
  # cleanup 
 # Set AllowUnsafeUpdates back to original value
 $SPWeb.AllowUnsafeUpdates = $AllowUnsafeUpdatesStatus
  $SPWeb.Dispose() }
# cleanup
$SPSite.Dispose()

Please allow some time for the changes to take affect, it can take a couple of minutes until the changes are reflected in your navgation.

Reference:

PortalNavigation Members

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.navigation.portalnavigation_members.aspx

2012-02-16 Updates: Added $SPWeb.AllowUnsafeUpdates section to script.