Tuesday, March 22, 2016

Powershell to Get Users From AD Group

Get-ADGroupMember -identity "GROUPNAME" -Recursive | Get-ADUser -Property DisplayName | Select Name,ObjectClass,DisplayName

Thursday, September 17, 2015

How to Enable or Disable Document Property Promotion (ParserEnabled) in SharePoint 2013

How to Enable or Disable Document Property Promotion (ParserEnabled) in SharePoint 2013

This is the way to solve issues on uploading document into SharePoint 2013 Document Library. After upload the document into SharePoint library, the document had the metadata (document properties) of the original document. Metadata that is changed on the document will revert to the original values that were given to the document; this occurs both from SharePoint and from MS Word.
 
Solution 1 – Remove Document Properties & personal Information using Inspect
1.      Open file using Microsoft office
2.      Click file and the inspect document (check for issues)
3.      Tick only on document properties & personal information
4.      Inspect & then remove
5.      Then Save
6.      Upload document into SharePoint.
 
Solution 2 – Disable Document Property Promotion using PowerShell
The SPWeb object has a ParserEnabled property, which enables or disables this functionality.  Using the PowerShell script, we can turn off this functionality at the web level. Sample script to disable the document parser feature in SharePoint:
1.      Open the SharePoint 2013 Management Shell as Administrator.
2.      Run the following script to disable document property promotion.
 
C:\> $web
        Url
        ---
        http://spfe01/sites/SITENAME/SUBSITENAME
C:\> $web.parserenabled
        True
C:\> $web.parserenabled  = $false
C:\> $web.Update()
C:\> $web.parserenabled
        false
 
 
3.      Document Property Promotion is disabled successfully and when you try to upload a document you will find that all the fields are empty
 
Reference 3:http://fairulshahrizat.blogspot.in/2014/10/how-to-enable-or-disable-document.html

Friday, September 4, 2015

Thursday, September 3, 2015

Get all Columns of List (including Hidden) using powershell

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null

$url = "SiteUrl/"
$listName = "Listname"
$path ="C:\Temp\Columns.csv"

$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$list.ContentTypes | % { $_.FieldLinks } | select Name |  Export-Csv -path $path

Get all fields inside ContentType sharepoint powershell


cls
set-variable -option constant -name url -value "http://siteurl"  # Site collection
#set-variable -option constant -name out -value "ContentTypes.csv"  # Site collection
# End of settings

$site = new-object Microsoft.SharePoint.SPSite($url)
$cts = $site.rootweb.ContentTypes["ContentTypeName"]


ForEach ($id in $cts)
{
  ForEach ($field in $id.Fields)
  {
  Write-Host $field.Title
  Write-Host $field.InternalName
 
  }
}

$site.Dispose()

echo "Finished!"

UnHide hidden column using powershell 2013 sharepoint

# First load SharePoint Core Assembly

###################################################################################
#                                                                                 #
###################################################################################

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
cls
$web = Get-SPWeb  "http://webapp/siteurl"
$listLegComp = $web.Lists["ListtemplateHidden"]
#$ContentType=$web.ContentTypes[""]
#$myfield=$ContentType.Fields[""]


$pcField = $listLegComp.Fields.GetFieldByInternalName("Hidden2Column")

if(!$pcField.CanToggleHidden)
{
   $bindingFlags = [Reflection.BindingFlags] "NonPublic,Instance"
   [System.Type] $type = $pcField.GetType()
   [Reflection.MethodInfo] $mdInfo = $type.GetMethod("SetFieldBoolValue",$bindingFlags)
   $object = [System.Object] @("CanToggleHidden",$true)
   $mdInfo.Invoke($pcField,$object)
   $pcField.Hidden = $true
   $field.ShowInEditForm = 1;



# Controls Field in New Form
$pcField.ShowInNewForm = 1;

# Controls Field in New Form
$pcField.ShowInDisplayForm = 1;

# Hides fields from list settings
$pcField.ShowInListSettings = 1;

# Hides fields from version history
$pcField.ShowInVersionHistory = 1;

# Hides fields form selection in views
$pcField.ShowInViewForms = 1;
#check allow deletion
   $pcField.AllowDeletion = $true
   $pcField.Update()
}



$listLegComp.Update()
$web.Dispose()

Get login Name using csom

  public static string GetUserLoginName(string Context, int UserID)
        {
         
       
            string LoginName = string.Empty;
string EmailId = string.Empty;
            try
            {
                using (ClientContext ctx = new context(Context))
                {

//credentials
                    if (ctx != null)
                    {


                        UserCollection users = ctx.Web.SiteUsers;
                        ctx.Load(users);
                        ctx.ExecuteQuery();
                        User RequestorUser = users.GetById(UserID);
                        ctx.Load(RequestorUser);
                        ctx.ExecuteQuery();
                        LoginName = RequestorUser.LoginName;
    EmailId= RequestorUser.EmailID;
                    }
                }
            }
            catch (Exception ex)
            {

         
            }


            return LoginName;
        }