Browse by Tags

  • Remove Group Permissions

    Niklas Goude -Expert in Residence You can remove a group’s permissions on a specific Web site with Windows PowerShell. Simply remove the group from the role assignment collection: PS > $spWeb = Get-SPWeb http : // SP01.powershell.nu PS > $spPrincipal = [ Microsoft.SharePoint.SPPrincipal ] $spWeb . SiteGroups [ "Site Members" ] PS > $spWeb . RoleAssignments . Remove ( $spPrincipal ) PS > $spWeb . Dispose () ReTweet this...
  • Removing Nodes from the QuickLaunch

    Niklas Goude -Expert in Residence You can use Windows PowerShell when removing one (or more) nodes from a Web site’s QuickLaunch. The example below shows how you can remove everything except for nodes under the lists heading: PS > $spWeb = Get-SPWeb http : // SP01.powershell.nu -ErrorAction Stop PS > foreach ( $node in ( $spWeb . Navigation . QuickLaunch | >> Where-Object { $_ . Title -ne "Lists" })) { >> $node ....
  • Handling Errors in Your Scripts

    Niklas Goude -Expert in Residence When creating automated SharePoint scripts using Windows PowerShell, it’s a good idea to add some form of error handling. A typical example is when you try to access a non-existent site collection. By default, Windows PowerShell displays an error message. You can use a Try/Catch statement if you want to handle this. Note that the –ErrorAction is set to stop on the cmdlet: $url = "http://SP01.powershell...
  • Enable Auditing

    Niklas Goude -Expert in Residence You can enable site audit using Windows PowerShell. The example below demonstrates how to add specific audit flags on a site collection and enable auditing: PS > $spSite = Get-SPSite http : // SP01.powershell.nu PS > $spSite . Audit . AuditFlags = >> ([ Microsoft.SharePoint.SPAuditMaskType ] :: All ` >> - bxor [ Microsoft.SharePoint.SPAuditMaskType ] :: View ) PS > $spSite . Audit . Update ()...
  • Changing Locale

    Niklas Goude -Expert in Residence You can change a Web site’s locale setting using Windows PowerShell. Simply replace the value of the locale property by using an object of the type System.Globalization.CultureInfo. The example below shows how to set the locale to Swedish: PS > $culture = [ System.Globalization.CultureInfo ] :: CreateSpecificCulture ( “ sv - SE ” ) PS > $spWeb = Get-SPWeb http : // SP01.powershell.nu PS >...
  • Create Default Associated Groups

    Niklas Goude -Expert in Residence When creating Web site using PowerShell, you may encounter situations where you’re missing the site’s default groups. A simple solution to this is using the CreateDefaultAssociatedGroups method. The example below demonstrates how you can use the method: PS > $spWeb = Get-SPWeb http : // SP01.powershell.nu PS > $spWeb . CreateDefaultAssociatedGroups ( "powershell\spAdmin" , ""...
  • Changing Custom Master Page

    Niklas Goude -Expert in Residence You can use Windows PowerShell to change a Web’s custom master page. Simply point the CustomMasterUrl to a new master page: PS > $spWeb = Get-SPWeb http : // SP01.powershell.nu PS > $spWeb . CustomMasterUrl = "/_catalogs/masterpage/myNew.master" PS > $spWeb . Update () PS > $spWeb . Dispose () ReTweet this Tip!
  • Adding Solutions

    Niklas Goude -Expert in Residence Did you know that when you upload solution packages to a farm, you can use the Add-SPSolution cmdlet? Simply: # Adding a Solution Add-SPSolution – LiteralPath C:\Stuff\MySolution.wsp After you’ve uploaded a solution package, you can use the Install-SPSolution cmdlet. The example below will get you all solutions and then filter out the solution where the name is equal to MySolution.wsp. Finally, the solution...
  • Adding Managed Accounts using PowerShell

    Niklas Goude -Expert in Residence You can add SharePoint 2010 managed accounts by using New-SPManagedAccount in Windows PowerShell. When creating automated scripts, you may want to check if an account is already a managed account. Simply use Get-SPManagedAccount and a simple if/else statement to determine if the managed account already exists. Here’s a short code example: $userName = "domain\user" if ( Get-SPManagedAccount | Where...
  • Adding Alternate Access Mappings using PowerShell

    Niklas Goude -Expert in Residence Adding Alternate Access Mappings is a simple task using Windows PowerShell. You can simply use the New-SPAlternateUrl cmdlet, which supports the creation of internal or public URLs for a given Web application. The examples below demonstrate how to create both a public and internal URL: # Public PS > New-SPAlternateURL -Url http : // public.powershell.nu ` >> -Zone "Internet" -WebApplication http...
  • Add Managed Paths to Web Applications using PowerShell

    Niklas Goude -Expert in Residence You can use the New-SPManagedPath cmdlet to add managed paths to a given Web application: PS > New-SPManagedPath -RelativeURL MyPath ` >> -WebApplication http : // SP01.powershell.nu The example above creates a “MyPath” managed path for the Web application http://SP01.powershell.nu. ReTweet this Tip!
  • User Management in SharePoint 2010 with PowerShell

    Niklas Goude -Expert in Residence SharePoint 2010 includes three cmdlets that you can use to manage users in SharePoint 2010. Here’s an example on adding a new user: New-SPUser "XYZ\david" -Web http : // SP -PermissionLevel "Contribute" The example above adds the user “david” to the specified site and sets the user permissions to contribute. You can retrieve an existing user through the Get-SPUser cmdlet: Get...
  • Backup and Restore Site Collections in SharePoint 2010 using PowerShell

    In SharePoint 2010 you can take a backup of a site collection using the Backup-SPSite cmdlet: Backup-SPSite http : // SP – Path C:\Backup\siteCollection.bak Restoring a site collection in SharePoint 2010 is just as simple: Restore-SPSite http : // SP – Path C:\Backup\siteCollection.bak ReTweet this Tip!
  • Managing sites in SharePoint 2010 Using PowerShell cmdlets

    In SharePoint 2010 you can manage sites through Windows PowerShell. You can create new sites in a site collection using the New-SPWeb cmdlet: New-SPWeb http : // SP / TeamSite -Template "STS#0" – Name "Team Site" ` -Description "Description of Site" – AddToTopNav – UseParentTopNav You can retrieve an existing site using the Get-SPWeb cmdlet: Get-SPWeb http : // SP / TeamSite You can configure a site...
  • Adding List Items using PowerShell

    SharePoint 2010 offers over 500 new cmdlets that we can use to automate the SharePoint 2010 environment through Windows PowerShell. The cmdlets go as deep as SPWeb, everything beyond SPWeb requires additional scripting, such as adding fields, views and items. Here’s an example showing how to add an item to the Announcements list in SharePoint 2010: $spWeb = Get-SPWeb -identity http : // SP $spList = $spWeb . GetList ( “ Lists / Announcements...
Idera SharePoint Reviews SMBology, Inc. Rackspace Hosting Sponsored by Idera and SharePoint Reviews and SMBology and EPCGroup.net
Copyright 2011 SecretsOfSharePoint.com. All rights reserved.