Showing posts with label SharePoint Foundation 2013. Show all posts
Showing posts with label SharePoint Foundation 2013. Show all posts

Friday, July 24, 2020

powershell update Peoplepicker in List In SHarePoint

#Read the CSV file 
#stored local variable 
$delimitercsv = "|" 
$filePath = "C:\peakfinders.csv" 
$userid = "EmpID"
$useremailowner = "Owner"

#Get the SharePoint List
$tWeb = Get-SPWeb -identity "http://sharepoint.peakfinders.com" 
$list = $tWeb.Lists["Employee"]
$CSVData = Import-CSV -path $filepath | ForEach-Object {
    Write-Host "$($_.ID) ,$($_.'Email-Address')";
foreach($sitem in $items)
{

$userid = $sitem['EmpID']
if($userid.LookUPid -eq $($_.ID)){
$sitem["mail"] =$($_.'Email-Address');
$sitem.Update()
}
}
}

Friday, February 12, 2016

When we get retrive People or Group field returning semicolon hash then Name

1;#Deepak Kumar


Get User name:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupValue;


Get User ID:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupId;

Using Split fuction:

properties.ListItem["Staff Member"].ToString();

You are going to be returned their userID and username, so it will always be returned separated by ;#.



properties.ListItem["Staff Member"].ToString().split(";#")[1];

Friday, January 29, 2016

Get all the site collection with content DB details using powershell commands

Get sites and content DB details using following power shell command

$rootSite=New-Object Microsoft.SharePoint.SPSite("http://weburl")
$spWebApp = $rootSite.WebApplication 
foreach($site in $spWebApp.Sites) {
    
    write-output "$($site.RootWeb.Url) - $($site.ContentDatabase)"     
  
    $site.Dispose() 

Wednesday, December 9, 2015

Creating User Profile Services using Powershell commands in SharePoint foundation 2013

$ver = $host | select version
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Load Functions

function PollService
{
sleep 5
}

#Set Script Variables

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Creating Script Variables"

$ProfileSyncServer = "ContosoApp1"

$UserProfileDB = "Contoso_Profile_DB"

$UserProfileSyncDB = "Contoso_Profile_Sync_DB"

$UserProfileSocialDB = "Contoso_Profile_Social_DB"

$UserProfileApplicationPoolManagedAccount = "Contoso\ServiceAppPool"

$UserProfileApplicationPoolPassword = "Passw0rd1"

$SPFarmAccount = "Contoso\SPFarm"

$FarmAccountPassword = "Passw0rd1"

$UserProfileServiceName = "Contoso User Profile Service"


#Begin Script

$UserProfileAppPoolCredential = New-Object System.Management.Automation.PSCredential $UserProfileApplicationPoolManagedAccount,

(ConvertTo-SecureString $UserProfileApplicationPoolPassword -AsPlainText -Force)


Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Creating Managed Account if Required"
if (get-spmanagedaccount $UserProfileApplicationPoolManagedAccount -EA 0)
  {
  Write-Host "Managed Account Exists, No Need to Create a Managed Account" -foregroundcolor "Yellow"
  $UserProfileServiceAccount = Get-SPManagedAccount $UserProfileApplicationPoolManagedAccount
  }
else
  {
  $UserProfileServiceAccount = New-SPManagedAccount -Credential $UserProfileAppPoolCredential
  }

$UserProfileSyncAccount = Get-SPManagedAccount $SPFarmAccount

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Creating Application Pool"

$UserProfileServiceApplicationAppPool = New-SPServiceApplicationPool -Name $UserProfileServiceName -Account $UserProfileServiceAccount

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Starting User Profile Service"

$UPSI = get-spserviceinstance | where {$_.server -like "*" + $ProfileSyncServer -and $_.Typename -eq "User Profile Service"} | Start-

SPServiceInstance
$UserProfileSyncServiceInstance = get-spserviceinstance | where {$_.server -like "*" + $ProfileSyncServer -and $_.Typename -eq "User Profile

Synchronization Service"}

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Creating User Profile Service Application
"
$UserProfileSA = New-SPProfileServiceApplication -Name $UserProfileServiceName -ApplicationPool $UserProfileServiceApplicationAppPool -

ProfileDBName $UserProfileDB -ProfileSyncDBName $UserProfileSyncDB -SocialDBName $UserProfileSocialDB

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Setting User Profile Service Application Properties"
$SPUserprofileMachine = get-spserver $ProfileSyncServer
$UserProfileSA.SetSynchronizationMachine($ProfileSyncServer, $UserProfileSyncServiceInstance.id, $UserProfileSyncAccount.username,

$FarmAccountPassword)

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Creating User Profile Service Application Proxy"

New-SPProfileServiceApplicationProxy -Name ($UserProfileServiceName + " Proxy") -ServiceApplication $UserProfileSA

Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Starting User Profile Synchronization Service"

Start-SPServiceInstance $UserProfileSyncServiceInstance

while ($UserProfileSyncServiceInstance.status -ne "online")
{
pollservice
Write-Progress -Activity "Provisioning User Profile Service Application" -Status "Waiting for User Profile Synchronization Service to Start"
$UserProfileSyncServiceInstance = get-spserviceinstance | where {$_.server -like "*" + $ProfileSyncServer -and $_.Typename -eq "User Profile

Synchronization Service"}
}

Write-Host "Resetting IIS"
cmd.exe /c "iisreset $ProfileSyncServer /noforce"