我们使用SharePoint客户端对象模型SDK访问Office 365,没有API可以获取拥有一个驱动器的所有用户。我们怎么能这样做?
在MSDN上有PowerShell script解决方案,我们可以只用C#代码来实现吗?
答案 0 :(得分:1)
基于MSDN中的PowerShell Script,我想出了如何在C#中实现它:
在命令行上运行WSDL.exe以生成用户分析器服务的代理代码:
wsdl https://xxxx-admin.sharepoint.com/_vti_bin/UserProfileService.asmx?wsdl /username:aaaaa /password:ppppp
以下代码将列出所有使用OneDrive的用户:
UserProfileService uprofService = new UserProfileService();
uprofService.Url = adminPortalUrl + "/_vti_bin/UserProfileService.asmx";
uprofService.UseDefaultCredentials = false;
Uri targetSite = new Uri(url);
uprofService.CookieContainer = new CookieContainer();
string authCookieValue = spCredentials.GetAuthenticationCookie();
uprofService.CookieContainer.SetCookies(targetSite, authCookieValue);
var userProfileResult = uprofService.GetUserProfileByIndex(-1);
long numProfiles = uprofService.GetUserProfileCount();
while (userProfileResult.NextValue != "-1")
{
string personalUrl = null;
foreach(var u in userProfileResult.UserProfile)
{
/* (PersonalSpace is the name of the path to a user's OneDrive for Business site. Users who have not yet created a OneDrive for Business site might not have this property set.)*/
if (u.Values.Length != 0 && u.Values[0].Value != null && u.Name == "PersonalSpace" )
{ personalUrl = u.Values[0].Value as string;
break;
}
}
int nextIndex = -1;
nextIndex = Int32.Parse(userProfileResult.NextValue);
userProfileResult = uprofService.GetUserProfileByIndex(nextIndex);
}