Add Hostname variable in a vbs script

Home Forums Scripting Windows Script Host Add Hostname variable in a vbs script

This topic contains 2 replies, has 2 voices, and was last updated by Avatar vonPryz 8 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    L4ndy
    Member
    #151979

    Hi there,

    I’ve got the following script:

    Set objEmail = CreateObject(“CDO.Message”)
    objEmail.From = “[EMAIL=”[email protected]”][email protected][/EMAIL]”
    objEmail.To = “[EMAIL=”[email protected]”][email protected][/EMAIL]”
    objEmail.Subject = “Server down”
    objEmail.Textbody = “Server1 is no longer accessible over the network.”
    objEmail.Configuration.Fields.Item _
    (“[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]”) = 2
    objEmail.Configuration.Fields.Item _
    (“[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]”) = _
    “smarthost”
    objEmail.Configuration.Fields.Item _
    (“[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]”) = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send

    [/CODE]

    I need to put in a variable of the hostname in either the Subject title or in the text body.
    I believe strHostName can be used but I don’t know how.

    Can anyone help?

    Tia[CODE]
    Set objEmail = CreateObject(“CDO.Message”)
    objEmail.From = “[email protected]
    objEmail.To = “[email protected]
    objEmail.Subject = “Server down”
    objEmail.Textbody = “Server1 is no longer accessible over the network.”
    objEmail.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2
    objEmail.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = _
    “smarthost”
    objEmail.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send

    [/CODE]

    I need to put in a variable of the hostname in either the Subject title or in the text body.
    I believe strHostName can be used but I don’t know how.

    Can anyone help?

    Tia

    Avatar
    vonPryz
    Member
    #347514

    Re: Add Hostname variable in a vbs script

    Use Wscript.Network like so,

    Code:
    Set WshNetwork = WScript.CreateObject(“WScript.Network”)
    WScript.Echo WshNetwork.ComputerName

    Thus, change your script to catenate computer name into the subject string:

    Code:
    Set WshNetwork = WScript.CreateObject(“WScript.Network”)
    objEmail.Subject = “Server ” & WshNetwork.ComputerName & ” is down”

    As usual, thanks go to Guy Thomas.

    -vP

    Avatar
    L4ndy
    Member
    #276915

    Re: Add Hostname variable in a vbs script

    Thanks -vP,

    That worked a treat.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Register for this Petri Webinar!

Want to Make Your Backup Storage Unlimited & Ready for the Cloud? – Free Thurrott Premium Account with Webinar Registration!

Tuesday, August 27, 2019 @ 1:00 pm EDT

A Scale-Out Backup storage infrastructure is a must-have technology for your backups. In this webinar, join expert Rick Vanover for a look on what real-world problems are solved by the Scale-Out Backup Repository.

Register Now

Sponsored By