Tom,
You are close.
It should only remove the first zero from the numeric part.
Eg. file0123
username = user123
----------------------------------------------------
file00123
username = user123.
-------------------------------------------------
file1023
username = user1023.
-----------------------------------------------------------
Hope this is good now.
Sudhi...
"Tom Lavedas" wrote:
> On Nov 13, 10:07 am, sudhi_shrivatsa
> <sudhishriva...@discussions.microsoft.com> wrote:
> > Pefasus your understanding is correct. I cant help you on wisdom of the
> > scheme. Its is already set here. The admin account on these are set like
> > this. 200 Machines one common admin password but admin username is derived
> > from the hostname. with following criteria.
> > eg
> > Hostname = file456
> > Admin user = user456
> > password = common123
> > ------------------------------------------------------------------
> > Hostname = file1456
> > Admin user = user1456
> > password = common123
> > ------------------------------------------------------------------
> > Hostname = file0456
> > Admin user = user456
> > password = common123
> > -------------------------------------------------------------------
> > a) Remove all leading non-numeric characters and replace them with the word
> > "user".
> > b)In all cases, suppress all leading 0s.
> >
> > All are local admins on the servers. Hope this information adds some more
> > light.
> >
> > Now I have to run a script from one of these machine which will fetch the
> > server names from one text file and logon remotely and run a specific command
> > add the output to one text file. Rest all is done but i am stuck at
> > generating username from the server name.
> >
> > Let me know if you need any more info on this.
> >
> > Thanks
> > Sudhi...
> >
> > "Pegasus [MVP]" wrote:
> >
> > > "sudhi_shrivatsa" <sudhishriva...@discussions.microsoft.com> wrote in
> > > messagenews:AD36A097-B24F-4952-9CAF-...
> > > > Hi ,
> >
> > > > I want to generate username from the hostname.
> > > > For example if the hostname is "test2345" then username should be
> > > > "user2345".
> > > > "user" should be prefixd to the numbers from the hostname.
> >
> > > > where "user" is common for all the servers.
> >
> > > > If the hostname is "test0123" it should omit 0 and only take the later
> > > > part.
> > > > It will be something like this then "user234".
> >
> > > > Can i achive this from a VBSCript. If yes please let me know how.
> >
> > > > Thanks in advance.
> > > > Sudhi....
> >
> > > You need to nail down your requirements in greater detail. According to your
> > > post the following interpretations are possible:
> > > a) Remove the first four characters from the host name and replace it with
> > > the word "user".
> > > b) Remove all leading non-numeric characters and replace them with the word
> > > "user".
> > > c) Take the last four characters and put the word "user" in front.
> > > d) Take the trailing digits and put the word "user" in front.
> > > e) In all cases suppress the first number if it is a 0.
> > > f) In all cases, suppress all leading 0s except the last one.
> > > g) In all cases, suppress all leading 0s.
> > > I also wonder about the wisdom of the scheme. If you have two users using
> > > one machine then you would get identical user names . . . Time to put on the
> > > thinking cap!
> >
> > > .
>
> If you are just looking for the string manipulation part of the
> problem, a regular expression can be used, something like this (in
> VBS) ...
>
> sHostName = "file0123"
> ' Locate first occurrence of a digit other than zero
> nPos = RegExpPos("[1-9]", sHostName)
> if nPos > 0 and nPos <= Len(sHostName) then
> sUserName = "user" & Mid(sHostName, nPos)
> wsh.echo sHostName, "=>", sUserName
> else
> wsh.echo "Unable to parse Hostname", sHostName
> end if
>
> Function RegExpPos(patrn, strng)
> Dim regEx, Match, Matches, RetPos ' Declare variables.
> Set regEx = New RegExp ' Create regular expression.
> regEx.Pattern = patrn ' Set pattern.
> regEx.IgnoreCase = True ' Set case insensitivity.
> regEx.Global = false ' Set non-global applicability.
> Set Matches = regEx.Execute(strng) ' Execute search.
> if Matches.count > 0 then
> RetPos = Matches(0).FirstIndex + 1
> else
> RetPos = 0
> end if
> RegExpPos = RetPos
> End Function
>
> Note that this approach removes all the leading zeros in the numeric
> part, not just the first one. That possibility is not mentioned as
> part of your description, so I didn't worry about it. To do
> otherwise, is noticeably more complex.
> _____________________
> Tom Lavedas
> .
>
|