|
|
|||||||
Our logon script is providing a local machine and selected services password change and then moves on to look at the computer workstation name. The name is checked against a MS Access Database. If the name is an old name, it gets changed to the new name using a shell command with NetDom. No problems at the moment as it is working fine... We found out that we have to alter our naming convention for a selected group of computers. This brings 2 problems. First is the prefix and secondly is the number. We have to use a 5 digit number. In the code below, hopefuly you will be able to see that we parse the machine name, change the number string to an integer, do a counter loop to increment the workstation number then piece it back together with the prefix for a total name: Code:
We now need to add NSSFNW to the naming convetion. I am thinking a switch will do the job for that. However, when we go to NSSFNW, the workstation count needs to start at 00001 and increment from there. I am not sure how to get the number to hold 5 places. I did cheat when I did the NSNCPW. We arleady have over 1000 workstations so I added a 0 to the name and then just used the counter to add one. Can anyone provide some suggestions? Thanks! |
||||||||
|
|
|||||||
Code:
|
||||||||
|
|
|||||||
Code:
|
||||||||
|
|
|||||||
No need to make it that complicated: Code: $sZeroFilled=Right("00000"+$iNumber,5) |
||||||||
|
|
|||||||
Quote: simple and effective. i wish i would have known more about the right(). Do you think a case is the best way to go with the prefix for seperation? I have a hunch we are going to change several machine names prefix, depending on the command (military) that owns them. |
||||||||
|
|
|||||||
well, i must not be smart enough to figure this out on my own...yet. The system is working with the add 1 on the number but here is the new challenge and I can't figure it out. Let's say that the number goes from 00001, 00002, 00003, 00005, 00006, etc. The way the script is running through the record set, it is telling us that 00006 is the highest number and the new assigned number will be 00007. We want to catch 00004 and assign the machine to that number. This way we won't have huge gaps in the numbering sequence. I looked at using an array instead of an if statement but cant figure out how to get the 00004 value. Could you shed some light on this??? |
||||||||
|
|
|||||||
Well... maybe you need to explain yourself better cuz I am not sure I understand. The value of 00004 was known to you before you converted it to a string by padding with zeros so you should already know its value. Otherwwise, you can use Val() to get it again. |
||||||||
|
|
|||||||
Quote: I am terrible at explaining so let me give it another go Looking at the first post, the code runs through the recordset. In the process it parses the record and we then look at the numeric piece Code: Right($record1,5) Next we use the if statement to find the high number when the records are being run. I don't really know what the record information is except a bunch of numbers. When we built the database, it was populated with all of our workstations old names and they were assigned new names. The script is looking at this database to get the new name. The problem I found was the new name of approximately 200 "unknown old name" computer need a different naming convention and have to start at 00001. So, what I am attempting to do is to avoid creating a new record for the existing workstation entry. First, we identify the workstation and then we give it the proper prefix and then we have to give it the numeric value. We know that some computer names have been assigned with a number like 00005. Using the script as it shows in the first post, the next assigned number will be 00006. While this is a true statement, we want it to be assigned to the first free number (hypothetical) of 00004. So, I have been trying to figure out how to capture the low free number and high free number. If the low number exists or matches the high number, use it. I hope this helps a little... |
||||||||
|
|
|||||||
Well, you already sort the records by the computername, so just compare each record to the previous one. If they differ by more than one then there is a gap. Here is one way of doing it: Code: $highNum = 0 [edit] Replaced the "EndIf" lost on the last line of the code during cut'n'paste. [/edit] |
||||||||
|
|
|||||||
You could use a SQL statement to identify missing sequence numbers by basically performing a self-join against itself and using the sequence number as paramerter, e.g. Code:
But why is this done in a login script and not via central admin script? Renaming workstations requires admin privs and a reboot anyway. |
||||||||
|
|
|||||||
Quote: Hi Richard, Thanks for this example. It works perfectly! |
||||||||
|
|
|||||||
Quote: This process is being done with the login script for our technician group only. Putting it in the login script, our techs log in and the script executes (matter of convenience and time savings). There are other requirements involved in our process that requires the tech to log on to every workstation on the installation. |