Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Get computer name as variable to use in vbs script.

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-04-2009
spacemancw
 
Posts: n/a
Get computer name as variable to use in vbs script.


I have the following script below. I didn't write it. It finds Storage
groups, mail and public stores and paths on exchange 2003.
But it starts with a dialog box asking the user for tha name of the
server.
I want to have it run automatically unattended.
I want to get rid of the first two lines and define 'strServer' as a
variable that the script can find no matter what the name of the
server I put it on.

For example:

strServer=getTheNameOfThisServer.

So that I can use strServer later on in the script. How do I do that?
Thanks

===========================

strTitle="Mailbox Storage DB Report"
strServer=InputBox("What is the name of the Exchange
Server?",strTitle,"TANK")




SGReport strServer
WScript.Quit

Sub SGReport(strServer)
Dim iServer
Dim iSGs
Dim iMBS

Set iServer=CreateObject("CDOEXM.ExchangeServer")
Set iSGs=CreateObject("CDOEXM.StorageGroup")
Set iMBs=CreateObject("CDOEXM.MailboxStoreDB")
Set iMPs=CreateObject("CDOEXM.PublicStoreDB")
iServer.DataSource.Open strServer

On Error Resume Next

arrSGs=iServer.StorageGroups

For i=0 To UBound(arrSGs)
strSGUrl=arrSGs(i)
'WScript.Echo strSGUrl
iSGs.DataSource.Open "LDAP://" & iServer.DirectoryServer &
"/" & strSGUrl
strData=strData & iSGs.Name & vbcrlf
strData=strData & " LogPath: " &iSGs.LogFilePath & VBCRLF
strData=strData & " SysPath: " & iSGs.SystemFilePath &
VBCRLF & VBCRLF

arrPFStores=iSGs.PublicStoreDBs
For j=0 To UBound(arrPFStores)
iMPS.DataSource.open "LDAP://" & arrPFStores
(j)
strData=strData & " " & iMPS.Name& vbTab & " Path:" &
iMPS.DBPath&vbcrlf

next

Next





For k=0 To UBound(arrSGs)
strSGUrl=arrSGs(k)
'WScript.Echo strSGUrl
iSGs.DataSource.Open "LDAP://" & iServer.DirectoryServer &
"/" & strSGUrl
strData=strData & iSGs.Name & vbcrlf
strData=strData & " LogPath: " &iSGs.LogFilePath & VBCRLF
strData=strData & " SysPath: " & iSGs.SystemFilePath &
VBCRLF & VBCRLF



arrMBStores=iSGs.MailboxStoreDBs
For m=0 To UBound(arrMBStores)
iMBS.DataSource.open "LDAP://" & arrMBStores
(m)
strData=strData & " " & iMBS.Name& vbTab & "
Path:" & iMBS.DBPath&vbcrlf




Next


Next

WScript.Echo strData

End sub


===========================



Reply With Quote
  #2  
Old 28-04-2009
Pegasus [MVP]
 
Posts: n/a
Re: Get computer name as variable to use in vbs script.

Have a look at the wsshell.ExpandEnvironmentStrings method of the
WScript.Shell object. There is a complete example in the downloadable help
file script56.chm. The computer name is available as %ComputerName%.
Alternatively you'll find the computer name under the Wscript.Network
object.
Reply With Quote
  #3  
Old 29-04-2009
spacemancw
 
Posts: n/a
Re: Get computer name as variable to use in vbs script.

I added this to the top of the script

Set wshShell = Wscript.CreateObject( "Wscript.Shell" )
WScript.Echo "HOSTNAME: " & wshShell.ExpandEnvironmentStrings
( "%COMPUTERNAME%" )
WScript.Echo "DOMAIN : " & wshShell.ExpandEnvironmentStrings
( "%USERDOMAIN%" )
WScript.Echo ""


strServer=wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%"
Reply With Quote
  #4  
Old 29-04-2009
Pegasus [MVP]
 
Posts: n/a
Re: Get computer name as variable to use in vbs script.

Thanks for the feedback. Note that the following will work too:

wscript.echo wshShell.ExpandEnvironmentStrings("User=%UserName%,
PC=%COMPUTERNAME%" )
Reply With Quote
  #5  
Old 29-04-2009
T Lavedas
 
Posts: n/a
Re: Get computer name as variable to use in vbs script.

There is also the WSHNetwork object ...

Set WshNetwork = CreateObject("WScript.Network")
WScript.Echo "Domain = " & WshNetwork.UserDomain
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
WScript.Echo "User Name = " & WshNetwork.UserName
Reply With Quote
  #6  
Old 30-01-2010
Member
 
Join Date: Jan 2010
Posts: 2
Re: Get computer name as variable to use in vbs script.

Once you capture the name of the computer using any of the forementioned methods, how do you read the first 3 characters of the name?

For example, I have a script that I want to run on specific clients. The hostname on those clients start with the city of where they are located.

L-A-pcname
S-F-pcname
N-Y-pcname

I am looking to not only capture the name but do an if else statement so that it reads the first 3 characters of the hostname and based on the city let it install what is needed.

In this case I want L-A-pcname so I am thinking

IF %computername% ISEQUAL "L-A"
continue with script
ELSE
GOTOEND

Last edited by El-Uapo : 30-01-2010 at 06:33 AM.
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Get computer name as variable to use in vbs script."
Thread Thread Starter Forum Replies Last Post
Need vbs script to add computer in the domain (OU ) lolo1790 Windows Server Help 10 04-03-2011 04:50 AM
How to Pass a Javascript variable to a PHP script leshaspar Software Development 4 24-11-2010 09:48 AM
Bash script to import variable configuration Anja Software Development 5 23-08-2010 08:12 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM
Exporting environment variable from a bash script Unix'EM Software Development 3 06-08-2009 05:52 PM


All times are GMT +5.5. The time now is 08:03 AM.