Tag Archives: PowerShell

Activating all Publishing Feature – Programmatically & Powershell – SharePoint 2010, 2013, 2016 & Online:

Hi Everyone!!!

Today i will talk about Publishing Features!!! During this afternoon I was trying to activate Publishing Features but i wasn’t having success because Page Library not was created on activation! So there are more than two Publishing Feature that we need have in consideration, it’s not enough Activate Publishing Infrastructure Feature and Publishing Feature. If you want activate all Publishing Features you can do it pragmatically or using Powershell script:

SharePoint Server – Powershell:

 
Disable-SPFeature –identity 'publishingSite' -URL http://server/ -force
Disable-SPFeature –identity 'PublishingResources' -URL http://server/-force
Disable-SPFeature –identity 'Publishing' -URL http://server/ -force
Disable-SPFeature –identity 'PublishingLayouts' -URL http://server/ -force
Disable-SPFeature –identity 'publishingweb' -URL http://server/ -force

Enable-SPFeature –identity 'publishingSite' -URL http://server/ -force
Enable-SPFeature –identity 'PublishingResources' -URL http://server/ -force
Enable-SPFeature –identity 'Publishing' -URL http://server/ -force
Enable-SPFeature –identity 'PublishingLayouts' -URL http://server/ -force
Enable-SPFeature –identity 'publishingweb' -URL http://server/ -force

SharePoint Online – Powershell:

 
Disable-SPOFeature –Identity "F6924D36-2FA8-4f0b-B16D-06B7250180FA" -Scope Site
Disable-SPOFeature –Identity "AEBC918D-B20F-4a11-A1DB-9ED84D79C87E" -Scope Site
Disable-SPOFeature –Identity "22A9EF51-737B-4ff2-9346-694633FE4416" -Scope Web
Disable-SPOFeature –Identity "D3F51BE2-38A8-4e44-BA84-940D35BE1566" -Scope Site
Disable-SPOFeature –Identity "94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" -Scope Web

Enable-SPOFeature –Identity "F6924D36-2FA8-4f0b-B16D-06B7250180FA" -Scope Site
Enable-SPOFeature –Identity "AEBC918D-B20F-4a11-A1DB-9ED84D79C87E" -Scope Site
Enable-SPOFeature –Identity "22A9EF51-737B-4ff2-9346-694633FE4416" -Scope Web
Enable-SPOFeature –Identity "D3F51BE2-38A8-4e44-BA84-940D35BE1566" -Scope Site
Enable-SPOFeature –Identity "94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" -Scope Web

Also that you can activate Programmatically:

 

        private void ActivatePublishingFeatures(SPWeb web, SPSite site)
        {
            // Publishing Site
            string sharePointPublishingSite = "f6924d36-2fa8-4f0b-b16d-06b7250180fa";
            Guid sharePointPublishingSiteGuid = new Guid(sharePointPublishingSite);

            if (site.Features[sharePointPublishingSiteGuid] == null)
            {
                site.Features.Add(sharePointPublishingSiteGuid, true);
            }

            // Publishing Resources
            string sharePointPublishingResources = "aebc918d-b20f-4a11-a1db-9ed84d79c87e";
            Guid sharePointPublishingResourcesGuid = new Guid(sharePointPublishingResources);

            if (site.Features[sharePointPublishingResourcesGuid] == null)
            {
                site.Features.Add(sharePointPublishingResourcesGuid, true);
            }

            // Publishing
            string sharePointPublishing = "22a9ef51-737b-4ff2-9346-694633fe4416";
            Guid sharePointPublishingGuid = new Guid(sharePointPublishing);

            if (web.Features[sharePointPublishingGuid] == null)
            {
                web.Features.Add(sharePointPublishingGuid, true);
            }

            // Publishing Layouts
            string sharePointPublishingLayouts = "d3f51be2-38a8-4e44-ba84-940d35be1566";
            Guid sharePointPublishingLayoutsGuid = new Guid(sharePointPublishingLayouts);

            if (site.Features[sharePointPublishingLayoutsGuid] == null)
            {
                site.Features.Add(sharePointPublishingLayoutsGuid, true);
            }

            // Publishing Web
            string sharePointServerPublishingWeb = "94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb";
            Guid sharePointServerPublishingWebGuid = new Guid(sharePointServerPublishingWeb);

            if (web.Features[sharePointServerPublishingWebGuid] == null)
            {
                web.Features.Add(sharePointServerPublishingWebGuid, true);
            }
        }

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

 

 

SharePoint – Get all alerts from a specific SP List/Library using Powershell

Hey Everyone!!!

Today i will talk about List and Library Alerts and how can you get all Active alerts for a specific list using powershell script and how can you disable all alerts.

This is very useful script, when you need move a large list of items on a maintenance routine and you don’t want send a large number of emails/ notifications for users who subscribe alerts, this script help you disable and enable them.

This first PowerShell Script get all SharePoint list alerts with state active.

 

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue

#Variables
$WebURL = "http://YourWebUrl"
$ListName="YourListName"

#Function to Get All Active Alerts on a Given List
Function Get-ListAlerts($WebURL, $ListName)
{
  #Get the Web and List objects
  $Web = Get-SPWeb $WebURL
  $List = $web.Lists.TryGetList($ListName)

  #Get All Alerts created in the list - Which are Active
  $ListAlerts = $Web.Alerts | Where-Object {($_.List.Title -eq $List.Title) -and ($_.Status -eq "ON")}

  foreach($Alert in $ListAlerts)
  {
          write-host "Alert' - $($Alert.Title)' Created for User - '$($Alert.User.Name)'"
  }

 #Dispose web object
 $Web.Dispose()
}

#Call the function Appropriately to Disable or Enable Alerts 
Disable-ListAlerts $WebURL $ListName

 

 

If you want disable all alerts on this specific list you just need run the following script.

 

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue

#Variables
$WebURL = "http://YourWebUrl"
$ListName="YourListName"

#Function to Disable All Active Alerts on a Given List
Function Disable-ListAlerts($WebURL, $ListName)
{
  #Get the Web and List objects
  $Web = Get-SPWeb $WebURL
  $List = $web.Lists.TryGetList($ListName)

  #Get All Alerts created in the list - Which are Active
  $ListAlerts = $Web.Alerts | Where-Object {($_.List.Title -eq $List.Title) -and ($_.Status -eq "ON")}

  Write-host "Total Number of Active Alerts Found in the list: $($ListAlerts.Count)" 
 
  #Iterate through each alert and turn it OFF
  foreach($Alert in $ListAlerts)
  {
     $Alert.Status="OFF"
     $Alert.Update()
     write-host "Disabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
  }
 
 #Dispose web object
 $Web.Dispose()
}

#Call the function Appropriately to Disable or Enable Alerts 
Disable-ListAlerts $WebURL $ListName

 

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

SharePoint 2016 – Create Service Accounts using PowerShell script

Hey Everyone!!!

Today i will show you how can you create SharePoint 2016 Service Accounts using PowerShell script following the Best Practices.

The script not only create all the accounts but also create the respectives OU (Organizational Unit):

  • SharePoint Accounts
  • SQL Accounts

Service Accounts:

 Name Description Local Rights Domain Rights
SP_FarmThe server farm account is used to perform the following tasks:
-Configure and manage the server farm.
-Act as the application pool identity for the SharePoint Central Administration Web site.
-Run the Microsoft SharePoint Foundation Workflow Timer Service.
SecurityAdmin and DB_Creator rights on the SQL InstanceDomain User
SP_AdminThe server farm account is used to perform the following tasks:
-Setup
-SharePoint Products Configuration Wizard
Local Administrator on all the SharePoint Servers. SecurityAdmin and DB_Creator rights on the SQL InstanceDomain User
SP_PoolThe Pool account is used to run the Web Application PoolsNoneDomain User
SP_ServicesThe Services Account is used to run the Service Application PoolNoneDomain User
SP_CrawlThe Default Content Access Account for the Search Service ApplicationNoneDomain User
SP_SearchService Account to run the SharePoint Search “Windows Service”NoneDomain User
SP_UserProfilesThe User Profile Synchronization AccountNoneDomain User
SP_MySitePoolUsed for the My Sites Web ApplicationNoneDomain User
SP_CacheSuperUserObject Cache Service Account. The goals of the object cache are to reduce the load on the computer on which SQL Server is running, and to improve request latency and throughput. These user account must be properly configured to ensure that the object cache works correctly.None.
SharePoint: Must be an account that has Full Control access to the Web application.
Domain User
SP_CacheSuperReaderObject Cache Service Account. The goals of the object cache are to reduce the load on the computer on which SQL Server is running, and to improve request latency and throughput. These user account must be properly configured to ensure that the object cache works correctly.None.
SharePoint: Must be an account that has Full Read access to the Web application
Domain User
WF_ServiceWorkFlow Manager Service AccountLocal Administrator and SysAdmin rights on the SQL instance.Domain User
SP_MySitePoolUsed for the My Sites Web ApplicationNoneDomain User
SP_VisioUserVisio Unattended IDNoneDomain User
SP_ExcelUserExcel Unattended IDNoneDomain User
SP_PerfPointUserPerformance Point Unattended IDNoneDomain User
SQL_AdminSQL Admin on the SQL Server. Used to Install the SQL Server.Local Administrator on the SQL ServerDomain User
SQL_ServicesIt is the service account for the following SQL Server services: MSSQLSERVER SQLSERVERAGENTNoneDomain User


Script:

 

$mydom = (get-addomain).distinguishedname 
$password = "pass@word1" | ConvertTo-SecureString -AsPlainText -Force 

$ouNameSP = "SharePoint Accounts"
$oudnSP = "OU=$ounameSP,$mydom" 

$ouNameSQL = "SQL Accounts" 
$oudnSQL = "OU=$ounameSQL,$mydom" 

#----------------------------> Organizational Unit <---------------------------- 

New-ADOrganizationalUnit -Name $OUNameSP -Path $mydom 
Write-Host "OU $OUNameSP Created" -foregroundcolor green 

New-ADOrganizationalUnit -Name $OUNameSQL -Path $mydom 
Write-Host "OU $OUNameSQL Created" -foregroundcolor green 

#-----------------------------> SharePoint 2016 <-------------------------------

$usersArraySP = @("SP_Farm","SP_Admin","SP_Pool","SP_Services","SP_Crawl","SP_Search",
                  "SP_UserProfiles","SP_PortalSuperReader","SP_CacheSuperUser","SP_VisioUser",
                  "SP_PerfPointUser","WF_Service","SP_MySitePool","SP_PortalSuperUser")

foreach ($usp in $usersArraySP) {
        New-ADUser -Name $usp -DisplayName $usp -SamAccountName $usp -AccountPassword $password 
        -ChangePasswordAtLogon $false -PassThru -PasswordNeverExpires $true -Path $oudnSP 
        Write-Host "$usp Created" -foregroundcolor green
 }

#----------------------------------> SQL <--------------------------------------
$usersArraySQL = @("SQL_Admin","SQL_Service")

foreach ($usql in $usersArraySQL) {
       New-ADUser -Name $usql -DisplayName $usql -SamAccountName $usql -AccountPassword $password 
       -ChangePasswordAtLogon $false -PassThru -PasswordNeverExpires $true -Path $oudnSQL
       Write-Host "$usql Created" -foregroundcolor green
 }

 

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

SharePoint – Export all solutions wsp using PowerShell script

Hey Everyone,

Today i will post a script very helpful when you are on Migration steps and you need export all wsp solutions.

 

$dirName = "C:\WSP"
if (!(Test-Path -path $dirName))
{
New-Item $dirName -type directory
}
Write-Host Exporting solutions to $dirName
foreach ($solution in Get-SPSolution)
{
    $id = $Solution.SolutionID
    $title = $Solution.Name
    $filename = $Solution.SolutionFile.Name
    Write-Host "Exporting ‘$title’ to …\$filename" -nonewline
    try {
        $solution.SolutionFile.SaveAs("$dirName\$filename")
        Write-Host " – done" -foreground green
    }
    catch
    {
        Write-Host " – error : $_" -foreground red
    }
}

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|