Wednesday, October 10, 2012

Powershell script sync Sharepoint user from AD


Powershell script sync Sharepoint user from AD

get-spuser -identity domain\user -web url
set-spuser -identity domain\user -SyncFromAD -web url

Monday, September 10, 2012

Powershell Bulk upload by putting the keywords in text or csv file

get-content "C:\path\NameOfFile.csv" | foreach-object {   New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication "Fast Query" -Language en-US -Type QuerySuggestionAlwaysSuggest -Name $_ }

Monday, January 16, 2012

Powershell script update draft version Sharepoint 2010

#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://yoursite.com/
$lookForList = "Shared documents"
#Walk through each site and change draft settings on the list specified
$site | Get-SPWeb -Limit all | ForEach-Object {
   
    write-host "Checking site:"$_.Title
   
    #Make sure the library exists
    $docLibrary = $_.Lists[$lookForList]
   
    if ($docLibrary -ne $null)
    {
        $docLibrary.DraftVersionVisibility = 1
        $docLibrary.Update()
 write-host $docLibrary.Title "on site" $_.Title "is updated"
    }
    else
    {
        write-host "The list" $lookForList "does not exist in site" $_.Title
    }
}
#Dispose of the site object
$site.Dispose()

Powershell script modify webpart on page Sharepoint 2010

$site = new-object Microsoft.SharePoint.SPSite("http://yoursite.com")
$web = $site.OpenWeb("RandomSite/AnotherSite/")
$page = $web.GetFile("Pages/default.aspx")
$page.CheckOut()
$wpm = $web.GetLimitedWebPartManager("Pages/default.aspx", [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$wpm.WebParts | ft

$wp = $wpm.WebParts[1]
$wp.EnableRedirect = $false
$wp.Url = "http://www.google.com/"
$wpm.SaveChanges($wp)
$page.CheckIn("Test")
$page.Publish("Test")
$web.Close()
$site.Close()

Powershell script list all powershell commands in a text file

Get-Command –PSSnapin “Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell” format-table name > C:\SP2010_PowerShell_Commands.txt

Powershell script install feature Sharepoint 2010

$MyFeatureId = $(Get -SPFeature -limit all where {$_.displayname -eq "myfeatureName"}).Id
Install -SPFeature $MyFeatureId

Powershell script activate developer dashboard on demand in your Sharepoint 2010 environment

$dd = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$dd.DisplayLevel = ‘On Demand’;
$dd.TraceEnabled = $true;
$dd.Update ();

Powershell script disable feature Sharepoint 2010 site collection

$singleSiteCollection = Get-SPSite -Identity http://yoursite.com/
Disable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL

Powershell script change title of a document library in your Sharepoint 2010 site collection

#Change these variables to your site URL and list name
$site = Get-SPSite http://yoursite.com/
$listName = "Shared Documents"
#Walk through each site in the site collection
$site | Get-SPWeb | ForEach-Object {
#Get the list in this site
$list = $_.Lists[$listName]
#Make the list changes
$list.Title = "Documents"
$list.Description = "Use the Documents library to store shared files"
#Update the list
$list.Update()
}
#Dispose of the site object
$site.Dispose()

Powershell script add webpart to your Sharepoint 2010 sites in your site collection

$site = new-object Microsoft.sharePoint.SPSite("http://yoursite.com/")
$web=$site.OpenWeb()$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)$defaultpage=$pubweb.GetPublishingPages()[$pubweb.DefaultPage]$defaultpage.CheckOut()$webpartmanager=$web.GetLimitedWebPartManager($defaultpage.Url,
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)$webpart=new-object  Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
$webpart.ChromeType=[System.Web.UI.WebControls.WebParts.PartChromeType]::TitleOnly;
$webpart.Title="Name of your Webpart"
$webpartmanager.AddWebPart($webpart, "Left", 0);$defaultpage.CheckIn("Checked in Webpart")
$defaultpage.listItem.File.Publish("Published Webpart")
if ($defaultpage.listItem.ParentList.EnableModeration)
{
   $modInformation = $defaultpage.listItem.ModerationInformation   if($modInformation.Status -ne [Microsoft.SharePoint.SPModerationStatusType]::Approved)
   {
      $defaultpage.ListItem.File.Approve("Approved Page")
   }
}