CHUVASH.eu
  • About
  • Search

Posts

January 22, 2012

Adding organizational units to AD through powershell

Want to create some organizational structure in AD, I suppose it is specifically useful in a development environment, well the best solution is powershell then. Mastering Powershell by and Powershell.nu by Niklas Goude provide examples how to do this.

$domain = \[ADSI\]""
$ou = $domain.Create("organizationalUnit", "OU=Administration")
$ou.SetInfo()
```Be sure you write "organizationalUnit" in lower case. Otherwise you'll get "Exception calling "SetInfo" with "0" argument(s): "The specified directory service attribute or value does not exist" when you invoke **$ou.setinfo()**. If you want to create an OU under another OU, just create $domain and specify the location: \[code language="powershell"\] $domain = \[ADSI\]"OU=Administration, dc=takana, dc=local" $company = $domain.Create("organizationalUnit", "OU=Accounting") $company.SetInfo()</pre> To save some other properties: <pre>$ou.put("Description", "this is a dummy ou") $ou.SetInfo() \[/code\]

#### Update 2013-12-10

In PowerShell V3 you have a built-in cmdlet for doing that once you add the Active Directory role in your server. It simple as that: \[code language="powershell"\] New-ADOrganizationalUnit "Accounting" -Path "dc=takana, dc=local" \[/code\]
read more
January 22, 2012

Install a custom timer job in Powershell

First we have to create a class for our timer job which inherits SPTimerJobDefinition, build it and deploy it.

public class TakanaTimer : SPJobDefinition
{
	public TakanaTimer(){}
	public TakanaTimer(string jobName, SPService service,
		SPServer server, SPJobLockType targetType)
		: base(jobName, service, server, targetType) { }

	public TakanaTimer(string jobName, SPWebApplication webapp)
		: base(jobName, webapp, null, SPJobLockType.ContentDatabase)
	{
		Title = jobName;
	}
	public override void Execute(Guid contentDbId)
	{
		Log.Info("Running Takana Timer");
	}
}

There is a powershell example for this, but it has not been updated since MOSS.

read more
January 22, 2012

Shrink sharepoint database

A Sharepoint Database can become big and have unused spaces. To shrink database go to CA-> Health Analyzer: http://takana:1337/Lists/HealthReports/AllItems.aspx See if there is a list item about unused space in db under the Availability. Click on Repair Automatically in the opened Modal Dialog:  

read more
January 22, 2012

Set ObjectTrackingEnabled = false when reading

In LINQ 2 SP we work with a data context. By default a data context has the property ObjectTrackingEnabled = true. This property is crucial for all other operations in CRUD except Read. I performed a mini experiment. I created 20 000 items in my task list. Every seventh item contains “pärla”. Allright, here is what I found out:

2857 / 20 000 items

ObjectTrackingEnabled = true

read more
January 20, 2012

The new interface of wp.com is great.

The new interface of wp.com is great. For a while I had some considerations to migrate to tumblr, now I definitivly stay with wp. Now wp takes the best from itself, tumblr and twitter.

read more
January 20, 2012

Find the current Active Directory Domain

While working with Active Directory within SharePoint we probably don’t need to specify the domain or the root container. We can the current values. Here is a simple method from a console application just to demonstrate:

internal static void GetDomain()
{
	var context = new DirectoryContext(DirectoryContextType.Domain);
	var domain = Domain.GetDomain(context);
	Console.WriteLine("Full domain:");
	Console.WriteLine(domain.Name); //takana.local
	Console.WriteLine();
	Console.WriteLine("root container");
	var parts = domain.Name.Split(new\[\] {"."}, StringSplitOptions.RemoveEmptyEntries);
	var dcParts = parts.Select(n => "dc=" + n).ToArray();
	var d = string.Join(",", dcParts); //dc=takana, dc=local
	Console.WriteLine(d);
}

First we get get the full domain, then we split and join them again.

read more
January 20, 2012

Two interesting html5-in-sharepoint presentations

[slideshare id=11031050&doc=sharepointhtml5-120113215236-phpapp02]   HTML5-and-CSS3-What-About-SharePoint.pdf (968 KB) by Kyle Schaefer

read more
January 18, 2012

qoutes in @ strings

I use @-prefixed strings very often. You can use line breaks as much as you want. Very useful e.g. when I must create an xml in code. One thing I didn’t know was that you CAN use quotation marks inside @-strings. But you must write double quoutes like:

var t = @"säg ""hej""
		och ""hå""";
read more
January 17, 2012

Datetime in ASP.NET javascript and $.ajax

In one of my previous blogs I wrote about serializing of javascript objects. You can do it with JSON.stringify or Sys.Serialization.JavaScriptSerializer.serialize. Both methods work fine… almost. There is a big difference when it comes to datetime objects. MS treats dates a little bit different (like RegEx and much more). Let’s try this one:

var writer = { name: "Ajgi", birthdate: new Date(1934, 8-1, 21) };
var json = JSON.stringify(writer);
var msjson = Sys.Serialization.JavaScriptSerializer.serialize(writer);

What happens if we try to parse back msjson with JSON.parse: Well, the date isn’t a valid date anymore. How can we improve it. Rick Strahl gives a solution with custom functions for serializing and deserializing of ms date. But the thing is: we don’t need any custom functions for this, not if you run ASP.NET. The only thing we need is to use serialize and deserialize functions from Sys.Serialization.JavascriptSerializer namespace which you get automatically when you add ScriptManager in ASP.NET (and you get it even automagically in SharePoint). But what about $.ajax and functions I wrote about for retrieving list items and populating them, and updating list items with listdata.svc? Well, there comes the really nice tip from Rick Strahl: not to force $.ajax to parse the response. So instead of dataType: “json”, use the plain dataType: “text”. As the result we’ll get just a text, which we, of course, will deserialize with the native code for Microsoft:…. Use text when possible. When you define json as response format:

read more
January 16, 2012

SPWebConfigModification

SPWebConfigModification. Some links to start with: http://panvega.wordpress.com/2009/09/02/using-spwebconfigmodification-within-a-feature-receiver/ http://www.onedotnetway.com/get-name-of-current-executing-assembly-in-c/ http://blogs.devhorizon.com/reza/?p=459 http://ikarstein.wordpress.com/2010/09/02/add-web-config-modification-with-powershell-spwebconfigmodification/ http://msdn.microsoft.com/en-us/library/bb861909.aspx

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
	var webapp = parent as SPWebApplication;
	if (webapp != null)
	{
		var mod1 = GetWebControlsConfigMod();
		webapp.WebConfigModifications.Add(mod1);
		var mod2 = GetConStringConfigMod();
		webapp.WebConfigModifications.Add(mod2);
		SaveChanges(webapp);
	}
	else
	{
		Log.Warning("no modifications to webapp are done");
	}
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
	var webapp = parent as SPWebApplication;
	if (webapp != null)
	{
		var mod = GetWebControlsConfigMod();
		var modsCollection = webapp.WebConfigModifications;
		var modToDelete =
			(from m in modsCollection
			 where m.Value.Equals(mod.Value, StringComparison.InvariantCultureIgnoreCase)
			 select m).FirstOrDefault();
		if (modToDelete != null)
		{
			modsCollection.Remove(modToDelete);
			SaveChanges(webapp);
		}
	}
}
private static void SaveChanges(SPPersistedObject webapp)
{
	var service = webapp.Farm.Services.GetValue();
	service.ApplyWebConfigModifications();
	webapp.Update();
}

private static SPWebConfigModification GetWebControlsConfigMod()
{
	var assembly = System.Reflection.Assembly.GetAssembly(typeof(WebControls.OfficeEditor));
	var ass = assembly.FullName;
	var @namespace = assembly.GetName().Name + ".WebControls";
	var value = string.Format("", ass,
							  @namespace);
	const string path = "configuration/SharePoint/SafeControls";
	var mod = new SPWebConfigModification
	{
		Path = path,
		Name = "JustaName1",
		Sequence = 0,
		Owner = @namespace,
		Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
		Value = value
	};
	return mod;
}

private static SPWebConfigModification GetConStringConfigMod()
{
	const string name = "ContosoConString";
	const string conString =
		"Data Source=db.contoso.com;Initial Catalog=contoso\_db;Persist Security Info=True;User ID=contoso\_Contributor;Password=contoso";
	var mod = new SPWebConfigModification
	  {
		  Name = "JustaName2",
		  Path = "configuration/connectionStrings",
		  Owner = "contoso\_connectionstrings",
		  Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
		  Value = String.Format("", name, conString)
	  };
	return mod;
}
```Powershell:

#ADDING asnp microsoft.sharepoint.powershell $url = “http://contoso” $app = Get-SPWebApplication $url $name = “ContosoConString”; $conString = “Data Source=db.contoso.com;Initial Catalog=contoso_db;Persist Security Info=True;User ID=contoso_Contributor;Password=contoso”; $mod = new-object Microsoft.SharePoint.Administration.SPWebConfigModification $mod.Name = “JustName2” $mod.Path = “configuration/connectionStrings” $mod.Owner = “User Name” $mod.Type = 0 #for the enum value “SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode” $mod.Value = ‘’ -f $name, $conString $app.WebConfigModifications.Add($mod) $service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService $service.ApplyWebConfigModifications() $app.Update() #ADDING snapin asnp microsoft.sharepoint.powershell

read more
  • ««
  • «
  • 26
  • 27
  • 28
  • 29
  • 30
  • »
  • »»
© CHUVASH.eu 2025