Active Directory Usefull Methods

Here are a few methods that will enable you to do some tasks in Active Directory.

Add Member
DirectoryEntry.Properties["member"].Add(fullUserPath);
DirectoryEntry.CommitChanges();
Directory.Close();

Remove Member
DirectoryEntry.Properties["member"].Remove(fullUserPath);
DirectoryEntry.CommitChanges();
Directory.Close();


Move Directory Object

currentLocation.MoveTo(oldLocationDirectory, newLocationDirectory);

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Add Value To SharePoint Farm Property Bag

When creating SharePoint applications I found using the propertybag very usefull. 
As it makes accessing important data accross the SharePoint
farm very easy.
I do though always sugest enryption dependant on the importants
of
the information stored
. 

SPFarm farm = SPFarm.Local;

farm.Properties.Add(object Key, Object Value);

 Wink

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Active Dirctory Permissions

Working on AD I found that permissions play a huge part in allowing access to directory objects.
I think that creating a new abject without using any kind of elevation of privileges is a very bad
idea as you will get an exception that is not very useful. So to counter this heart ache we use elevation.

Elevation Code 

DirectoryServicesPermission dPermission = new DirectoryServicesPermission
(System.Security.Permissions.PermissionState.Unrestricted);

dPermission.Assert();

Hope this helps with AD!

Laughing

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SharePoint Web Part Architecture

When working on coding standards I came up with a possible design for
a WebPart based largely on a few design patterns that I looked at. I wanted to
present this to everyone for possible feed back.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Displaying raw XML on search results

Quite often you will need to customise the search results and ensure that your custom metadata mappings are displaying correctly.

To view the raw results, I undertake the following...

a) Edit the results page (results, or people depending on what you are looking to modify

b) Add a new core results web part (again people or results)

c) Add your columns, fixed queries etc

d) Click the Edit XSLT button and replace the XSLT with the following

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>
</xsl:template>
</xsl:stylesheet>

Save everything and you can now see the raw results.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Powershell & HyperV - Create a VM in a specific folder

Well, James O'Neill has updated his library on codeplex again, but there is still a function missing that I needed. In our environment we create multiple machines and I wanted a way to create them in a specific directory, now I know I could set the default location and then create it, but I prefer to just specify a path and go from there.

I started from Ben Armstrong's code at Virtual PC Guy's Weblog and then modified the code after the VM name is set to also specify the location of the folder it will be created in.

# Setthe VM name
$newVSGlobalSettingData.psbase.Properties.Item("ElementName").value = $VMName

# New code - Set Folder location
$VMFolder = "E:\DevVMs\"
$newVSGlobalSettingData.psbase.Properties.Item("ExternalDataRoot").value = $VMFolder + $VMName

It took a little while to find the correct property to set, and I don't think that ExternalDataRoot is particularly obvious but the documentation at MSDN was helpful. In the example above, it puts the VM files in E:\DevVMs\VMName.

For our scripts I then used the HyperV Library to configure the VM with CPUs, RAM, disks and network connections.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Displaying a Single Users Profile Details

Following the previous post on search, this shows how to simply and quickly show a single users profile details on a page. Note, that this intended for MOSS (where we have the profile database) but could be re-worked for WSS to show details from the user list.

On our page, we need to add the People Search Core Results Part

 

Once added, open the web part properties so we can configure the part. We need to make several changes....

a) Under the Results Display / View group, set the Results Default View to Relveance and Results per page to 1

b) Under the Results Query Options group, change the Cross Web Part Query ID to Query 2 (see also note below)

c) Under the Miscellanous group, uncheck all the options except  Show Search Results

d) Finally, in the Fixed Keyword Query option, enter the query required (e.g. LastName:Piper)

Save the changes.

The final result will be basic details from the profile databse about our user

If the appearance needs to be changed, then you can edit the XSLT (another future post I think!) to suit.

Note - you may need more than one profile - in this case, the Cross Web Part Query ID needs to unique for each part on the page.

If you have more than 3 user profiles to display, then consider using different queries to get multiple results. For example, to show all users who have the property Department:Sales to show all sales members. If doing this, the number of search results should be increased from 1!

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

 

Dilbert of the day