Wednesday, July 3, 2013
Get All Sites in a SharePoint form
Get All Sites in a SharePoint form
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>("");
foreach (SPWebApplication webapp in service.WebApplications)
{
foreach (SPSite site in webapp.Sites)
{
foreach (SPWeb web in site.AllWebs)
{
Console.WriteLine(web.Url);
}
}
}
Tuesday, July 2, 2013
SharePoint Site Accessed users list
SharePoint Site Accessed users list
foreach (SPWeb web in siteCol.AllWebs)
{
DataTable dtUsers = new DataTable();
dtUsers = web.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.lastMonth, 400, DateTime.Now);
if (dtUsers != null)
{
foreach (DataRow rows in dtUsers.Rows)
{
Allrecords.Add(rows["User"] + "|" + rows["Most Recent Day"] + "|" + web.Url);
//Most Recent Day
// Console.WriteLine(rows["User"] + "|" + rows["Most Recent Day"]);
}
foreach (DataColumn col in dtUsers.Columns)
{
Console.WriteLine(col.ColumnName);
}
}
else
{
Console.WriteLine(web.Url);
}
}
Monday, July 1, 2013
Get active directory user details c#, (Get All Active directory domains in a Network & All Enabled users from Active Directory) to CSV
Get All Active directory domains in a Network .
ArrayList Doamin = new ArrayList();SPSecurity.RunWithElevatedPrivileges(delegate
{
Forest currentForest = Forest.GetCurrentForest();
DomainCollection domains = currentForest.Domains;
foreach (Domain objDomain in domains)
{
Doamin.Add(objDomain.Name);
}
});
===========================see more code==============================
All Enabled users from AD.
public static void GetAllInactivePersonsNEm(){
SPSecurity.RunWithElevatedPrivileges(delegate
{
//StreamWriter SW;
//SW = File.AppendText("C:\\ADall_InactivePrsns_NEm.csv");
//SW.WriteLine("User Name, Email , Domain Directory");
Forest currentForest = Forest.GetCurrentForest();
DomainCollection domains = currentForest.Domains;
try
{
foreach (Domain objDomain in domains)
{
Console.WriteLine("---Domain--" + objDomain.Name + "------");
string lDAPName = "LDAP://" + objDomain.Name;
DirectoryEntry entry = new DirectoryEntry("LDAP://" + objDomain.Name);
DirectorySearcher Dsearch = new DirectorySearcher(entry);
Dsearch.Filter = "(&(objectClass=user)(objectCategory=Person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";
try
{
foreach (SearchResult sResultSet in Dsearch.FindAll())
{
DirectoryEntry de = sResultSet.GetDirectoryEntry();
Console.WriteLine(GetProperty(sResultSet, "cn"));
//String ObjEmail = (GetProperty(sResultSet, "mail"));
//if (!String.IsNullOrEmpty(ObjEmail))
//{
// SW.WriteLine(GetProperty(sResultSet, "cn").Replace(",", " ") + "," + GetProperty(sResultSet, "mail") + "," + entry.Path.ToString());
//}
}
}
catch (Exception ex)
{
}
}
}
catch (Exception ex)
{
}
// SW.Close();
Console.WriteLine("AD aAtive Document Write Completed..4..");
Console.ReadLine();
});
}
public static string GetProperty(SearchResult searchResult, string PropertyName)
{
if (searchResult.Properties.Contains(PropertyName))
{
return searchResult.Properties[PropertyName][0].ToString();
}
else
{
return string.Empty;
}
}
Subscribe to:
Posts (Atom)