Saturday, August 31, 2013

Change SharePoint Site Collection Quota using PowerShell

In some cases, I have seen site collection quotas are turned to "Individual Quota" in database attachment method, even I copied the quota templates before database attachment. All quota settings are lost! I dunno the cause of this issue and want to apply site collection quota to existing sites.

To apply quota for SharePoint site collection using PowerShell, the syntax goes like:
Set-SPSite -Identity "Site-collection-URL" -QuotaTemplate "Quota-Template-Name"

E.g.
Set-SPSite -Identity "http://sharePoint.company.com/sites/sales" -QuotaTemplate "Gold - 1 GB"
Where "Gold - 1 GB" is our existing quota defined! We can apply quotas in bulk with PowerShell now!

Change quota for SharePoint Site Collections programmatically:
To set site collection quota for SharePoint sites programmatically using PowerShell, The code goes like:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Void]System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") 

function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }

$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService

$QuotaTemplate = $contentService.QuotaTemplates["Gold - 1 GB"]
$site = Get-SPSite "http://sharepoint.company.com/"
$site.quota=$QuotaTemplate 

Set Individual Quotas using PowerShell:
#Set the site URL variable accordingly!
$SiteURL = "http://sales.crescent.com"

Set-SPSite -Identity $SiteURL -MaxSize 1GB -WarningSize 900MB 

Bulk update SharePoint Site collection quotas:
In an another case, Got a requirement to change quota template for all site collections under a specific managed path (say: Departments)
$WebAppURL = "http://sharepoint.crescent.com"

$TemplateName ="Gold - 1 GB"

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$TemplateName]

Get-SPWebApplication $WebAppURL | Get-spsite -limit all | Where-Object {$_.ServerRelativeUrl.StartsWith("/departments/")} |  ForEach-Object { $_.Quota = $quotaTemplate }

To Remove a Quota Assigned (either via Quota Template or Individual Quota) to a Site collection, Use:
$Site = Get-SPSite -Identity "http://your-site-collection.com/"
$Site.Quota = $null           

SharePoint 2007 - Set quotas in Bulk with STSADM:
We can set site collection quota in bulk using stsadm -o updatequota command line. Its available after installing SharePoint Administration Toolkit version 4.0

E.g. stsadm –o updatequota –quotaname "Name of the Quota defined in Central Admin" 
Its also possible to limit the quota changes with in a content database. More info: http://technet.microsoft.com/en-us/library/ee449569%28v=office.12%29.aspx  

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 29, 2013

Add Site Collection Administrators Programmatically in SharePoint

SharePoint site collection administrators have Full rights to all sites within a site collection. Primary site collection administrator and Secondary site collection administrator specified in central administration will automatically become site collection admins. Its also possible to add multiple site collection admins for any SharePoint site collection.

How to add site collection administrator in SharePoint?
To add site collection administrator in SharePoint, you must be either Farm Administrator or another Site Collection Administrator of the site collection. Navigate to Site Settings >> Click on "Site collection administrators" link under "Users and Permissions"
add site collection administrator programmatically

which will lead you to a page where you can manage site collection administrators.

How to Add Site Collection Administrators Programmatically with C#?
In some scenarios, we may have to add site collection administrators programmatically. Say for e.g. There may be a requirement to add a particular user as site collection administrator to multiple site collections. Here is the code to add site collection administrator programmatically:
            //Define the parameter values: Site collection URL and user account to remove
            string siteURL = "http://sharepoint.crescent.com/sites/operations";
            string userAccount = @"global\Salaudeen";

            using(SPSite site=new SPSite(siteURL))
            {
                using (SPWeb web = site.RootWeb)
                  {
                    //Get the User 
                     SPUser user = web.EnsureUser(userAccount);

                    //Make the user as Site collection Admin
                     user.IsSiteAdmin = true;
                     user.Update();

                    //Print a message
                    Console.WriteLine("User: "+userAccount +" has been added as site collection administrator!");
                   }
            }

            //Pause
            Console.ReadLine();
       
Add site collection administrator SharePoint 2010 with PowerShell
The above code can be transformed to PowerShell to add site collection administrator SharePoint 2010 programmatically. Here is how to add site collection administrator in SharePoint 2010 using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

    #Define the parameter values: Site collection URL and user account to remove
    $siteURL = "http://sharepoint.crescent.com/sites/operations"
    $userAccount = "Global\Salaudeen"
 
 Start-SPAssignment -Global
 
 #Get the RootWeb
 $web= Get-SPWeb $siteURL
 #Get the user acount - If doesn't exists ADD
 $user = $web.EnsureUser($userAccount)

 #Make the user as Site collection Admin
        $user.IsSiteAdmin = $true
        $user.Update()

       #Print a message
 Write-host "User: $($userAccount) has been added as site collection administrator!"
    
 Stop-SPAssignment -Global
So with the Power of scripting, we can add site collection administrator to all sites.

Add site collection administrator using stsadm:
We can also add a site collection admin for MOSS 2007 using STSADM tool. Here is an example:
stsadm.exe -o adduser -url "http://sharepoint.crescent.com/sites/operations" -userlogin "Global\Salaudeen" -useremail "Salaudeen@crescent.com" -role "Full Control" -username "Salaudeen Rajack" -siteadmin

If you are looking for a way to set SharePoint site collection's Primary administrator or secondary administrator, here is my another post for you: How to Change Site Collection Primary, Secondary Administrators in SharePoint


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Enable Wildcard Search by Default in SharePoint 2010

By default, Wildcard search is not enabled in SharePoint! Say for e.g. If you search for "Script" you will get results for the search query. But if you want to search using partial words ("sc" for "Script") that aren't complete, You will not get the search results until you add the wildcard character * in your queries (sc*)

Here are the screens to explain the above scenario: Search results for the complete word: Script
enabling wildcard search in sharepoint
Search results for the partial word: Sc
wildcard search on sharepoint
Yes, You can always add a wildcard character * in your queries: E.g. sc* to perform wildcard search in SharePoint 2010. But how to make it default without you/end-user entering the wildcard character every time?

Sure, We can enable wildcard search in SharePoint by default! here is how:

How to Enable Wildcard Search in SharePoint 2010
To enable Wildcard search in SharePoint Server 2010, Go to:
  • Central Administration >> Application Management 
  • Manage Service Applications >> Pick your Search service Application
  • Click on "Federated locations" under "Queries and Results" from Left navigation
  • Click on "Location Search Results" linkwildcard search for sharepoint 2010
  • Expand the "Location Information" section 
  • Append a * (asterisk) character to Query Template field - Change it from {searchTerms} to {searchTerms}*sharepoint 2010 wildcard search default
  • Scroll down and update the "More Results" Link Template from: results.aspx?k={searchTerms}To: (results.aspx?k={searchTerms}*) . Click "OK" to save changes. Sharepoint 2010 wildcard search
That's all . We have enabled SharePoint Server 2010 wildcard search! Wait for a moment for the search service to reflect your changes and see the result in action. We've typed "sc" as search string and SharePoint returned results for: sc*
sharepoint server 2010 wildcard search
The above method can be use to apply wildcard people search in SharePoint 2010 too!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, August 28, 2013

Fix Incoming Emails Not Working Issue in SharePoint Migration

Problem:
After a Database attach method of SharePoint migration from SharePoint 2007 to SharePoint 2010, all incoming E-mail enabled libraries stopped working! They no longer receive E-mails!!  Here is the root cause and fix for SharePoint incoming email stopped working issue.

Root Cause:
This is because, SharePoint stores incoming E-mail configurations on its Farm Configuration Database (usually SharePoint_Config) and during database attachment method of migration, We didn't (and we can't) migrate the configuration database. So, incoming email settings on SharePoint 2010 not working.

Solution:
One quick solution is simply Flip the value of  "Allow this list to receive e-mail?"
  1. Just go to List Settings
  2. Under Communication, click on "Incoming e-mail settings" link
  3. Select "Allow this list to receive e-mail?" to "No" and click on "Save"
  4. Now, go back to the Incoming e-mail settings again and choose ""Allow this list to receive e-mail?" to "Yes" and then save your changes.
    sharepoint document library incoming email not working
 We can also automate the above activities with PowerShell.

Wait, There is an elegant solution yet:
However there is an another efficient way by: Calling RefreshEmailEnabledObjects() method of SPSite object to refresh all Incoming Email settings! (or use: stsadm -o refreshdms command). Here is the PowerShell script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Get All Site Collections of the given web application
$SiteCollections = Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite -Limit All 
 
 #Iterate through Each site collection
 foreach ($site in $SiteCollections)
 {
  #Refresh Incoming Email settings
  $site.RefreshEmailEnabledObjects()
  #Write Ouput message
  Write-Host "Processed: $($site.rootweb.url)"
  #Dispose the Site object
    $site.Dispose() 
    }
Make sure you enabled incoming email settings in SharePoint central admin, before running this script


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, August 20, 2013

Update Web Part Properties using PowerShell in SharePoint

Ever wanted to update SharePoint web part properties programmatically? After a company acquisition, We had to change the company name from a custom web part's title, throughout the web application.

SharePoint update web part properties using PowerShell: 
$Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#configuration parameters
$WebURL="http://sharepoint.Crescent.com"

#Get objects
$web = Get-SPWeb $WebURL
$page = $web.GetFile("SitePages/Home.aspx")
$page.CheckOut()
$WebPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

#$WebPartManager.WebParts
$WebPartManager.WebParts | % { write-host $_.title}
#Get the Web part
$Webpart = $WebPartManager.WebParts | Where { $_.Title -eq "Shared Documents"}

#Update Webpart Property
$Webpart.Title = "Team Documents"

#Save and Publish
$WebPartManager.SaveChanges($Webpart)
$page.CheckIn("updated Title Property") 

Update Web Part Properties in entire Web Application:
Say, we want to update all web part titles containing "Crescent Inc." to "Lunar Inc."
#Get All Webs (sites)
$webs = Get-SPWebApplication "http://sharepoint.Crescent.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All
 
 #Iterate through webs
 foreach ($web in $webs)
 {
  #Get All Pages from site's Root into $AllPages Array
  $AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})
 
  #Search All Folders for Pages
  foreach ($folder in $web.Folders)
      {
          #Add the pages to $AllPages Array
          $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})
      }

   #Iterate through all pages
   foreach($Page in $AllPages)
     {
       #Web Part Manager to get all web parts from the page
        $webPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

       #Iterate through each web part
       foreach($webPart in $WebPartManager.WebParts)
          {
            $OldTitle=$webPart.title
            #Get the Content Editor web part with specific Title
            if($webPart.title -like "*Crescent Inc*")
             {
                  #Replace the Old Title
                  $webPart.title = $webPart.title.Replace("Crescent Inc.", "Lunar Inc.")
       
                  #Same method goes to update any other custom properties.
                  #E.g. To update Page viewer web part's link property:
                  #$webPart.ContentLink = "http://www.sharepointdiary.com" 
                  #To set built-it properties, E.g. To set Set the Chrome type programmatically use:
                  #$webPart.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::TitleAndBorder
                  
                  #Save the changes
                  $webPartManager.SaveChanges($webPart)
                
                  write-host "Updated '$($OldTitle)' on $($web.URL)$($Page.ServerRelativeUrl)"
             }
         }
      }
  }
Set  SharePoint web part properties programmatically using C#
Above code is fairly simple and we can re-write it in C# object model also.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, August 16, 2013

Remove Site Collection Administrator using PowerShell

How to remove a site collection administrator in SharePoint? To remove SharePoint Site Collection Administrator, we use "Site collection Administrators" link from site settings.
remove site collection administrator
You must be a Farm Administrator or site collection administrator to see this link, BTW! From this page, we can delete site collection administrators.
remove site collection administrator powershell

PowerShell Script to Remove Site Collection Administrator:
We may have to remove site collection administrators programmatically. Lets use PowerShell in SharePoint to remove site collection administrator:
Function RemoveSiteCollAdmin($AdminID, $SiteCollectionURL)
 {
 #Get the site collection
 $site = Get-SPSite $SiteCollectionURL

 #Get the Admin to remove from Site collection Administrator Group
 $Account = $site.RootWeb.SiteAdministrators | where {$_.UserLogin -eq $AdminID}
 
    #if User account found
 if($Account)
 {
  $Account.IsSiteAdmin = $false
  $Account.Update()
  Write-Host "$($AdminID) has been removed from Site Collection Administrator Group!"
 }
 else
 {
  Write-Host "$($AdminID) Not found in Site Collection Administrator Group!"
 }
}

 #Call the function to remove Site collection Admin
 RemoveSiteCollAdmin "Domain\UserAccount" "http://sharepoint.crescent.com/"

Note that, Primary Site collection administrator can't be removed and can be only changed! If you want to change a Primary Site collection administrator using Central Administration/PowerShell/Stsadm tool, refer my post: How to Change Site Collection Primary, Secondary Administrators in SharePoint



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 15, 2013

Create SharePoint Quota Templates using PowerShell

SharePoint quota templates enables us to keep the site collections growth in control. It defines the maximum amount of data stored in a site collection and prevent from disk fillings!

Quota templates offer two levels: Warning Level and Maximum Storage Level.Once the site collection reaches warning level, SharePoint triggers an Email to site collection administrators and further addition to site is possible until it reaches to Maximum storage level.

How to Create a New Quota Template in SharePoint 2010
Creating new quota template in SharePoint 2010 is relatively simpler! Go to:
  • Central Administration >> Application Management
  • Click on "Specify quota templates" under "Site Collections" group
  • On the quota templates page click on "Create a new template"
  • Give a Name to your new Quota Template
  • Specify the maximum of storage limit, warning limits of the quota template.
  • Optionally, You can specify the sandboxed code limits
  • Click "OK" to complete creation of new quota template sharepoint 2010 create quota template
PowerShell Script to Create New Quota Template in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to Create New Quota Template
 function CreateQuotaTemplate ($QuotaName, $MaxLevelMB, $WarnLevelMB)
    {
     $quotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
     #Set Quota Name
     $quotaTemplate.Name = $QuotaName
     #Set Maximum & Warning Levels
     $quotaTemplate.StorageMaximumLevel = ($MaxLevelMB*1024)*1024
     $quotaTemplate.StorageWarningLevel = ($WarnLevelMB*1024)*1024
     #Add the Quota Template
     $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
     $contentService.QuotaTemplates.Add($quotaTemplate)
     $contentService.Update()
          
            #Print a Success message
     Write-Host "New Quota Template: $($QuotaName) has been added!"
    }

    #Call the function to Create Quota
    CreateQuotaTemplate –QuotaName "Standard" –MaxLevelMB 250 –WarnLevelMB 200

To Create SharePoint quota template programmatically using C#, Refer: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spquotatemplatecollection.add.aspx

Update a Quota Template:
To update an existing quota template, use this PowerShell script.
Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue

#Target quota Name to update
$QuotaName = "Standard"
$ContentService  =[Microsoft.SharePoint.Administration.SPWebService]::ContentService

#Get the Quota Template
$QuotaTemplate = $ContentService.QuotaTemplates[$QuotaName]

#Rename the Quota Template
$QuotaTemplate.Name = "Standard Plus"

#Increase the Maximum size from 250MB to 350MB
$QuotaTemplate.StorageMaximumLevel = (350*1024)*1024
$ContentService.Update()

Write-Host "Quota Template has been updated!" -f Green

Delete a Quota Template:
#Target quota Name to delete
$QuotaName = "Standard Plus"
$ContentService  =[Microsoft.SharePoint.Administration.SPWebService]::ContentService

#Delete the Quota Template
$ContentService.QuotaTemplates.Delete($QuotaName)
$ContentService.Update() 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, August 11, 2013

SharePoint 2010 Visual Upgrade - FAQs

What is Visual Upgrade in SharePoint 2010?
Lets understand visual upgrade in SharePoint 2010. In short: It's a feature introduced in SharePoint 2010 to ease up transition from MOSS 2007 user interface to SharePoint 2010 UI. When sites migrated from MOSS 2007 using database attach method, They will be using the v3 interface by default and we got to update it.
sharepoint visual upgrade all sites

SharePoint 2010 Visual Upgrade to all Sites:
To apply visual upgrade on a single site, Navigate to:
  • Site Actions >>Site Settings 
  • Click on "Title, Description, and Icon", Choose the Visual Upgrade option to : Update the user interface and click on OK. 
Clicking on "Site Actions >> Visual Upgrade" also will lead to the same URL (/_layouts/prjsetng.aspx)
sharepoint visual upgrade site collection

To visual upgrade entire site collection (all sites):
  • Navigate to Site Actions >> Site Settings 
  • Click on "Visual Upgrade" link under Site collection Administration >> Click on "Upgrade All Sites" button.
    sharepoint 2010 visual upgrade all subsites
SharePoint 2010 visual upgrade all sites with PowerShell: We can apply visual upgrade programmatically with PowerShell. Here is my article on SharePoint 2010 visual upgrade using PowerShell script: Visual upgrade all sites in a site collection

Visual Upgrade options missing?
Remember, its available only on sites migrated/upgraded from SharePoint 2007 and Not for sites created in SharePoint 2010 itself. Also, once sites are upgraded to SharePoint 2010 look and feel, Visual upgrade options will disappear!
sharepoint visual upgrade not available

Also, If you clicked on "Hide Visual Upgrade" button from Site collection administration, that hides visual upgrade options from Site settings menu as well as from "Title, Description, Icon" link under site settings. It removes Visual upgrade notification as well. We can enable it back with PowerShell. By default, Its not available on sites created in SharePoint 2010.

Visual Upgrade Buttons Disabled (Greyed out)?
Its available only on sites migrated/upgraded from SharePoint 2007 and Not for sites created in SharePoint 2010 itself. Both of the buttons "Hide Visual Upgrade" and "Update All Sites"  under Visual Upgrade page (/_layouts/suppux.aspx) disabled in site collections created in SharePoint 2010.
sharepoint visual upgrade grayed out

Hide Visual Upgrade Options
In SharePoint 2010, We can remove visual upgrade options by going to Site Settings >> Visual Upgrade under Site Collection Administration >> Click on "Hide Visual Upgrade" button.

Enable Visual Upgrade Options
If visual upgrade options missing due to any of the reasons discussed above, We can bring it back with PowerShell. Here is how to enable it for single site (subsite or rootsite):
#Get the Web
$Web = Get-SPWeb http://Site-url

#Enable Visual Upgrade
$Web.UIversionConfigurationEnabled=$true
$Web.update() 
                                                                     
To enable Visual Upgrade on Entire Site collection with PowerShell script:
#Get the site collection
$Site = Get-SPsite http://SiteCollection-url

# enable visual upgrade on sites with powershell
foreach($Web in $Site.AllWebs)
  {
    $Web.UIversionConfigurationEnabled=$true
    $Web.update()
  }

Getting access is denied during visual upgrade?
You may get access denied error during visual upgrade when your site collections are locked or Database is in read-only mode. Check database status from SQL Server management studio. To Unlock any site collections, use: Set-SPSite -Identity <Site-collection-url> -LockState Unlock     
Fore more info on site collection locks, refer: Site Collection Locks in SharePoint 2010

Visual Upgrade Rollback
So you upgraded to SharePoint 2010 UI and want to reverse visual upgrade? Sure, We can rollback SharePoint visual upgrade and revert to MOSS 2007 user interface using this PowerShell script.
#Get the site collection
 $Site = Get-SPsite http://SiteCollection-url

 #Enable Visual upgrade on Each site
  foreach($web in $site.AllWebs)
        {          
           $web.UIVersion = 3  #set the UI version to SharePoint 2007 look and feel
           $web.Update()    
        }

How do I Visual  Upgrade All Site Collections using PowerShell:
To convert all SharePoint 2007 sites UI to SharePoint 2010:

Get-SPSite | foreach-object {$_.VisualUpgradeWebs()}

Get Visual Upgrade Status:
To verify SharePoint 2010 sites visual upgrade status, we can get the status for all sites under given site collection with PowerShell:

$site = Get-SPSite http://sitecoll-url

#Get Visual Upgrade Status for all sites
$site.GetVisualReport()  | Format-Table


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 8, 2013

How to Recover Deleted SharePoint Central Admin Site from IIS

SharePoint Central Administration site got deleted from IIS accidentally! It may happen due to file system got corruption errors. No worries, We can Re-provision SharePoint Central admin site! Lets provision SharePoint central administration site using PowerShell.

PowerShell Script to provision SharePoint Central Admin:
Open the "SharePoint 2010 Management Shell" and enter:
New-SPCentralAdministration -Port 2010 -WindowsAuthProvider "NTLM"
This will Re-provision Central Administration site.

For SharePoint 2007, Use PSConfig to Re-Provision Central Administration site:
In case of MOSS 2007, Use Psconfig.exe as:
psconfig.exe -cmd adminvs -provision -port 2010 -windowsauthprovider OnlyUseNTLM
All done, we are back to business.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Configure Replicating Directory Changes in Windows Server 2008 / 2012

Replicating directory changes permission is a requirement to configure User Profile Service Application(UPS) in SharePoint 2010 and for SharePoint 2013. We've to grant replicate directory changes permission on a domain to our service account which crawls and syncs AD contracts to SharePoint.

Here is the step by step instructions to provide "Replicating directory changes" permission to your managed account.
  • Log in to your domain controller,  Open "Active Directory Users and Computers", right-click on your domain and select Delegate Control.
    sharepoint user profile service replicating directory changes
  • Click on "Next"
    sharepoint 2010 user profile synchronization replicating directory changes
  • Click on "Add" to add the managed account
    sharepoint 2010 user profile service replicating directory changes
  • Enter your Service Account and click on "OK"
    sharepoint replicating directory changes
  • Click on "Next"    sharepoint replicating directory changes
  • Select "Create a Custom Task to Delegate", Click Next
    sharepoint replicate directory changes permission
  • Click "This folder, existing objects in this folder, and creation of new objects in this folder" and Click "Next"
    sharepoint 2010 replicate directory changes permission
  • Select "General" and choose "Replicating Directory Changes" Permission. Click Next
  • Click Finish      sharepoint 2010 user profile sync replicate directory changes
That's all! We're done with that, we can start our UPSS and create our connection.In Windows Server 2008 R2 and in Windows Server 2012 also the same procedure applies!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Site Collection Administrators Report for All SharePoint 2007 Sites

I just had to generate a report to find SharePoint site collection administrators and see who are all assigned with Site collection administrator rights on various site collection in entire SharePoint Farm.

Sure, Lets use PowerShell in SharePoint to get site collection administrator programmatically. This script iterates through all site collections in all web applications to list site collection administrators.

PowerShell Script to Get All Site Collection Administrators (I've made it compatible with SharePoint 2007)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Get the Farm
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

#Get All Web Applications
$farmWebServices = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
foreach ($farmWebService in $farmWebServices) {
 #Loop through Each web applicatoin
  foreach ($webApplication in $farmWebService.WebApplications) {
    #Loop through each site collection
    foreach ($site in $webApplication.Sites)
    {
   $Admins=""
   #Get all Site Collection Administrators
      foreach ($siteCollAdmin in $site.RootWeb.SiteAdministrators)
      {
        $Admins+= $siteCollAdmin.LoginName +";"
      }
        Write-Host "Site URL: " $site.RootWeb.Url " - Site Collection Admins: " $Admins "`n"
        $site.Dispose()
    }
  }
}
By the way, It works on SharePoint 2010 and SharePoint 2013 as well.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, August 7, 2013

Fix for SharePoint UserProfileApplicationNotAvailableException_Logging Exception

I was trying to write a PowerShell script to retrieve user profile properties in SharePoint 2013, and ended up with the below error:

"UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have c4a5371c-01c2-4281-b91b-ca335982f994"
SharePoint UserProfileApplicationNotAvailableException_Logging Exception

Solution:
After verifying user profile service application and SharePoint timer jobs are up and running, arrived to the right destination: User profile service application permissions! Grant "Full Control" permission to the account running the code on User profile Service application.
  1. Open SharePoint Central Administration site.
  2. Go to: Application Management >> Service Applications >> Manage service applications.
  3. Pick your user profile service application. Now, from the ribbon, click on Permissions button.
  4. Add your account to the permissions. (Make sure: Farm Admin account also added)
  5. Enable Full Control for your account and Click OK.
That's all. Try restarting the IDE and the error should gone now!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, August 6, 2013

SharePoint Site Collection Storage Size - Quota Usage Report using PowerShell

Requirement: Wanted to get a quick storage quota report on SharePoint sites on their allocation vs used space metrics to find out underutilized sites.

Solution: PowerShell script to get SharePoint site quota report!
If you want to get used storage space for a particular site collection, use:
Get-SPSite http://site-collection=url | select @{label="Size in MB";Expression={$_.usage.storage/1MB}}
To get storage data for all site collections, use:
Get-SPSite | Select Url, @{Label="Size";Expression={$_.usage.Storage/1MB}} | Sort-Object -Descending -Property "Size"
sharepoint powershell get site collection size

Get Site collection Storage assigned vs used for all site collections:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Get-SPSite | Select URL,`
      @{Name="Site Owner"; Expression={$_.Owner.Email}},`
      @{Name="Quota Assigned"; Expression={"{0:N2} MB" -f ($_.Quota.StorageMaximumLevel/1MB)} } ,`
      @{Name="Storage Used"; Expression={"{0:N2} MB" -f ($_.Usage.Storage/1MB)}},`
   @{Name="Percentage Used"; Expression={"{0:P2}" -f (   ($_.Usage.Storage/1MB) / ($_.Quota.StorageMaximumLevel/1MB ))}}`
   | Out-GridView -Title " Quota Report"

Report Output:
SharePoint Site Collection Quota Usage Report
Note that the "Infinity" has occurred on sites with No quota assigned!

Here is an another script to generate Storage Quota report:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all available Quota Templates
$QuotaTemplates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.QuotaTemplates 
$QuotaHash=@{} #Hash Array to Hold: Quota ID & Name
$QuotaTemplates | ForEach-Object { $QuotaHash.Add($_.QuotaID, $_.Name) } 

#Get All Site collections Quota
Get-SPWebApplication | Get-SPSite -Limit "All" |  ForEach-Object { Write-host $_.RootWeb.URL". Quota Assigned : "  $QuotaHash.Get_Item($_.Quota.QuotaID) }


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Run SharePoint 2010 Timer Jobs On-Demand with PowerShell

We may have to run SharePoint timer jobs on-demand in some situations. Say for e.g. To update Rating values, I had to run the timer jobs: User Profile Service Application - Social Rating Synchronization Job and User Profile Service Application - Social Data Maintenance Job. Read more at SharePoint 2010 Rating Feature Configuration

How to run timer job manually in SharePoint 2010
So, To run a SharePoint 2010 timer Jobs on-demand, we used to navigate to Central Administration >> Monitoring >> Timer Jobs >> Review Job Definition >> Pick the timer jobs we want to run >> Click on "Run Now", BTW SharePoint 2007 doesn't offer way to run timer job manually!
how to run timer job manually in sharepoint 2010
This will run timer job immediately in SharePoint 2010.

SharePoint 2010 run timer job from PowerShell:
We can run timer job from code.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Display name of the Timer Job to Run on-demand
$TimerJobName = "User Profile SA - Social Rating Synchronization Job" 

#Get the Timer Job 
$TimerJob = Get-SPTimerJob | where { $_.DisplayName -match $TimerJobName}

#start the timer job
Start-SPTimerJob $TimerJob

#Or use this One-liner:
#Get-SPTimerJob | where { $_.DisplayName -match "User Profile SA - Social Rating Synchronization Job"} | Start-SPTimerJob

I've used display name here, which various based on your installation. You can also use "Name" attribute, like:
$TimerJob = Get-SPTimerJob | where { $_.Name -eq "User Profile Service_SocialRatingSyncJob" } 

Run SharePoint 2010 timer job programmatically with PowerShell:
In some other cases, you may have a timer job associated with multiple web applications and want to run a particular web app's timer job:
#Display name of the Timer Job to Run on-demand
$TimerJobName = "Workflow Auto Cleanup" 

#Get the Web Application
$WebApp = Get-SPWebApplication "http://sharepoint.crescent.com"

#Get the Timer Job associated with the given web application
$TimerJob = Get-SPTimerJob | where { $_.DisplayName -match $TimerJobName} | where {$_.Parent -eq $WebApp }

#start the timer job
Start-SPTimerJob $TimerJob

How to run SharePoint 2007 Timer job on-demand?
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")  
[void][reflection.assembly]::LoadwithPartialName("Microsoft.Office.Server")

Function global:Get-SPWebApplication($WebAppURL)
{
 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}
#Get the web application
$WebApp = Get-SPWebApplication "https://sharepoint.crescent.com"

foreach ($TimerJob in $WebApp.JobDefinitions)
{
 if($TimerJob.Title -eq "Profile Synchronization")
 {
    $TimerJob.Execute([guid]::Empty)
 }
}
Please note, This doesn't update "LastRun" time!

Using STSADM  to run timer jobs on demand:
You can use "STSADM" to change the timer job schedule and make them run immediately:
E.g. Lets get "Recycle bin cleanup" timer job schedule.

stsadm -o getproperty -propertyname "job-recycle-bin-cleanup" -url "http://your-sharepoint-webpapp"

This should return the output as:
<Property Exist="Yes" Value="daily between 22:00:00 and 06:00:00" />

We can change the schedule
stsadm -o setproperty -propertyname "job-recycle-bin-cleanup" -url "http://your-sharepoint-webpapp" -propertyvalue "Every 1 minutes between 0 and 59"

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, August 5, 2013

Enable-Activate a SharePoint Feature on All Site Collections using PowerShell

Ever wanted to enable a feature on all site collections in a SharePoint environment? Well, To activate a site collection feature in SharePoint, navigate to Site settings >> Site Collection Features >> Click on "Activate" next to the relevant feature.
How to activate a feature in SharePoint
How to Activate a Feature using PowerShell?
To activate a SharePoint feature on a particular site, we use: Enable-SPFeature cmdlet.
Enable-SPFeature –Identity "FeatureName" –url http://SharePoint-site-URL  
Recently I had to enable a Branding feature on all sites to apply new corporate branding with the following one liner: PowerShell script.
#activate feature on all sites in all web applications in the farm
Get-SPWebApplication | Get-SPSite -Limit ALL | ForEach-Object{ Enable-SPFeature -URL $_.url -Identity (Feature Name or URL) -Confirm:$FALSE } 

Here is the E.g. for above script:
Get-SPWebApplication "http://www.sharepoint.crescent.com" | Get-SPSite -Limit All | Get-SPWeb -Limit ALL | ForEach-Object { Enable-SPFeature  "fead7313-ae6d-45dd-8260-13b563cb4c71" } -Url $_.Url
Here the PowerShell script gets all sites under the web application and activates the feature.

To get the Feature GUID you can use:
Get-SPFeature | Where {$_.DisplayName -eq "FeatureName"} | Select ID
In total, The below script iterates through all web applications, site collections, checks whether the feature is already activated. If not, enables feature on all sites .
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all Site collections
$SiteColl = Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite -Limit All 
#Target Feature to Activate
$FeatureToActivate = Get-SPFeature | Where {$_.DisplayName -eq "FeatureName"} 

#Iterate through each site collection
ForEach($Site in $SiteColl)
{
  #Check if Feature is already activated
  $FeatureActivated = Get-SPFeature -site $site | Where {$_.displayname -eq $FeatureToActivate.DisplayName}
 
  if ($FeatureActivated -ne $null)
    {
  Write-Host "Feature already activated at: "$site.Url
 }
  else
 {
  #Activate the feature
  Enable-SPFeature -Identity $FeatureToActivate -URL $Site.URL -Confirm:$False
  Write-Host "Activated Feature on "$site.Url
 }
} 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Create/Delete SharePoint Groups Programmatically with PowerShell

These PowerShell code snippets helps to Create or Delete SharePoint Groups programmatically using PowerShell:

Create SharePoint Group Programmatically with PowerShell:
Use this function to create a SharePoint group using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Create-SPGroup($SiteURL, $GroupName, $GroupOwner,$GroupDescription)
{
 <#
  .Description
  This PowerShell function Creates new SharePoint Group  on the given site collection URL
 .Example
  Create-SPGroup "http://sharepoint.crescent.com/sites/operations" "Operation Managers" "Global\salaudeen" "Group for Operation Managers"
  This example Creates new SharePoint group "Operation Managers" at the given site collection 
 .Link
  http://www.sharepointdiary.com
  http://twitter.com/SharePointdiary
 .Inputs
  $SiteURL - Site collection URL in which the group to be created
  $GroupName - Name of the Group to be create
  $GroupOwner - Existing user account, By default only Group owner can edit members of the group
  $GroupDescription - Descriptive text for the group
 .Outputs
  Gives message on the screen on Group Creation/Failure
 #>
 
 #Get the RootWeb
 $web = Get-SPWeb $SiteURL

 #Get Group Owner
 $GroupOwner = Get-SPUser -Identity $GroupOwner -Web $web

 #if the group doesn't exists already
  if($Web.SiteGroups[$GroupName] -eq $null)
   {
   #create sharepoint user group programmatically
   $web.SiteGroups.Add( $GroupName, $GroupOwner, $GroupOwner, $GroupDescription)

   #Get the Group
   $NewGroup = $Web.SiteGroups[$GroupName]

   #Set Group Properties
   #$NewGroup.AllowMembersEditMembership = $true
    
   #Assign Permissions to the Group
   $GroupAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($NewGroup)

   #Get Full Control Role (Permission Level)
   $GroupRoleDefinition = $web.Site.RootWeb.RoleDefinitions["Full Control"]

   #Bind Full Control
   $GroupAssignment.RoleDefinitionBindings.Add($GroupRoleDefinition)

   #Grant Full control to the Web
   $web.RoleAssignments.Add($GroupAssignment)
   $web.Update()
   
   Write-Host "New Group Created!"
  }
  else
  {
   Write-Host "Group already Exists!"
  }
 $web.Dispose()
 }

#Call the function to create a SharePoint user group programmatically
Create-SPGroup "http://sharepoint.crescent.com/sites/operations" "Operation Managers" "Global\Salaudeen" "Group for Operation Managers"

Delete SharePoint Group Programmatically with PowerShell:
And to delete an existing SharePoint group programmatically, the PowerShell code goes like:
Function Delete-SPGroup($SiteURL, $GroupName)
{
 <#
  .Description
  This PowerShell function Deletes an existing SharePoint Group on the given site collection URL
 .Example
  Delete-SPGroup "http://sharepoint.crescent.com/sites/operations" "Operation Managers"
  This example deletes SharePoint group "Operation Managers" at the given site collection 
 .Link
  http://www.sharepointdiary.com
 .Inputs
  $SiteURL - Site collection URL in which the group to be created
  $GroupName - Name of the Group to be create
 .Outputs
  Gives message on the screen on Group Deletion/Failure
 #>
 
 #Get the RootWeb
 $web = Get-SPWeb $SiteURL

 #if the group exists 
  if($Web.SiteGroups[$GroupName] -ne $null)
   {
                        #remove sharepoint group using powershell 
                        $web.SiteGroups.Remove($GroupName)
                        $web.Update()
   
          Write-Host "Group Deleted!"
  }
  else
  {
   Write-Host "Group doesn't Exists!"
  }
 $web.Dispose()
 }

#Call the function to delete sharepoint groups using powershell
Delete-SPGroup "http://sharepoint.crescent.com/sites/operations" "Operation Managers"
To add users to SharePoint group programmatically, refer my another post: How to Add User To SharePoint Site Group Programmatically

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, August 4, 2013

"Internet Explorer cannot display the webpage" on Accessing SharePoint Central Admin

Problem: SharePoint 2010 central administration site stopped working after a reboot and gave "Internet Explorer cannot display the webpage" on trying to access!
sharepoint 2010 central administration internet explorer cannot display the webpage

Troubleshooting:
SharePoint central admin page cannot displayed error could be caused since Central Administration service is in disabled state! Lets troubleshoot by checking Central Administration service status with PowerShell:
$CA = Get-SPServiceInstance | Where-Object {$_.TypeName -eq `Central Administration'}
write-host $CA.status 

Got "Disabled" as Central Administration Service Status! No issues, Lets start the service:
Get-SPServiceInstance | Where-Object {$_.TypeName –eq ‘Central Administration’} |  Start-SPServiceInstance -Confirm
 
Wait till it comes to "Online" Status. That's all! We've fixed SharePoint 2010 central administration page cannot be displayed issue.
sharepoint central administration cannot display webpage



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


PowerShell Scripts to Manage Choice Field in SharePoint

Here are some nifty PowerShell scripts to manage choice field in SharePoint.

How to Add New Choice Field to SharePoint List using PowerShell
Lets use PowerShell to create choice column:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Define URL and List name variables 
$WebURL="http://sharepoint.crescent.com"
$ListName ="Employee Profiles"

#Get the Web and Lists objects
$web = Get-SPWeb $WebURL
$List = $web.Lists[$ListName]

#Add New choice field to the list
$list.Fields.Add("Department", [Microsoft.SharePoint.SPFieldType]::Choice, $false)

#Add Choices to the field
$ChoiceField = $list.Fields.GetField("Department") #Get the field
$ChoiceField.Choices.Add("Sales")
$ChoiceField.Choices.Add("Marketing")

#Commit changes
$ChoiceField.update()

SharePoint PowerShell add value to choice column
Choices can be added from array's also.
$ChoiceField = $list.Fields.GetField("Department") #Get the field
#Add in bulk - Array as Choices
$ChoicesArray = @("Marketing","Production","Operations","HR","IT")
$ChoiceField.choices.addrange($ChoicesArray)

#Commit changes
$ChoiceField.update()

PowerShell to create choice column - Multi-Choice Field (Checkboxes)
#Choices for the column
$Choices = New-Object System.Collections.Specialized.StringCollection;
$Choices.Add("Sales")
$Choices.Add("Purchase")
$Choices.Add("Operations")

#Add Multichoice field
$list.Fields.Add("Department",[Microsoft.SharePoint.SPFieldType]::MultiChoice,$False,$False,$Choices)
New fields added to SharePoint lists will not be included in default view by default! You have to add them explicitly.

Remove choices from the choice field:
#Get the choice field
$ChoiceField = $list.Fields.GetField("Department")

#Remove a Choice from the column
$ChoiceField.Choices.Remove("Sales")
#To remove all choices, use: 
#$ChoiceField.Choices.Clear()

#Commit changes to update choice column
$ChoiceField.update()

Set choice fields settings:
We've added the choice field. Now, we can configure choice field settings via PowerShell.
#Get the Web and Lists objects
$web = Get-SPWeb $WebURL
$List = $web.Lists[$ListName]

#Get the choice field
$ChoiceField = $list.Fields.GetField("Department")

#Required Field?
$ChoiceField.Required = $true
#Set Default value
$ChoiceField.DefaultValue = "Operations"
#Allow Fill-in Choices
$ChoiceField.FillInChoice = $false
#Field format: such as radio button, drop down list
$ChoiceField.EditFormat = "RadioButtons"

#Commit changes
$ChoiceField.update()
You may get error when the column is "Sealed". Set it to "False" to perform any of the change/delete operations.

Get choice field value:
#Define URL and List name variables 
$WebURL="http://sharepoint.crescent.com/"
$ListName ="user Info"

#Get the 1st item stored in the list
$Item = $list.items[0]

#Get the formatted value of "Department" choice column
Write-host "Choice Field Value:" $item.GetFormattedValue("Department")

Set choice field values:
SharePoint 2010 PowerShell script to add value to choice column 
#Define URL and List name variables 
$WebURL="http://sharepoint.brightpoint.com/sites/Operations/"
$ListName ="List Versions"

#Get the Web and Lists objects
$web = Get-SPWeb $WebURL
$List = $web.Lists[$ListName]

#Add new Get the 1st item stored in the list
$Item = $list.AddItem()
$item["Title"] = "Test001" #Set Mandatory title field
#sharepoint 2010 powershell update choice field
$item["Department"] = "Sales"
$item.Update(

Set Multi-choice field value:
#Add new Get the 1st item stored in the list
$Item = $list.AddItem()
$item["Title"] = "Test009"

#Set Choice values
$choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue
$choicevalues.Add("Sales")            
$choicevalues.Add("Purchase")    

$list.Fields["Department"].ParseAndSetValue($item,$choicevalues)

#Commit changes
$item.Update()
To check if a choice field is a multiple choice, use:  SPField.FieldValueType.Name -eq "SPFieldMultiChoiceValue"

for all supported properties of choice field in SharePoint, refer SPFieldChoice reference in MSDN


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 1, 2013

Apply SharePoint Quota Template Changes to Existing Sites

Problem Scenario: 
End-users actively started using their "My Sites" and most of their My sites reached the site collection storage quota limit of 100MB! Gradually started receiving many requests to increase storage limits.

Initially, My site web application assigned with "Personal" quota template which offers 100MB of disk space. After a while, we decided to increase my site storage quota limit to 250MB. So, went to Central Administration >> Application Management >> Specify Quota Templates >> Selected "Personal" Quota template and set that storage limit to 250MB.
sharepoint 2010 personal site quota template
That's enough! This should fix the problem, isn't it? Unfortunately NO! Users still receiving "Your changes could not be saved because this SharePoint Web site has exceeded the storage quota limit." error while trying to upload a file or add new item to their SharePoint site.
Your changes could not be saved because this SharePoint Web site has exceeded the storage quota limit.
Went to Central Administration, Verified again that Site collections has enough space to accommodate new items.
sharepoint 2010 quota template powershell
In short: Even if you increase a quota template's limits, it won't reflect on site collections which are already using that quota!
Fix: 
Updating an existing SharePoint site quota template's quota limits will not automatically increase the quota limits for the site collections which are already using that particular quota. Site collections which are using the particular quota still be showing old quota values. So, the fix is: Switch the Quota template of the site collection to some thing else and then switch it back to its original quota.
Here is how: Go to
  • Central Administration >> Application Management 
  • Click on "Configure Quotas and locks" under site collections group 
  • Change the site collection's quota template to a different quota template (In my case its "Starter"). Click OK to save changes. 
  • Now, go back to Configure Quotas and locks and specify the old template ("Personal" in my case!) again. Click "OK" to save the changes.

That's all! Problem solved? Yes, kind of! but are we going to do the same for our 100+ site collections? May be, depends on your time! but sounds like a bad idea!! So, Lets use PowerShell to automate this. 

PowerShell Script to Apply Quota Change:
Lets use PowerShell to apply SharePoint 2010 quota template changes.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 #Define the parameter values: My Site Web App URL, Quota Template Names
        $WebAppURL = "http://mysite.crescent.com/"
        $MySiteQuota = "Personal Site"
 $TempQuota = "Starter"
 
 Start-SPAssignment -Global
 
 #Get the Quota Templates 
 $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
 $MySiteQuotaTemplate = $contentService.QuotaTemplates[$MySiteQuota]
 $TempQuotaTemplate = $contentService.QuotaTemplates[$TempQuota]

 #Get all site collections
  $Sites = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All 

 #Loop through all sites and Swap the Quota Templates
 foreach($site in $Sites)
 {
     if($site.Quota.QuotaID -eq $MySiteQuotaTemplate.QuotaID)
      {
    #Set new Quota Template
       $site.Quota = $TempQuotaTemplate 
    #Revert to Original Quota Template
    $site.Quota = $MySiteQuotaTemplate
    
       #Print a message
    Write-host "Quota changes applied to : $($site.RootWeb.URL)!"
 
   }
 }
    
 Stop-SPAssignment -Global


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...