sharepointking

Just another WordPress.com site

Monthly Archives: July 2011

Change Modified By/Created By columne value in whole site – SharePoint 2010

Change user name in created/modified by column in all the list/library in site with appropriate user name using powershell in sharepoint 2010:

#Get the SharePoint Assembly
# You will need to run this on the SharePoint Server

[Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

# The site my list was in was at http://demoserver
# create a new object called $SPSite

$SPSite = New-Object Microsoft.SharePoint.SPSite(“https://www.myserver.com/entis/build1/sitename/subsite/”)

# Make sure you have the last “/” in the url on the site
# allow $SPWeb to be the OpenWeb from the site

$SPWeb = $SPSite.OpenWeb()

# Get the list ModifyCreatedBy

#$SPList = $SPWeb.Lists[“Shared Documents”]

# Get the Collection of the List Items

#$SPListItemCollection = $SPList.Items

# iterate the Collection

[Microsoft.SharePoint.SPListCollection] $lists = $SPWeb.Lists

# iterate the list and libraries
#[Microsoft.SharePoint.SPList] $list = $null

[int] $iList = 0

for( $iList=0; $iList -lt $lists.Count; $iList++)
{

$SPList = $lists[$iList]
$SPListItemCollection = $SPList.Items

Write-Host $SPList

# iterate the Collection

foreach ($ListItem in $SPListItemCollection)
{

# The user in this case was Test R. Test and had a user id of 8 from the SPWeb users
#

#$SPFieldUserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($SPWeb,1,”#Vaibhav, Jain”)
#$SPFieldUserValuereplacewith = New-Object Microsoft.SharePoint.SPFieldUserValue($SPWeb,10, “#Rink, Jain”)

#$ListItem[“Author”] = $SPFieldUserValue
$SPFieldUserValueOriginalCreatedby = $ListItem[“Author”]
$SPFieldUserValueOriginalModifiedby = $ListItem[“Editor”]

if ($SPFieldUserValueOriginalCreatedby -eq “18;#Name, Surname” -or $SPFieldUserValueOriginalModifiedby -eq “18;#Name, Surname”)
{
Write-Host $SPFieldUserValueOriginalCreatedby
Write-Host $SPFieldUserValueOriginalModifiedby

if ($SPFieldUserValueOriginalCreatedby -eq “18;#Name, Surname”)
# “ID,#User Name” – ID from –>http://server/sites/EMEA1/_layouts/userdisp.aspx?ID=18
{
$ListItem[“Author”] = “69;#Vaibhav, jain”
Write-Host “found created by”

}else
{
$ListItem[“Author”]=$ListItem[“Author”]
}

# Note: Editor will be the account that you are running the Powershell under unless you update # Editor as well
# $ListItem[“Editor”] = $SPFieldUserValuereplacewith
if ($SPFieldUserValueOriginalModifiedby -eq “18;#Name, Surname”)
{
$ListItem[“Editor”] = “69;#Vaibhav, Jain”
Write-Host “found Modified by”
}else
{
$ListItem[“Editor”]=$ListItem[“Editor”]
}
$ListItem.Update()

}

}
}

$SPWeb.Update()

# Still TODO Disposes, Error Checking, Change to take Parameters, etc

Add Bulk user using powershell script – sharepoint 2010

$0 = $MyInvocation.MyCommand.Definition # Get complete file path (eg: D:\VJESPMasterScript\VJESPMaster.ps1)
$dp0 = [System.IO.Path]::GetDirectoryName($0) # Get current Directory file path (eg: D:\VJESPMasterScript)
$bits = Get-Item $dp0 | Split-Path -Parent # Get current Drive (eg: D:\)

## Start logging
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile = “$dp0\AF.rtf”

## check to ensure Microsoft.SharePoint.PowerShell is loaded if not using the SharePoint Management Shell
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
if ($snapin -eq $null)
{
Write-Host “Loading SharePoint Powershell Snapin…”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}

#This takes care of the disposable objects to prevent memory leak.
Start-Transcript $logfile

New-SPUser -UserAlias “domain\trial5535” -web “https://www.mysharepointserver.com/managedpath/collection/site” -Group “Interim Site Owners”

New-SPUser -UserAlias “domain\tryenr1” -web “https://www.mysharepointserver.com/managedpath/collection/site” -Group “Interim Site Owners”

Stop-Transcript