Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Generate usernames from Hostnames.

Reply
Thread Tools Display Modes

Generate usernames from Hostnames.

 
 
sudhi_shrivatsa
Guest
Posts: n/a

 
      11-13-2009
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....
 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      11-13-2009

"sudhi_shrivatsa" <> wrote in
message news: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!


 
Reply With Quote
 
sudhi_shrivatsa
Guest
Posts: n/a

 
      11-13-2009
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" <> wrote in
> message news: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!
>
>
> .
>

 
Reply With Quote
 
sudhi_shrivatsa
Guest
Posts: n/a

 
      11-13-2009
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
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renamin the username's username JKL Windows Vista Administration 0 01-23-2008 04:24 PM
passwords and usernames MRFOSTER Windows Vista Administration 3 10-03-2007 09:41 PM
Can't generate system health report + problem device Ralph Windows Vista Hardware 0 07-28-2007 01:10 AM
No numeric usernames? Thomas Hacker Windows Vista Administration 0 06-29-2006 07:13 AM
How can I generate a verbose Install log during Vista Setup Regina_SK_Canada Windows Vista Installation 0 06-14-2006 04:46 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59