Quantcast
Channel: Software Communities : Popular Discussions - ActiveRoles
Viewing all articles
Browse latest Browse all 1277

VB to Powershell script conversion for ARS policy help request

$
0
0

I want to convert a couple of old vbs script to powershell. I have attempted to do this & am not making much progress as I am a newbie to scripting.

The script below will send out an email when a user account is created & it will include some information about the new user.

I have read about the utilization of the $Dirobj variables in the ARS SDK but have found the documentation difficult to follow.

Does anyone have some help available to get this converted?

 

Sub onPostCreate(Request)

          ' ********************************************************

          ' Set SMTP constants

          strCmdMailCC = ""

          strCmdMailFrom = "TestReport@test.local"

          strCmdMailTo = "ARSRocks@Test.local"

          constSmtpPort = 25

          constSmtpServer = "relayme.test.local"

          strCmdSubject = "User Account Created"

 

 

          If (LCase(Request.Class) <> "user") Then Exit Sub

 

 

          ' Obtain user data

          Dim objUser, strInitiator, strUserAdsPath

          Set objUser = GetObject("EDMS://" & request.name)

          objuser.getinfo

 

          '--- get object username (samAccountName)

          strSamName = CStr(Request.Get("samAccountName"))

 

          '--- get object userPrincipalName (userPrincipalName)

          strUPN = CStr(Request.Get("userPrincipalName"))

 

          '--- get object FirstName (givenName)

          strFirstName = CStr(Request.Get("givenName"))

 

          '--- get object Initials (initials)

          strInitials = CStr(Request.Get("initials"))

 

          '--- get object LastName (sn)

          strLastName = CStr(Request.Get("sn"))

 

          '--- get object Office (physicalDeliveryOfficeName)

          strOffice = CStr(Request.Get("physicalDeliveryOfficeName"))

 

          '--- get object Department (department)

          strDepartment = CStr(Request.Get("department"))

 

          '--- get object Email Address (mail)

          'strEmail = CStr(Request.Get("mail"))

 

 

          strCmdMsgText = objUser.Get("name") & " has been created via Active Roles Server<br>"

          'strCmdMsgText = strCmdMsgText & "Account Created by: " & strInitiator & "<br>"

          strCmdMsgText = strCmdMsgText & "Windows logon Name: " & strSamName & "<br>"

          strCmdMsgText = strCmdMsgText & "Email Address: " & strUPN & "<br>"

          strCmdMsgText = strCmdMsgText & "User First Name: " & strFirstName & "<br>"

          strCmdMsgText = strCmdMsgText & "User Initials: " & strInitials & "<br>"

          strCmdMsgText = strCmdMsgText & "User Last Name: " & strLastName & "<br>"

          strCmdMsgText = strCmdMsgText & "User Office: " & strOffice & "<br>"

          strCmdMsgText = strCmdMsgText & "User Department: " & strDepartment & "<br>"

 

          Email strCmdMailFrom,strCmdMailTo,strCmdSubject,strCmdMsgText,constSmtpServer

End Sub

 

 

' ********************************************************

' Email sent using CDO

Sub Email (strCmdMailFrom,strCmdMailTo,strCmdSubject,strCmdMsgText,constSmtpServer)

          Set objEmail = CreateObject("CDO.Message")

          objEmail.From = strCmdMailFrom

          objEmail.To = strCmdMailTo

          objEmail.Subject = strCmdSubject

          objEmail.HTMLBody = strCmdMsgText

          objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

          objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = constSmtpServer

          objEmail.Configuration.Fields.Update

          objEmail.Send

End Sub


Viewing all articles
Browse latest Browse all 1277

Trending Articles