Announcement

Collapse
No announcement yet.

script to email computer name

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • script to email computer name

    I'm trying to create a script file that will get the local machine name and send an email from one acount to another with the local machine name as the subject...

    I can get the local machine name from another post to output to the screen and I can send an email with a script from the accounts I want, but I can't manipulate the subject line with information that is variable (such as the local machine name). Do you have any suggestions?

  • #2
    can you post you're current script (with comment please)?

    please use the code buttons when posting you're script.
    also, tell me which language you use..
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Here is the code for the email:

      Code:
      Set objEmail = CreateObject("CDO.Message")
      objEmail.From = "[email protected]"
      objEmail.To = "[email protected]"
      objEmail.Subject = "Test EMail" 
      objEmail.Textbody = "Just checking to see if this thing works."
      objEmail.Send
      Here is the code to get the computer name (from a previous post):
      Code:
      Set objAdsSystemInfo =   CreateObject("adsysteminfo") 
      Set objComputerName =   Getobject("LDAP://" & objAdsSystemInfo.ComputerName) 
      strHostName = UCase(replace(objComputerName.Name,"CN=","")) 
      WScript.Echo "MY HOST NAME IS: " & strHostName
      What I'd like to do is generate an email where the subject is the output of the latter script (the computer name)...

      Right now I've already used the latter script to write the machine name to a text file and each machine that runs the script appends its machine name to the end of the text file... that will suffice, but to be really slick, I'd like to get it to email me with the machine name as the subject...

      Comment


      • #4
        why making it so hard:

        Code:
        Set objAdsSystemInfo =   CreateObject("adsysteminfo") 
        Set objComputerName =   Getobject("LDAP://" & objAdsSystemInfo.ComputerName) 
        Set objEmail = CreateObject("CDO.Message") 
        
        strHostName = UCase(replace(objComputerName.Name,"CN=","")) 
        WScript.Echo "MY HOST NAME IS: " & strHostName
        
        objEmail.From = "[email protected]" 
        objEmail.To = "[email protected]" 
        objEmail.Subject = "Test EMail" & " " & strHostName
        objEmail.Textbody = "Just checking to see if this thing works." 
        objEmail.Send
        or isn't this where you looking for?
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Thanks, after looking at it I realized how blind I am. All I had to do was combine the scripts and use the strhostname variable as the subject line... Duh. Thanks for your help. You helped me connect a few dots in scripting as I'm rather new to it...

          Comment


          • #6
            ps.

            also declare you're variables like:

            Code:
            Option explicit
            Dim objAdsSystemInfo, objComputerName, objEmail, strHostName 
            
            Set objAdsSystemInfo =   CreateObject("adsysteminfo") 
            Set objComputerName =   Getobject("LDAP://" & objAdsSystemInfo.ComputerName) 
            Set objEmail = CreateObject("CDO.Message") 
            
            strHostName = UCase(replace(objComputerName.Name,"CN=","")) 
            WScript.Echo "MY HOST NAME IS: " & strHostName 
            
            objEmail.From = "[email protected]" 
            objEmail.To = "[email protected]" 
            objEmail.Subject = "Test EMail" & " " & strHostName 
            objEmail.Textbody = "Just checking to see if this thing works." 
            objEmail.Send
            otherwise, with large scripting, it can cause you troubles when you using double variable names, without you noticed it...
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment

            Working...
            X