Question : Script to email newly created computers. Need to add groups & users accounts also.

Hi,

Script to email newly created computers. Need to add groups & users accounts also.
Can this be added. With seperate headings and just the object names below each hheader.

regards
sharath
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
const SCHEDULER_TASK_NAME = "PcsEnumTask"
const SCHEDULER_TASK_START_TIME = "12:00:00"
const ROOT_OU = "ou=CHANGE_ROOT_OU,"

dim LogResult,args
Dim objShell : Set objShell = CreateObject("WScript.Shell")
Dim strOutput : strOutput = objShell.Exec("schtasks /query /fo list").StdOut.ReadAll

if InStr(data, SCHEDULER_TASK_NAME) = 0 then
        WScript.Echo SCHEDULER_TASK_NAME & " found.."
end if

if InStr(strOutput, SCHEDULER_TASK_NAME) = 0 then
        WScript.Echo "Create task scheduler [" & SCHEDULER_TASK_NAME & "]..."
        'create task scheduler
        args = "schtasks /Create /F /SC DAILY /TN " & SCHEDULER_TASK_NAME & " /TR """ & Wscript.ScriptFullName & """ /ST " & SCHEDULER_TASK_START_TIME
		WScript.Echo "args: " & args
		objShell.Run args, 1, True

        WScript.Echo "Task scheduler [" & SCHEDULER_TASK_NAME & "] created successfully"
else
        'numertae pcs and email
        EnumPcs
        EmailResult
end if

Sub EmailResult
dim ToAddress,MessageSubject,MessageBody
	ToAddress = "contact1,contact2"
	MessageSubject = "Enum Pcs report..."
	MessageBody = "*BODY* email via MAPI *BODY*"

	Set ol = WScript.CreateObject("Outlook.Application")
	Set ns = ol.getNamespace("MAPI")
	ns.logon "","",true,false
	Set newMail = ol.CreateItem(olMailItem)
	newMail.Subject = MessageSubject
	newMail.Body = MessageBody & vbCrLf

	' validate the recipient, just in case...
	Set myRecipient = ns.CreateRecipient(ToAddress)
	myRecipient.Resolve
	If Not myRecipient.Resolved Then
	   MsgBox "unknown recipient"
	Else
	   newMail.Recipients.Add(myRecipient)
	   newMail.Send
	End If

Set ol = Nothing


End Sub

Sub EnumPcs
        dtmDate = Now
         
        strYear = Right(Year(dtmDate), 2)
        strMonth = Month(dtmDate)
        If Len(strMonth) < 2 Then strMonth = "0" & strMonth
        strDay = Day(dtmDate)
        If Len(strDay) < 2 Then strDay = "0" & strDay
         
        strStartDate = strYear & strMonth & strDay & "000000Z"
        strEndDate = strYear & strMonth & strDay & "235959Z"
         
        strFilter = "(&(createTimeStamp>=" & strStartDate & ")(createTimeStamp<=" & strEndDate & ")(objectCategory=computer))"

        Set objConnection = CreateObject("ADODB.Connection")
        objConnection.Provider = "ADsDSOObject"
        objConnection.Open "Active Directory Provider"
         
        Set objRootDSE = GetObject("LDAP://RootDSE")
        Set objRecordSet = objConnection.Execute( _
          "<LDAP://" & ROOT_OU & objRootDSE.Get("defaultNamingContext") & ">;" & _
          strFilter & ";distinguishedName,name,createTimeStamp;subtree")
        Set objRootDSE = Nothing
         
        While Not objRecordSet.EOF
          dtmCreateTimeStamp = CDate(objRecordSet.Fields("createTimeStamp").Value)
          strMessage = objRecordSet.Fields("distinguishedName").Value & VbCrLf & _
                objRecordSet.Fields("name") & VbCrLf & _
                objRecordSet.Fields("createTimeStamp")
         
          LogResult = LogResult & strMessage & vbcrlf 
          objRecordSet.MoveNext
        WEnd

End Sub

Answer : Script to email newly created computers. Need to add groups & users accounts also.

you don't need the 'ref' because you already returning a value...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
class Program
    {
        static void Main(string[] args)
        {
            int fib = 20;
            fib = computeFibonacci(fib); Console.WriteLine(fib);
            fib = 20;
            fib = computeFibonacciRecursive(fib); Console.WriteLine(fib);
        }

        private static int computeFibonacciRecursive(int n)
        {
            if (n <= 1)
            {
                return n;
            }
            else
            {
                return computeFibonacciRecursive(n - 1) + computeFibonacciRecursive(n - 2);  //<------
            }
        }

        private static int computeFibonacci(int n)
        {
            int a = 1, b = 1;
            for (int i = 3; i <= n; i++)
            {
                int c = a + b;
                a = b;
                b = c;
                Console.WriteLine("b is= " + b);
            }
            return b;
        }

    }
Random Solutions  
 
programming4us programming4us