Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Generate usernames from Hostnames.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sudhi_shrivatsa  
View profile  
 More options Nov 13 2009, 1:36 pm
Newsgroups: microsoft.public.windows.server.scripting
From: sudhi_shrivatsa <sudhishriva...@discussions.microsoft.com>
Date: Fri, 13 Nov 2009 05:36:01 -0800
Local: Fri, Nov 13 2009 1:36 pm
Subject: Generate usernames from Hostnames.
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....


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pegasus [MVP]  
View profile  
 More options Nov 13 2009, 1:53 pm
Newsgroups: microsoft.public.windows.server.scripting
From: "Pegasus [MVP]" <n...@microsoft.com>
Date: Fri, 13 Nov 2009 14:53:44 +0100
Local: Fri, Nov 13 2009 1:53 pm
Subject: Re: Generate usernames from Hostnames.

"sudhi_shrivatsa" <sudhishriva...@discussions.microsoft.com> wrote in
message news:AD36A097-B24F-4952-9CAF-A31E36133A73@microsoft.com...

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!

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sudhi_shrivatsa  
View profile  
 More options Nov 13 2009, 3:07 pm
Newsgroups: microsoft.public.windows.server.scripting
From: sudhi_shrivatsa <sudhishriva...@discussions.microsoft.com>
Date: Fri, 13 Nov 2009 07:07:03 -0800
Local: Fri, Nov 13 2009 3:07 pm
Subject: Re: Generate usernames from Hostnames.
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...


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Lavedas  
View profile  
 More options Nov 13 2009, 3:39 pm
Newsgroups: microsoft.public.windows.server.scripting
From: Tom Lavedas <tglba...@cox.net>
Date: Fri, 13 Nov 2009 07:39:49 -0800 (PST)
Local: Fri, Nov 13 2009 3:39 pm
Subject: Re: Generate usernames from Hostnames.
On Nov 13, 10:07 am, sudhi_shrivatsa

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sudhi_shrivatsa  
View profile  
 More options Nov 13 2009, 4:23 pm
Newsgroups: microsoft.public.windows.server.scripting
From: sudhi_shrivatsa <sudhishriva...@discussions.microsoft.com>
Date: Fri, 13 Nov 2009 08:23:01 -0800
Local: Fri, Nov 13 2009 4:23 pm
Subject: Re: Generate usernames from Hostnames.
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...


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Lavedas  
View profile  
 More options Nov 13 2009, 4:58 pm
Newsgroups: microsoft.public.windows.server.scripting
From: Tom Lavedas <tglba...@cox.net>
Date: Fri, 13 Nov 2009 08:58:41 -0800 (PST)
Local: Fri, Nov 13 2009 4:58 pm
Subject: Re: Generate usernames from Hostnames.
On Nov 13, 11:23 am, sudhi_shrivatsa

OK, so multiple zeros ARE a problem.  It turns out the solution was a
lot easier than I first imagined or I might have addressed before.

Try this, instead ...

sHostName = "file00123"
nPos = RegExpPos("\d", 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
      if Matches(0).Value = "0" then RetPos = RetPos + 1
   else
      RetPos = 0
   end if
   RegExpPos = RetPos
End Function

BTW, the \d pattern is shorthand for [0-9] - match all digits.
_____________________
Tom Lavedas


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google