Powershell and Client Object Model - no error thrown if user is added more than once to same site or group
Hello All -
I am trying to add a user to a SharePoint site using PowerShell like below:-
New-SPUser -UserAlias MyDomain\jan20a -Web http://SPServer/sites/MySite
If I execute the above more than once, SharePoint does not throw that user already exists or something. This is not the same behavior in AD/Exchange PowerShell cmdlets.
Also, even the client object model behaves the same way.
Another interesting thing I noticed, I tried to remove a user from group in which the user was not part of it at all and still no error..!!
Looks like SharePoint does not care of invalid input and just ignores it.
Can anyone please confirm this and also the reason behind it ?
It's not really invalid input, since the user exists and that is how SharePoint behaves (will behave same way in browser). Try to input a user that and misspell the name, e.g. say you didn't have a MyDomain\Jan21a, then try to use same script above,
only with invalid data. It will bark at you. Or try using a web that it cannot find, one that does not exist. You'll get what I like to call, the red badge of courage if you enter invalid data.
you can test that sharepoint will let you enter a user twice in the browser, and nothing bad comes from it. Powershell is just unable to tell that the user was not in the site, when you removed it the second time.
Hope that confirms it, if it does please mark this reply accordingly. thanks
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
Similar Messages
-
Heading level hierarchy errors when topics are in TOC more than once
I have discovered that the hierarchy in the Heading levels in
the Printed Documentation will differ from than in my online help
table of contents hierarchy, and that the problem is due to topics
that are intentionally in the TOC more than once.
For example, in chapter 5 of a particular help system the
hierarchy should be:
Heading 1 < Chapter 5 title from top-level book>
Heading 2 <title of second level book>
Heading 3 <title of topic that appears under second-level
book>*
What I actually get is:
Heading 1 < Chapter title from top-level book>
Heading 2 <title of second level book>
Heading 4 <title of topic that appears under second-level
book>*
* This same topic appeared in an earlier chapter. In that
chapter it was really at a Heading 4 level.
Due to company styles, etc. we use a numbering system at the
headings and in the TOC, so instead of
5
5.1
5.1.1
I erroneously get
5
5.1
5.1.1.1
This type of hierarchy issue appears multiple times in this
particular document (which I inherited by the way.)
Other than restructuring the document to not reuse topics in
different places in the TOC, is there a solution or a workaround
for this problem?
What I am doing so far, is generating the Print Documentation
one chapter at a time. As long as a topic is not reused with the
same chapter, my hierarchy of heading levels is maintained;
otherwise, it is not. Then I can put the chapters back together
after fixing the few places that still have heading level problems.
This however, will be quite cumbersome as this document is
translated into nine other languages.
I am using RoboHelp X5 for Word / Word 2003 for the source
and most of the translations; RoboHelp Asian Edition, Simplified
Chinese / Word 2003 for the Chinese translation. The heading level
hierarchy error occurs in both versions.>> AF: I've commented in sections...
Without Maintain Heading Levels, RH will apply heading levels
to the books and then the topic levels will get bumped down. So a
top level book will be Heading 1 and the Headings in the topic will
get bumped down to 2, 3 and 4 etc. If then you have another book
one level down so that it gets Heading 2 applied, the same topic
but under the level two book would then get 3, 4 and 5 applied.
That is not the original problem but hopefully we are agreed
that is how things work on that.
>> Yes - that is the expected behavior. When it didn't
happen as expected, that's what led me to the discovery of the
cause of the problem (topic reuse).
Your problem was that firstly Heading 3 got bumped to Heading
4 if the same topic was inserted into the TOC twice. I assume it
was OK in the first instance, or is it that when you add it twice
it goes wrong everywhere?
>> Your assumption is correct. First occurrence is
correct. Second, third, and fourth (yes - there is one topic that
is used 4 times! ) are not correct based on TOC hierarchy.
On the numbering, nothing surprises me. If you look at my
site you will see that for RH HTML, i gave up on getting it right.
I have had many queries on this and more than a few people have
indicated they will work on the problem and get it working. I'm
still waiting. There are many posts about outline numbering
problems. Has anyone got it working satisfactorily?
>> I don't really have numbering problems. The
numbering is following the RoboHelp-generated hierarchy and the
.dot template that I apply. It's just that the RH-generated
hierarchy and its heading levels don't correspond to the "real"
hierarchy because of the reuse issue.
I have seen various Word gurus maintain that numbering has
not worked entirely satisfactorily since Word 2! Also enough posts
to convince me this is a Word issue, not a RH issue.
If you want to create a new project and knock something up
that demonstrates this problem, by all means zip it up and send it.
I'll assume it will be a small project and zip to less than 5mb. If
more, contact me first.
>> Unless you have RoboHelp X3 Asian Edition,
Simplified Chinese, there is really no need. I plan to either avoid
the reuse issue in the source, or build the print doc in sections
which is easy enough in RoboHelp X5 for the non-Chinese languages.
It is in the older Asian edition where the problems are compounded
by the omitted reuse topics. If you do have RoboHelp X3 Asian
Edition, Simplified Chinese and want to experiment, I can send you
a cut-down version of the project. Don't feel obligated though;
unless you can read Chinese (I can't) it is very tedious to work
with. -
Configure site auditing in sharepoint online using powershell or Client object model
Is the any way to configure site collection audit settings in sharepoint online programmatically or using powershell.
Hi Bhism,
The solution given in the article is for sharepoint 2010, i want to enable site auditing in Sharepoint 2013.
When i tried using that for sharepoint 2013 making he neccessary changes required for sharepoint 2013 i got an error :
Unable to find type [Microsoft.SharePoint.SPAuditMaskType]: make sure that the
assembly containing this type is loaded.
I think the assembly is for SP2010, is there anything like that for SP2013
Thanks in Advance. -
Quering the database using Client Object Model
Hi,
I have to fetch the list items from a list named "Project Status" and display it in a table using
Client Object model.
The equivalent server side code is:
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Project Status"];
DataTable dt1 = new DataTable();
try
if (list.ItemCount > 0)
DataColumn dc;
DataColumn dc1;
dc = new DataColumn("ProjectId", Type.GetType("System.String"));
dc1 = new DataColumn("Project Name", Type.GetType("System.String"));
dt1.Columns.Add(dc);
dt1.Columns.Add(dc1);
DataRow dr;
foreach (SPListItem item in list.Items)
dr = dt1.NewRow();
dr["ProjectId"] = item["ProjectId"];
dr["Project Name"] = item["Project Name"];
dt1.Rows.Add(dr);
Repeater1.DataSource = dt1;
Repeater1.DataBind();
catch (Exception Ex)
throw Ex;
1 more issue what i face is providing two links in the Visual WebPart and their navigate url is based on a condition that is fetched from the database. This corresponding code has to be converted to
Client Object Model.
string user = web.CurrentUser.LoginName;
string userID = user.Split(new char[] { '\\' })[1];
string connString = @"Data Source=NorthWind;Initial Catalog=EmployeeDB;User ID=sa;Password=Newuser123";
string query = "select * from EMPLOYEE_PROFILE";
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(query, conn);
try
conn.Open();
DataTable t1 = new DataTable();
using (SqlDataAdapter a = new SqlDataAdapter(cmd))
a.Fill(t1);
DataRow[] dr = t1.Select("PsNo = '" + userID + "'"); //This will select all rows where the Name Column has current user
foreach (DataRow r in dr)
string bU = r["DeputedBU"].ToString();
if (bU == "INS" || bU == "BFS")
lnkPM.NavigateUrl = web.Site.WebApplication.Sites[0].Url + "/Dashboard.aspx";
lnkSummary.NavigateUrl = web.Site.WebApplication.Sites[0].Url + "/DashboardWithHyperlinks.aspx";
else
lnkPM.Visible = false;
lnkSummary.Visible = false;
catch (Exception)
throw;
finally
conn.Close();
Any help would be appreciated.Hi,
According to your post, there would be two questions in this single thread.
It is recommended to post one question in one single thread which will make others easier to focus on one question in one thread.
For the first question, you want to fetch list items and put into a DataTable object using Client Object Model.
To fetch list items from a list using Client Object Model, you can take a look at the code snippet below from MSDN:
http://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx
For the second question, you might need to retrieve the User object and site collections object using Client Object Model.
However, if you can develop a Visual Web Part for your site, it means that you will be able to access the SharePoint Object Model which has more powerful APIs, so there is no
need to use Client Object Model in a Visual Web Part.
Best regards
Patrick Liang
TechNet Community Support -
Hi guys
I Think that is a simple error, but I don’t have enough knowledge in .NET apps.
I make an console app that use Remote Authentication in SharePoint Online Using the Client Object Model, that a I downloaded from MSDN.
This App run ok.
But when I like to make a Windows From App. This component send me an error in Application.Run(DisplayLoginForm)
This err msg :
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
Is there any way to use a form inside a windows form?
Thank in advance
Ramiro
Ramiro BHi,
Based on the error message, please do as following:
1. Check your code logic below:
void btn_Click(object sender, System.EventArgs e)
Thread t = new Thread(StartMyForm);
t.TrySetApartmentState(ApartmentState.STA);
t.Start();
public static void StartMyForm()
Application.Run(new MyForm(..));
2.Try to add the following code line in your code.
Application.Restart();
If the issue still exists, please provide your requirement and code for a further research.
Best Regards
Dennis Guo
TechNet Community Support -
Sharepoint client object model - Pull files from one site and move to another
Dear All,
I am using client object model to retrieve files of certain criteria using caml query and copy them to some other site using
client object model. There is no exception being thrown, but the application is not performing either. No files are being copied to destination. Here is the code. Please advise.
The message box that I have kept at the end is being displayed, but no files are being copied.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using SP = Microsoft.SharePoint.Client;
namespace WindowsFormsApplication2
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
SP.ClientContext srcContext = new SP.ClientContext(textBox1.Text);
srcContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
SP.ClientContext destContext = new SP.ClientContext(textBox2.Text);
destContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
SP.CamlQuery camlQuery = new SP.CamlQuery();
camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-01-01T04:16:20Z</Value></Geq><And><Lt><FieldRef
Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-12-31T04:16:43Z</Value></Lt><Or><Eq><FieldRef Name='Document_x0020_Classification' /><Value Type='Choice'></Value></Eq><Eq><FieldRef
Name='Document_x0020_Classification' /><Value Type='Choice'>Case Studies</Value></Eq></Or></And></And></Where></Query></View>";
SP.Web oWebsite = srcContext.Web;
srcContext.Load(oWebsite, website => website.Webs);
srcContext.ExecuteQuery();
SP.Web dWebsite = destContext.Web;
destContext.Load(dWebsite);
destContext.ExecuteQuery();
foreach (SP.Web web in oWebsite.Webs)
MessageBox.Show(web.Title);
foreach (SP.List list in web.Lists)
if (list.BaseType.ToString() == "DocumentLibrary")
MessageBox.Show(list.Title);
SP.ListItemCollection collListItem = list.GetItems(camlQuery);
srcContext.Load(collListItem);
srcContext.ExecuteQuery();
foreach (var doc in collListItem)
SP.File f = doc.File;
srcContext.Load(f);
srcContext.ExecuteQuery();
string destLibrary = "shared Documents";
string nLocation = dWebsite.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "")
+ "/" + f.Name;
SP.FileInformation fileInfo = SP.File.OpenBinaryDirect(srcContext, f.ServerRelativeUrl);
SP.File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true);
MessageBox.Show("Completed");
sk.RakhishmaHi,
To copy files from one site collection to another site collection, the simplest way is to open document library in windows explorer view.
Go to document library, click library tab, click open with explorer.
You can open the document library1 in explorer then copy the files which you want to paste to another site collection
document library2, then open the document library2 in explorer to paste the documents.
Besides, there are other method:
https://social.msdn.microsoft.com/Forums/office/en-US/67282348-25c7-4bd0-9d95-61024c6892f9/how-we-move-a-document-library-from-one-site-collection-to-another-sitecollection?forum=sharepointgeneralprevious
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/8c112d85-1ab8-426b-be37-d010cf8647fe/copy-a-list-from-one-site-collection-to-another-using-web-service
Best Regards,
Lisa Chen
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
403 Forbidden Error while trying to access External SharePoint site Via Client Object Model
Hi,
I am accessing the External SharePoint site from an intranet. When I try to access local sharepoint site in my intranet via Client object model to upload few documents into a library, it works perfectly fine without any issues.
But when I try to do the same (upload few docs ) to an external SharePoint 2010 site out of my intranet from my intranet, I get 403, forbidden error. It looks like there is some issue with login credentials of this site. But when I try to navigate to the
site URL in Visual studio 2010, it asks for credentials and takes me to home page.
I supplied the credentials in different forms like
ctx.Credentials = new NetworkCredential("username", "password", "domain");
and
clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
and
FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");
clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;
but nothing seems working and I get the Same 403 error. What am I missing here?
Thanks,
K.V.N.PAVANHi Pal,
Thanks for posting your query, Just try to add credentials to your clientContext object as mentioned below
NetworkCredential credentials =
new NetworkCredential("username", "pwd", "domain");
clientContext .Credentials = credentials;
or use
clientContext.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
I hope this will be helpful to you, If this works, Please mark it as Answered.
Regards,
Dharmendra Singh (MCPD-EA | MCTS)
Blog :http://sharepoint-community.net/profile/DharmendraSingh -
Conflict between Client object model and Item Updated Event Receiver in sharepoint 2010
Hello All,
As per my requirement I have a two custom list.
Agent Details
Port Name
Agent Details contains Agent code, Port Name, email, address and phone of Agent. Its possible that one Agent Code is connected with multiple Port Name.
Basically what I am doing is I am getting port name connected with Agent code, using jquery and bind those values with check box(using javascript created dynamically) and bind all with Div tag.
Now when my custom edit form of Agent list open up it shows me different port name binding with checkbox group.
when user select the check box and click confirm button my clicent object model script will run and add this selected value into Port Name list.
After confirm one more button named Save will enable asking user to edit the email, phone or address value and when I click on save my Item updated event fires which update the values of the selected port name(These port name I am getting from port
name list) to Agent Details custom list.
Now when I am trying to update the values my event receiver fires or some times it got stuck(not firing). So could you please help me the possible alternative for this requirements.
Can we user the Ecma Script(Client object model to preserve the value of selectec port) and Item updated event receiver on the same time?
Is anything am doing wrong then please guide me.Hi,
As I understand, when you updated values in the agent details list the Item updated event receiver got stuck sometimes.
The item update event receiver will fire after the item has been saved, and the client object model script or the Ecma Script runs before the item is saved, so there is no conflict between the client object model script and item update event receiver.
You could find out the reason about the item update event receiver gets stuck by debugging the event receiver.
When you want to debug your event receivers, you have to attach to OWSTIMER.EXE and wait till they are executed. You can control this behavior using the Synchronization attribute. Also, if you’re looking for an easy way to debug an event receiver without
having to manually attach a debugger to your code, you can use the System.Diagnostics.Debugger.Launch() method.
The articles below are about how to debug in the event receiver in SharePoint 2010.
http://sharepoint-kings.blogspot.jp/2013/02/debugging-event-receivers-in-sharepoint.html
http://chakkaradeep.com/index.php/event-receivers-in-sharepoint-2010/
http://sharesaint.com/?p=77
Best regards,
Sara Fan
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
I only recently learned/read about SharePoint's JavaScript Client Object Model. I'm reading online trying to figure this out but not having much luck.
On newform.aspx (and dispform.aspx) I want to get the
current list,
the last item created, and it's attachments. I now the CAML query I need to get the last item created, but first I have to get the current list and I am not sure how to do that.
I tried this but it returns null:
SP.ListOperation.Selection.getSelectedList()Hi,
For your issue, you can get the list name from the new form url and retrieve the list last created item :
https://social.msdn.microsoft.com/Forums/office/en-US/b90a64f8-2255-41b0-9d91-78335dd4a4cf/get-list-name-from-list-url-through-javascript?forum=sharepointdevelopmentprevious
http://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx
Best Regards,
Eric
Eric Tao
TechNet Community Support -
Advantages and Disadvantages of Client Object Model in sharepoint 2013
I need Advantages and Disadvantages of Client Object Model in sharepoint 2013
like below in javascript. Users will have read/edit and approve access to the list.
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Workflow Tasks');
MCTS Sharepoint 2010, MCAD dotnet, MCPDEA, SharePoint LeadThanks
AlexanderShelopukho for
right answer!
Alex-
I do not need comparison-
I need Advantages and Disadvantages of Client Object Model in sharepoint 2013
MCTS Sharepoint 2010, MCAD dotnet, MCPDEA, SharePoint Lead -
Hi,
I have started using the client object model so that i do not have to go to sharepoint admins to perform some basic operations on remote server. While assigning list item level permission i am getting following error, could you please help. thanks.
The remote server returned an error: (401) Unauthorized.
at
System.Net.HttpWebRequest.GetResponse()
at
Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at
Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at
Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at
SetDowntimeItemPermission.SetPermission.Main(String[] args) init seems your request was unauthenticated i'm not sure are you using a web application with FBA or desktop application my suggestion would be try to impersonate your request by passing network credentials (COM works on network credentials )
NetworkCredential credentials = new NetworkCredential("username", "pwd", "domain");
ClientContext context = new ClientContext("http://site-url");
context.Credentials = credentials;
Best Regards, Ashutosh | SharePoint World -
Attach a custom content type and set as default for picture library using client object model
Hi,
How to associate custom content type to a picture libraray and set it as default using the client object model?
ThanksHello,
Here you go:
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/b1de0697-0006-4f89-8909-1b94aa18ad89/how-to-reorder-content-types-in-list-with-client-context
http://www.niteenbadgujar.com/2013/05/change-default-content-type.html
Hope it could help
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
Remote server returned an error: (401) Unauthorized. in Client Object Model
Hi
I'm facing below error when using Client object model to access the sharepoint extended site which is windows authentication.'
The
remote server returned an error: (401) Unauthorized
The COM code was working fine, suddenly we get this error, so I'm sure nothing to fix in code. Please help what might cause this issue which was working well.
SubbuCan you post your code to understand how you are authenticating with SharePoint?
Bala -
I'm using the SharePoint 2013 Client Object Model to access a site that is either in Office 365 or behind an ADFS 3.0 login screen, is it sufficient to use the new SharePointOnlineCredentials credentials
or do I need other types of credentials for the sites behind ADFS 3.0 ? Is so, what type of credentials would I use for the sites behind ADFS 3.0?
using (ClientContext ctx = new ClientContext(siteUrl))
ctx.Credentials = new SharePointOnlineCredentials("some user", "a secure string password");
while (ctx.HasPendingRequest)
ctx.ExecuteQuery();
// etc.Hi,
According to your post, my understanding is that you want to know the ways to get credential either in Office 365 or sites behind ADFS 3.0.
For Office 365, you can use SharePointOnlineCredentials Object to get credential. For SharePoint sites behind ADFS 3.0, you can use NetworkCredential Object:
ctx.Credentials = new NetworkCredential(UserName, Password, Domain);
The link below will provide more information about using the ADFS FedAuth Token programmatically through the SharePoint Client Object Model:
http://samirvaidya.blogspot.com/2013/05/using-adfs-fedauth-token.html
Best regards
Patrick Liang
TechNet Community Support -
Unable to get the SharePoint 2013 List names using Client object model for the input URL
Please can you help with this issue.
We are not able to get the SharePoint 2013 List names using Client object model for the input URL.
What we need is to use default credentials to authenticate user to get only those list which he has access to.
clientContext.Credentials = Net.CredentialCache.DefaultCredentials
But in this case we are getting error saying ‘The remote server returned an error: (401) Unauthorized.’
Instead of passing Default Credentials, if we pass the User credentials using:
clientContext.Credentials = New Net.NetworkCredential("Administrator", "password", "contoso")
It authenticates the user and works fine. Since we are developing a web part, it would not be possible to pass the user credentials. Also, the sample source code works perfectly fine on the SharePoint 2010 environment. We need to get the same functionality
working for SharePoint 2013.
We are also facing the same issue while authenticating PSI(Project Server Interface) Web services for Project Server 2013.
Can you please let us know how we can overcome the above issue? Please let us know if you need any further information from our end on the same.
Sample code is here: http://www.projectsolution.com/Data/Support/MS/SharePointTestApplication.zip
Regards, PJ Mistry (Email: [email protected] | Web: http://www.projectsolution.co.uk | Blog: EPMGuy.com)Hi Mistry,
I sure that CSOM will authenticate without passing the
"clientContext.Credentials = Net.CredentialCache.DefaultCredentials" by default. It will take the current login user credentials by default. For more details about the CSOM operations refer the below link.
http://msdn.microsoft.com/en-us/library/office/fp179912.aspx
-- Vadivelu B Life with SharePoint
Maybe you are looking for
-
Specific signature when in folder
how do you select a specific signature when in a folder? i have a number of email accounts, and have set up folders, with various rules... when in some folders and select new message, the correct signature appears but then not in others. is there a s
-
The other day when I was on my iPod touch (8 GB) I put on music but then something when wrong. When I plug in my headphone and put music on, it sounded like I was hearing music under water, and it sounded fuzy and weird. Then I unplug the headphone f
-
Problem for uplaoding sales text using LSMW
Hi, I have use LSMW for uplaoding material masters sales and purchase order text , first I have done for purchase order text with object : MATERIAL and ID : BEST it works fine for this after that when I am trying same for uploading sales text
-
After effects crashing unpredictable, please help if you can?
Only be happening for a week or so. seems to be related to blurs in adjustment layers. ill be using blurs to spot blur certain anatomy for a tv show. sometimes I track and blur with mocha sometimes manual track. ill be adjusting a track or a mask an
-
Which is better:C++ or Java???
Hey,People (like my friends)keep tellin me that C++ is better, quicker, etc. than Java! I thnk Java is a lot better. What do you think is better and why so I could have a come-back when me and my friends are arguing about it?