Home All Groups Group Topic Archive Search About

Get computer name as variable to use in vbs script.

Author
28 Apr 2009 12:08 PM
spacemancw
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


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

Author
28 Apr 2009 12:28 PM
Pegasus [MVP]
Show quote Hide quote
"spacemancw" <spacema***@yahoo.com> wrote in message
news:45d61304-64df-4401-9a77-36aee13d39d6@z16g2000prd.googlegroups.com...
>
> 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
>
>
> ===========================
>

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.
Author
28 Apr 2009 7:18 PM
spacemancw
Show quote Hide quote
On Apr 28, 8:28 am, "Pegasus [MVP]" <n***@microsoft.com> wrote:
> "spacemancw" <spacema***@yahoo.com> wrote in message
>
> news:45d61304-64df-4401-9a77-36aee13d39d6@z16g2000prd.googlegroups.com...
>
>
>
>
>
>
>
> > 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
>
> > ===========================
>
> 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.- Hide quoted text -
>
> - Show quoted text -

Thanks

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%" )
Author
28 Apr 2009 7:55 PM
Pegasus [MVP]
"spacemancw" <spacema***@yahoo.com> wrote in message
news:312b8613-6406-419f-8c0a-Thanks

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%" )

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

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

wscript.echo wshShell.ExpandEnvironmentStrings("User=%UserName%,
PC=%COMPUTERNAME%" )
Author
28 Apr 2009 8:46 PM
T Lavedas
On Apr 28, 3:18 pm, spacemancw <spacema***@yahoo.com> wrote:
Show quoteHide quote
> On Apr 28, 8:28 am, "Pegasus [MVP]" <n***@microsoft.com> wrote:
>
>
>
> > "spacemancw" <spacema***@yahoo.com> wrote in message
>
> >news:45d61304-64df-4401-9a77-36aee13d39d6@z16g2000prd.googlegroups.com....
>
> > > 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
>
> > > ===========================
>
> > 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.- Hide quoted text -
>
> > - Show quoted text -
>
> Thanks
>
> 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%" )

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

Tom Lavedas
***********
http://there.is.no.more/tglbatch/