Skip to main content

SharePoint MySite – PowerShell script to get the “Activities I am following” preferences

 So I was asked to collect the preferences of “Activities I am following” (image below) for all the users of our SP2010 My Site.


The resources on web for this being  surprisingly limited , I was left with no other option but to turn to my cup of coffee  for solution . The coffees helped, the following script lists out the status of options available under “Activities I am following ” of My Site Edit Profile page in SharePoint 2010 , for each user.


$mySiteURL = "https://xxxx"
$site = Get-SPSite $mySiteURL
$context = Get-SPServiceContext $site;
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);

$val = "Username,ActivityName,Value"
Add-content -path "d:activity_preference.txt" -value $val

foreach ($profileupm in $upm.GetEnumerator())
{
$myprofile = $profileupm;
$usrprofile = $profileupm;

$am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($myprofile,
 $context)
$type = $am.GetType()

$methodInfo = $type.GetMethod("CopyBasicUserInfo", 
 [reflection.bindingflags]"nonpublic,instance",
 $null, $usrprofile.GetType(), $null)

$methodInfo.Invoke($am, $usrprofile)

$preftype = $am.ActivityPreferences.GetActivityPreferencesPerType();

foreach($pr in $preftype)
{
foreach($a in $am.ActivityTypes)
{
if ($pr.ActivityType -eq $a)
{
$val = $usrprofile["AccountName"].ToString() +
 "," + $a.ActivityTypeName.ToString() + 
 "," + $pr.IsSet.ToString()

 Add-content -path "d:activity_preference.txt" -value $val
} }  } }

Comments

Popular posts from this blog

FTP C# Error : “The remote server returned an error: (530) Not logged in ."

  Recently working on a FTP solution using C# , i encountered an error  “ The  remote server returned an error: (530) Not logged in.” The code i used was following: FtpWebRequest request = (FtpWebRequest)WebRequest.Create( ftp://xxxxxx/file.txt ); request.Method = WebRequestMethods.Ftp.UploadFile request.Credentials = new NetworkCredential(usernameVariable, passwordVariable); What was more bewildering was if i modified the code to following, the solution was working fine. But this for obvious reasons is not an option as the username cannot be hardcoded //works but implausible to use in realtime solutions request.Credentials = new NetworkCredential("dmn/#gsgs", password);  Some googling revealed that special charcters create issues in the NetworkCredential Object. Hence some playing around worked for me, and it works irrespective of wether i do a FTPWebRequest or WebRequest. Solution: Instantiate NetworkCredential object with three paramters (username, password, domain) and m

How to Add/Edit environment variables on Windows.

 1. Search and Open Environment variables 2. On the "System Properties" panel click Environment Variables 3. Double click on the required variable to edit/add new values.

Llamhub SnowflakeReader: A Loader to query and chat Snowflake Data in your LLM Applications

  Snowflake Loader for LLM Recently my second contribution to Llamaindex "SnowflakeReader" was merged to Lllamahub repository. This loader connects to Snowflake (using SQLAlchemy under the hood). The user specifies a query and extracts Document objects corresponding to the results. This loader is designed to be used as a way to load data into  LlamaIndex  and/or subsequently used as a Tool in a  LangChain  Agent.  Usage Option 1: Pass your own SQLAlchemy Engine object of the database connection Here's an example usage of the SnowflakeReader. from llama_index import download_loader SnowflakeReader = download_loader ( 'SnowflakeReader' ) reader = SnowflakeReader ( engine = your_sqlalchemy_engine , ) query = "SELECT * FROM your_table" documents = reader . load_data ( query = query ) Option 2: Pass the required parameters to esstablish Snowflake connection Here's an example usage of the SnowflakeReader. from llama_index import down