.net in run book help

May 4, 2016
Reaction score
Hi , i am very new to this .net stuff i am trying to integrate some .net scripts within a Orchestrator run books

The bellow code seems to work but i get a this error when ever i run it through the run book and all my start and end subs seem to be in the right spot.

any help would be much apreciated

C:\Users\user\AppData\Local\Microsoft System Center 2012\Orchestrator\Activities\RunScript\hb-xeojs.0.vb(6,0) : error BC30289: Statement cannot appear within a method body. End of method assumed.C:\Users\user\AppData\Local\Microsoft System Center 2012\Orchestrator\Activities\RunScript\hb-xeojs.0.vb(44,0) : error BC30429: 'End Sub' must be preceded by a matching 'Sub'.

Imports System.DirectoryServices

Module Module1
Public Sub SetADProperty(ByVal de As DirectoryEntry, ByVal pName As String, ByVal pValue As String)
If Not pValue Is Nothing Then
If de.Properties.Contains(pName) Then 'The DE contains this property
de.Properties(pName)(0) = pValue
End If
End If
End Sub
Public Function GetDirectoryEntry() As DirectoryEntry
Dim dirEntry As New DirectoryEntry("LDAP://mydomain")
dirEntry.Username = Nothing
dirEntry.Password = Nothing
dirEntry.AuthenticationType = AuthenticationTypes.Secure
Return dirEntry
End Function
Public Sub UpdateUserADAccount(ByVal userLogin As String, ByVal userDepartment As String, ByVal userTitle As String, ByVal userPhoneExt As String)
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectCategory=Person)(objectClass=user) (SAMAccountName=" & userLogin & "))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim searchResults As SearchResult = dirSearcher.FindOne()
If Not searchResults Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(searchResults.Path)
SetADProperty(dirEntryResults, "department", userDepartment)
SetADProperty(dirEntryResults, "title", userTitle)
SetADProperty(dirEntryResults, "phone", userPhoneExt)
End If
End Sub
Sub Main()
UpdateUserADAccount("Testuser", "HR", "Noone", "000")
End Sub
End Module


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question