February 23, 2010

csvde Command to show disabled accounts

Filed under: Information Technology — Tags: , , , , , , — Tim Lefler @ 4:53 pm

For audit purposes I needed to list all active directory users and prove that ex-employees were either deleted of disabled. There are a couple of techniques to produce the required output. I think the easiest was to make use of the csvde.exe.

Arguements for csvde.exe

CSV Directory Exchange
 
General Parameters
==================
-i              Turn on Import Mode (The default is Export)
-f filename     Input or Output filename
-s servername   The server to bind to (Default to DC of computer's domain)
-v              Turn on Verbose Mode
-c FromDN ToDN  Replace occurences of FromDN to ToDN
-j path         Log File Location
-t port         Port Number (default = 389)
-u              Use Unicode format
-?              Help
 
Export Specific
===============
-d RootDN       The root of the LDAP search (Default to Naming Context)
-r Filter       LDAP search filter (Default to "(objectClass=*)")
-p SearchScope  Search Scope (Base/OneLevel/Subtree)
-l list         List of attributes (comma separated) to look for in an
                LDAP search
-o list         List of attributes (comma separated) to omit from input.
-g              Disable Paged Search.
-m              Enable the SAM logic on export.
-n              Do not export binary values
 
 
Import
======
-k              The import will go on ignoring 'Constraint Violation' and
                'Object Already Exists' errors
 
 
Credentials Establishment
=========================
Note that if no credentials is specified, CSVDE will bind as the currently
logged on user, using SSPI.
 
-a UserDN [Password | *]            Simple authentication
-b UserName Domain [Password | *]   SSPI bind method
 
Example: Simple import of current domain
    csvde -i -f INPUT.CSV
 
Example: Simple export of current domain
    csvde -f OUTPUT.CSV
 
Example: Export of specific domain with credentials
    csvde -m -f OUTPUT.CSV
          -b USERNAME DOMAINNAME *
          -s SERVERNAME
          -d "cn=users,DC=DOMAINNAME,DC=Microsoft,DC=Com"
          -r "(objectClass=user)"
No log files were written.  In order to generate a log file, please
specify the log file path via the -j option.

So to display whether a user is disabled or not we need to extract the “userAccountControl” property.
(more…)

October 6, 2009

How to use SharePoint Elevated Privileges to set security on an item

I needed to develop the ability for a SharePoint workflow to modify permission’s on a list item.  In my case, after an approval workflow was instantiated I did not want a document item to be modified.  So I wanted to be able to break inheritance and set custom permissions for the individual list item.  This is somewhat complicated by the fact that the user who initiates the workflow doesn’t have permission to modify permissions.  Thankfully, SharePoint has the ability to execute code with Elevated Privileges.  So I encapsulated this functionality in a class so I could make use of it elsewhere. This was an excellent blog post that pointed me in the right direction. I had to make a few modifications to fit my functionality and also had to serialize the class to prevent these nasty errors:

10/05/2009 09:28:55.67     w3wp.exe (0x167C)                           0x0D90    Windows SharePoint Services       Workflow Infrastructure           98d4    Unexpected    System.Workflow.Runtime.Hosting.PersistenceException: Type ‘Microsoft.SharePoint.SPWeb’ in Assembly ‘Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ is not marked as serializable. —> System.Runtime.Serialization.SerializationException: Type ‘Microsoft.SharePoint.SPWeb’ in Assembly ‘Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ is not marked as serializable.     at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)     at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)     at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()     at System.Runtime.Serialization.Formatters.B…

Here is my class.

(more…)

September 3, 2009

Technique for Copying a SharePoint Document Library Item to another Document Library

Filed under: Development — Tags: , , , , , , , — Tim Lefler @ 12:57 pm

This was kind of more difficult than I would have expected.  This is the technique I’ve been able to use successfully to copy document library list items from one list to another.  I had to work through a number of problems including a confusing error from Visual Studio: “To add an item to a document library, use SPFileCollection.Add()”

SPFileCollection?  WTF, I thought I was dealing with a List!!

Below is the coding technique I finally was able to get to work.

  • Add a new file to the document library first using the SPFileCollection class.
  • From the file get the SPListItem object for the new item
  • Update the fields of the new list item
  • Use newitem.Update to commit the changes
' Code to COPY a document library list item to a new document library List
 ' Get a reference to the destination List.
 Dim destlist As SPList = workflowProperties.Web.Lists("Destination")
 Dim sourceitem As SPListItem = workflowProperties.Item
 Dim filebytes As Byte()
 Dim newitem As SPListItem
 
' Gets the source file from the source list
 Dim thefile As SPFile = sourceitem.File
 Dim ct As SPContentType
 Dim field As SPField
 Dim destrelativeurl As String = destlist.RootFolder.Url & "/" & sourceitem.File.Name
 
 ' Suck the source file into binary array
 filebytes = sourceitem.File.OpenBinary
 
 ' This creates an entry in the destination list and returns SPFile obj
 thefile = destlist.RootFolder.Files.Add(destrelativeurl, filebytes, True)
 ' We can now use the SPFile obj to get the new list entry.
 newitem = thefile.Item
 
 ' cycle through each of the fields setting them to be the same if the
 ' are fields that are not Read Only
 For Each field In sourceitem.Fields
     If Not field.ReadOnlyField Then
         Try
             ' Set the matching field in the destination list
             ' The Source list might not have the same number of columns so we enclose this
             '  in a TRY so that if a column doesn't exist in the destination it continues.
             newitem(field.Title) = sourceitem(field.Title)
         End Try
      End If
 Next
 ' Commit the changes
 newitem.Update()

Many thanks to this blog post for pointing me in the right direction

July 28, 2009

How to Import External Data into a SharePoint list using SQL Server Integration Services

Filed under: Sharepoint — Tags: , , , , , , , — Tim Lefler @ 12:51 pm

Recently I wanted to be able to take data from an external source and populate an existing SharePoint list.  The intent was to quickly get some customer data pre-loaded into the Call Center Application template available from Microsoft. For new custom lists SharePoint does this out of the box with the “Import Spreadsheet” option.

ImportSpreadsheet

Unfortunately, this doesn’t help us out for an existing list that was part of the Call Center Microsoft application template.  So I Googled around for a bit and explored options that included BDC definitions and writing custom code to interact the the SharePoint API.  It seemed so complicated.  Shouldn’t this be easier?  (more…)

Powered by WordPress