March 4, 2010

Script to set AD targetAddress property to forward Email during a Transition to new Domain

Filed under: General Development,Information Technology — Tags: , , , — Tim Lefler @ 9:07 am

My company was moving from our in house email system to a completely new infrastructure with a new email domain name and a new Active Directory domain.  The plan was to have users configure a new Outlook profile to connect to the new system at a particular time on the migration day.  Because we have little control over when the users will actually make the transition, I want to make sure any new emaill that arrived at the old mailbox would get forwarded to the new mailbox.  This would help cover the straggler users who keep sending email to users who had already migrated.

So this script does exactly that…. it takes a list of distinguished names in an input file, connects to active directory and sets the Active Directory attribute for “targetAddress”.  This will essentially forward the mail to the targetAddress SMTP location.

The input file can be easily generated with a CSVDE command:

C:\csvde -f input.csv -d "dc=domain,dc=com" -r "(ObjectCategory=Person)" -l "DN"
Connecting to "(null)"
Logging in as current user using SSPI
Exporting directory to file input.csv
Searching for entries...
Writing out entries
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
...........................................
Export Completed. Post-processing in progress...
763 entries exported
 
The command has completed successfully

Then you can run this script to read it in and make the changes the the mail enabled active directory objects. (more…)

January 4, 2010

Reading Registry using VB.Net

Filed under: General Development — Tags: , — Tim Lefler @ 4:46 pm

I quick code snippet on how to read the registry using VB.Net

Imports Microsoft.Win32
 
Public Class Somethiing
      Public Sub New() 
           Dim txtRegistryValue as String
           txtRegistryValue = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Company\SomeKey", "RegistryValueName", Nothing)
      End Sub
End Class

Retrieves the value associated with the specified name, in the specified registry key. If the name is not found in the specified key, returns a default value that you provide, or nullNothingnullptra null reference (Nothing in Visual Basic) if the specified key does not exist.
Parameters

keyName
Type: System..::.String
The full registry path of the key, beginning with a valid registry root, such as “HKEY_CURRENT_USER”.

valueName
Type: System..::.String
The name of the name/value pair.

defaultValue
Type: System..::.Object
The value to return if valueName does not exist.

Return Value
Type: System..::.Object
nullNothingnullptra null reference (Nothing in Visual Basic) if the subkey specified by keyName does not exist; otherwise, the value associated with valueName, or defaultValue if valueName is not found.

References:
http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.getvalue.aspx

Powered by WordPress