Wednesday, December 30, 2015

SharePoint Windows Azure DirSync error unable to re-install Directory Sync


I had installed the directory sync set up and then uninstalled it.However , while trying to reinstall the setup , it gave the above exception.

There is good blog from josephturley who gave detailed instructions on how to troubleshoot it. But this did not help. What worked for me was removing a registry entry for "Windows Azure Active Directory Sync". You can find it under registry path HKEY_LOCAL_MACHINE/ Software/ Microsoft/ Windows/ CurrentVersion/ Uninstall. Find the GUID which corresponds to the Display name as "Windows Azure Active Directory Sync"


Thursday, December 10, 2015

SharePoint Online Powershell error Cannot find an overload for "Load" and the argument count: "1".

While using Powershell with CSOM you encounter the error "Cannot find an overload for "Load" and the argument count: "1"  when you do $context.Load while trying to access data from SharePoint online

Exact error:
Cannot find an overload for "Load" and the argument count: "1".
At C:\Users\XXX\Desktop\Scripts\Scripts.ps1:20 char:14
+ $Context.Load <<<< ($Lists)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Resolution:

Make sure that you have installed the Sharepoint Client SDK - http://www.microsoft.com/en-us/download/details.aspx?id=35585

Since Load ClientRuntimeContext.Load<T> expects a generic ,in powershell you need to use the Invoke method to call generic methods.

Use the following method to load any objects instead of the Load method. Pass the current Context and the object that needs to be loaded.

Function Invoke-LoadMethod() {
param(
   $ctx,
   $clientObject
)
   $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load")
   $type = $clientObject.GetType()
   $genericMethodInvoker = $load.MakeGenericMethod($type)
   $genericMethodInvoker.Invoke($ctx,@($clientObject,$null))
}

Usage: Invoke-LoadMethod -ctx $ctx -clientObject $spWeb

Sample Code Execution:

Function Invoke-LoadMethod() {
param(
   $ctx,
   $clientObject
)
   $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load")
   $type = $clientObject.GetType()
   $genericMethodInvoker = $load.MakeGenericMethod($type)
   $genericMethodInvoker.Invoke($ctx,@($clientObject,$null))
}

#Specify tenant user and site col url
$user = "user@tenant.onmicrosoft.com"
$siteURL = "https://XX/sites/XXX"


#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"


$password = convertto-securestring "XXX" –asplaintext –force
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$password)

#initialize context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$password)
$ctx.Credentials = $creds

#Retrieve web related informations
$web = $ctx.Web
Invoke-LoadMethod -ctx $ctx -clientObject $web
$ctx.ExecuteQuery()

#Retrieve lists
$lists = $ctx.Web.Lists
Invoke-LoadMethod -ctx $ctx -clientObject $lists
$ctx.ExecuteQuery()

Sunday, October 21, 2012

Mapping Taxonomy Fields with Terms using PowerShell


SalesForce Tips

Updating Taxonomy Fields with Terms using PowerShell

Being a beginner in PowerShell script I had a bit of fun trying to figure out getting around a scenario where we had to map a given term (instead of TermSets) which had sub terms to a site column value. Below was the sample hierarchy for the Taxonomy



Here Country, Language were the Groups, Finance and HumanResources were the TermSets and the remaining were Terms. We needed to map the Terms to the site columns using PowerShell script reading the data from a configurable xml.
Though there were a couple of articles mentioning how to do the mapping to TermSet values ,it did not seem to work. The main thing missing was the AnchorID property. This is the mapping used by the fields to associate it to the Term value$field.AnchorId = $term.Id )  You can see the sample script used for the mapping below. 



# Create Site object
$site = Get-SPSite "http://siteurl/"
# Get the field ref
[Microsoft.SharePoint.Taxonomy.TaxonomyField]$field = $site.RootWeb.Fields | Where-Object { $_.Name -eq "FIELDNAME" }
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
# Get the term store instance
$termstore = $session.TermStores["Managed Metadata Service"]
# Get the Term Group using the Name
$group = $termstore.Groups | Where-Object { $_.Name -eq "Company" }
# Get the TermSet using the TermSet name
$termSet = $group.TermSets | Where-Object { $_.Name -eq "Finance" }
$terms = $termSet.GetTerms(100)
# Get the Term using the name
$term = $terms | ?{$_.Name -eq "Country"}
# Update the SspId
$field.SspId = $termstore.Id
$field.TermSetId = $termSet.Id
# Map the term value
$field.AnchorId = $term.Id
# Update the field
$field.Update()

Hope this helps !!!