Wednesday, February 3, 2016

Update User info in SharePoint site using Powershell

Sometimes user do report issue where their user information is not updated in SharePoint. It may happens that AD does sync all info and update on sharepoint site. In such cases, you can use below quickfix powershell command to update particular user info:

$site = Get-SPSite "https://Siteurl"

$web = $site.RootWeb

$list = $web.Lists["User Information List"]

#the account is using our trusted ADFS Identity Provider

$i = $list.Items | where {$_["Account"] -eq "domain\username"}

$i["Work e-mail"] = "emailaddress@asdf.com"

$i.update()
$web.Dispose()
$site.Dispose()

or  you can also use below command to update same:

$web = get-spweb "SiteCollection URL" 
$user = $web.EnsureUser("domain\username") 
echo $user
Set-SPUser -Identity $user -Email "email@yourdomain.com" -Web "SiteCollection URL"
 
 

Powershell command .ps1 cannot be loaded. the file is not digitally signed. you cannot run this script on current system

Recently I came across below error while execute powershell command:

file.ps1 cannot be loaded. The file D:\SIT\deploy\Deploy-SITConnector.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess


Cause:
=====


Generally, you will get this error if you retracted files from compressed format(.zip, .rar) and files are unblocked mode. Selecting individual file of ps1 or other dependent files by going to its properties to unblock will fix the error and you can execute the powershell command.


Solution:
======
- Go to properties of that ps1 file or its dependent files(xml, dll,...) and unblock it.