Thursday, 19 April 2012

Set Site Collection Owner For All Sites...

# set site collection owner for all sites...
# 1-2012 Jack
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# $AccountList is an array of Windows Identities in the format of $AccountList = @("DOMAIN\USERID" , "DOMAIN\USERID2")
$AccountList = @("LAB\Jack", "Lab\tom", "Lab\dick", "lab\harry")
# $iisSiteList is an array of top level IIS site URLs
#this gets an array of objects representing the sites at the IIS level:
## no longer needed.... $IISSites = Get-SPWebApplication
Foreach($oneIISSite in $IISSiteList)
{
  #using .Sites, we can get a list of the site collections
  #so really what were saying is for each SharepointSiteCollection
  #this code is altered a bit, since we're using an array of top level site names.
  # we need to use (Get-SPWebApplication $oneIISSite).Sites
  # which is the same as $sitelist = Get-SPWebApplication $oneIISSite
  #                      $sitelist.sites
  foreach ($SharepointSiteCollection in (Get-SPWebApplication $oneIISSite).Sites)
  {
       write-host $SharepointSiteCollection.url -ForegroundColor Cyan
       $spweb = Get-SPWeb $SharepointSiteCollection.url
       #now we have the website, so lets look at each account in our array
       foreach ($Account in $AccountList)
       {
           #lets see if the user already exists
           Write-host "Looking to see if User " $account " is a member on " $SharepointSiteCollection.url -foregroundcolor Blue
           $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url -ErrorAction SilentlyContinue #This will throw an error if the user does not exist
           if ($user -eq $null)
           { #if the user did NOT exist, then we will add them here.
               $SPWeb.ALLUsers.ADD($Account, "", "", "Added by AdminScript")
               $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url
                Write-host "Added user $Account to URL $SPWeb.URL" -Foregroundcolor Magenta
           }
            else
           {
                Write-host -ForegroundColor DarkGreen "user $Account was already in URL " $SPWeb.URL
           }
           if ($user.IsSiteAdmin -ne $true)
           {
             $user.IsSiteAdmin = $true
             $user.Update()
             Write-host "$account has been made an admin on $SPWeb.URL" -Foregroundcolor Magenta
           }
           else
           {
             Write-host -ForegroundColor DarkGreen "$account was already an admin on $SPWeb.URL"
           }
       }
     $SharepointSiteCollection.Dispose()
  }
 }

Set Site collection Owner For All Sites...

# set site collection owner for all sites...
# 4-2012 SharePoint Planet
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# $AccountList is an array of Windows Identities in the format of $AccountList = @("DOMAIN\USERID" , "DOMAIN\USERID2")
$AccountList = @("NA\rpolin")
# $iisSiteList is an array of top level IIS site URLs
$iisSiteList = @("http://zz", "http:///xx", "http://yy/")
#this gets an array of objects representing the sites at the IIS level:
## no longer needed.... $IISSites = Get-SPWebApplication
Foreach($oneIISSite in $IISSiteList)
{
  #using .Sites, we can get a list of the site collections
  #so really what were saying is for each SharepointSiteCollection
  #this code is altered a bit, since we're using an array of top level site names.
  # we need to use (Get-SPWebApplication $oneIISSite).Sites
  # which is the same as $sitelist = Get-SPWebApplication $oneIISSite
  #                      $sitelist.sites
  
foreach ($SharepointSiteCollection in (Get-SPWebApplication $oneIISSite).Sites)
  {
       write-host $SharepointSiteCollection.url -ForegroundColor Cyan
       $spweb = Get-SPWeb $SharepointSiteCollection.url
       #now we have the website, so lets look at each account in our array
       foreach ($Account in $AccountList)
       {
           #lets see if the user already exists
           Write-host "Looking to see if User " $account " is a member on " $SharepointSiteCollection.url -foregroundcolor Blue
           $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url -ErrorAction SilentlyContinue #This will throw an error if the user does not exist
           if ($user -eq $null)
           { #if the user did NOT exist, then we will add them here.
               $SPWeb.ALLUsers.ADD($Account, "", "", "Added by AdminScript")
               $user = Get-SPUSER -identity $Account -web $SharepointSiteCollection.url
                Write-host "Added user $Account to URL $SPWeb.URL" -Foregroundcolor Magenta
           }
            else
           {
                Write-host -ForegroundColor DarkGreen "user $Account was already in URL " $SPWeb.URL
           }
           if ($user.IsSiteAdmin -ne $true)
           {
             $user.IsSiteAdmin = $true
             $user.Update()
             Write-host "$account has been made an admin on $SPWeb.URL" -Foregroundcolor Magenta
           }
           else
           {
             Write-host -ForegroundColor DarkGreen "$account was already an admin on $SPWeb.URL"
           }
       }
     $SharepointSiteCollection.Dispose()
  }
 }
Paste the above code in notepad and save it with .PS1 extension
and then run powershell as administrator
and run the file.

SharePoint 2010 Migration:

SharePoint 2010 Migration:

We have three methods of migration process. Here I want to describe the Data Base migration approach.
 It’s simple and easy way of doing.

Pre- Migration Tasks:
SharePoint 2007 server farm:
1.       Run Pre-upgrade check on SharePoint 2007 server farm
Use Stsadm tool.
Command:

2.       This will give the complete server farm health details , including custom web parts, solutions, themes, templates.. etc  
3.       Fix the errors and run pre-upgrade check again until it get succeeded with any errors and warnings.(some warning you can ignore of course J.)
4.       Take Backup of the content DB which you would like to migrate.
SharePoint 2010 Server farm:

1.       Built SharePoint 2010 server farm ,I mean, Plan Server farm and  install SharePoint on all servers.
2.       Restore Content DB which would taken backup in SharePoint 2007.
3.       Run the one upgrade check command using Power Shell tool.
Command: Test –< Content Db name>

4.       Create a web application in SP 2010.(Note: Do not create site collection.)
5.       Attach (Mount) content db to the newly created web application.(Three ways to do this. 1. Power Shell 2. while creating Web app 3. From CA)
I prefer Powershell one.
                Command: Mount - <content db name> <Db server> -<web app path>
6.       It will do the migration for us. Open the web app once upgrade is completed.
7.       Check the upgrade log and fix the errors you get any .
8.       Do the unit testing on migrated 2010 portal.  

If you any one more in depth , please contact me , I can guide/help you Enjoy SharePoint J