Sunday, February 9, 2014

Powershell cmds Add/Install/Update/Remove/Backup/Restore/Export and Import


Add solution
-------------
Add-SPSolution "c:\code\bin\debug\SharePointProject2.wsp"

install for one webapplication
------
Install-SPSolution –Identity SharePointProject2.wsp –WebApplication "http://sp2010" -GACDeployment


install for all webapplications
---------
Install-SPSolution -Identity SharePointProject2.wsp -AllWebApplications -GACDeployment


update
------
Update-SPSolution –Identity SharePointProject2.wsp –LiteralPath c:\code\SharePointProject2.wsp –GACDeployment

un-install
----------
Uninstall-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010

Uninstall-SPSolution -identity SharePointProject2.wsp  -allwebapplications -Confirm:$false

remove
-------
Remove-SPSolution –Identity SharePointProject2.wsp

Backup site collection
------
Backup-SPSite –identity "http://domainName:2711" –path "C:\BackupFolder\mybackup.bak" -NoSiteLock

Restore site collection
--------------
Restore-SPSite –identity "http://domainName:2711" –path "C:\BackupFolder\mybackup.bak" –force


Restore-SPSite -Identity http://singhealthapps/sites/apims_dashboard -Path D:\Deployments\SHIntranet\2015\APR\14\Deployments\apimsbak\apims.bak -Verbose -DatabaseName WSS_Content_DBName
 
change user emailID using powershell
---------------
Set-SPUser -Identity ‘ISUZU03\keysuggestor1’ –Web http://isuzu03 –Email "siva.sankar@xx.com"

Export sitecollection using powershell cmd

Export-SPWeb http://siteurl/ -Path "D:\venkat\LAB.bak" -IncludeUserSecurity

Import sitecollection using powershell cmd

Import-SPWeb –Identity http://Siteurl/ -Path "D:\venkat\LAB.bak" -IncludeUserSecurity

if the bak file is more than 25 mb then import cmd gives error. In that case we need to compressionsize perameter to takecare abt that.

Export-SPWeb http://mysite -Path c:\backup\ExportFile -CompressionSize 1000 -IncludeUserSecurity

Reference:
http://webborg.blogspot.sg/2008/01/find-cexportsettingsxml-error-when.html

Saturday, February 1, 2014

Export SharePoint Users and Groups to Excel using PowerShell

Requirement: Export SharePoint Users and Groups to Excel for analyzing SharePoint Groups and Users along with their Account Name, E-mails!We can export SharePoint User Group to excel using PowerShell. Here is how:

PowerShell Script to Export Users & Groups:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 
#Using Get-SPSite in MOSS 2007
function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }
 
function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();      
            }
    return $web
}
 
  
     $site = Get-SPSite $URL
    
     #Write the Header to "Tab Separated Text File"
        "Site Name`t  URL `t Group Name `t User Account `t User Name `t E-Mail" | out-file "d:\UsersandGroupsRpt.txt"
         
     #Iterate through all Webs
      foreach ($web in $site.AllWebs)
      {
        #Write the Header to "Tab Separated Text File"
        "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "d:\UsersandGroupsRpt.txt" -append
         #Get all Groups and Iterate through   
         foreach ($group in $Web.groups)
         {
                "`t  `t $($Group.Name) `t   `t `t " | out-file "d:\UsersandGroupsRpt.txt" -append
                #Iterate through Each User in the group
                       foreach ($user in $group.users)
                        {
                           #Exclude Built-in User Accounts
                    if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
                    {
                                "`t  `t  `t  $($user.LoginName)  `t  $($user.name) `t  $($user.Email)" | out-file "d:\UsersandGroupsRpt.txt" -append
                             }
                        }
         }
       }
    write-host "Report Generated at d:\UsersandGroupsRpt.txt"

This script will Export SharePoint user group to excel. Here is the report output:
Export SharePoint Users and Groups to Excel using PowerShell
  
PowerShell script to Get All Groups and Members of Each group:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 
#Using Get-SPSite in MOSS 2007
function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }
 
function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
        
            }
    return $web
}
 
  
     $site = Get-SPSite $URL
      
     if (Get-SPWeb($url).HasUniqueRoleAssignments -eq $true)
     {
        $Web=Get-SPWeb($url)
     }
     else
     {
        $web= $site.RootWeb
     }
 
     #Get all Groups and Iterate through   
     foreach ($group in $Web.sitegroups)
     {
        write-host " Group Name: "$group.name "`n---------------------------`n"
            #Iterate through Each User in the group
                   foreach ($user in $group.users)
                    {
                        write-host $user.name  "`t" $user.LoginName  "`t"  $user.Email  | FT
                    }
     write-host "=================================="  #Group Separator
     }

How to Get members of a particular group in SharePoint 2007 using PowerShell:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 
#Using Get-SPSite in MOSS 2007
 
function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }
 
Function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb() 
            }
    return $web
}
 
 
     $site = Get-SPSite $URL
     $web= $site.OpenWeb() 
 
     #Get the Group by its name
     $Group = $Web.sitegroups | Where-Object {$_.Name -eq "CSA Test All Entity Users"}
   
            #Iterate through Each User in the group
                   foreach ($user in $group.users)
                    {
                        write-host $user.name  "`t" $user.LoginName "`t"  $user.Email
 
                    }
Its also possible to read user properties from User Profile.

PowerShell script to read user Profile Properties: 
?
1
2
3
4
5
6
#Get Profile Properties from User Profile
$ServerContext=[Microsoft.Office.Server.ServerContext]::GetContext($site)
 $UPM = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext)
 $UserProfile=$upm.GetUserProfile($user.LoginName )
 $Title=$UserProfile["Title"].Value
 $Department=$UserProfile["Department"].Value

Related Posts:


Reference:

http://www.sharepointdiary.com/2013/07/export-sharepoint-users-and-groups-to-excel-using-powershell.html

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...