|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading from file - batchThis is how my file containing list of users looks like (id username): 01 UserA 02 UserB 03 UserC .... I'm trying to write a batch file which could read the id of user whose name is passed as a parameter and save it to variable. I can find the line containing user's name: find "%1" UserB userlist.txt but how to save just user's id to variable ? Best regards, ABS Try something like this:
FOR /F "tokens=1" %x in ('find /i "userb" users.txt') do @set zuser=%x If you use this in a batch file change %x to %%x. -- Show quoteHide quoteJeffery Hicks Microsoft PowerShell MVP http://www.scriptinganswers.com http://www.powershellcommunity.org Now Available: WSH and VBScript Core: TFM Coming Soon: Windows PowerShell: TFM 2nd Ed. "abs" <nospam@wp.pl> wrote in message news:fh166n$phk$1@inews.gazeta.pl... > Hi everyone. > > This is how my file containing list of users looks like (id username): > > 01 UserA > 02 UserB > 03 UserC > ... > > I'm trying to write a batch file which could read the id of user whose > name > is passed as a parameter and save it to variable. I can find the line > containing user's name: > > find "%1" UserB userlist.txt > > but how to save just user's id to variable ? > > Best regards, > ABS > > > If by "ID" you mean the number in the first column, be careful about
treating it as if it were a number; the leading zero will flag it as an octal number, in which case 08 and 09 will result in errors. /Al Show quoteHide quote "Jeffery Hicks [MVP]" <jhi***@sapien.com> wrote in message news:8F5155A0-9AB1-43E4-922C-5E11A8A30675@microsoft.com... > Try something like this: > > FOR /F "tokens=1" %x in ('find /i "userb" users.txt') do @set zuser=%x > > If you use this in a batch file change %x to %%x. > > -- > Jeffery Hicks > Microsoft PowerShell MVP > http://www.scriptinganswers.com > http://www.powershellcommunity.org > > Now Available: WSH and VBScript Core: TFM > Coming Soon: Windows PowerShell: TFM 2nd Ed. > "abs" <nospam@wp.pl> wrote in message news:fh166n$phk$1@inews.gazeta.pl... >> Hi everyone. >> >> This is how my file containing list of users looks like (id username): >> >> 01 UserA >> 02 UserB >> 03 UserC >> ... >> >> I'm trying to write a batch file which could read the id of user whose >> name >> is passed as a parameter and save it to variable. I can find the line >> containing user's name: >> >> find "%1" UserB userlist.txt >> >> but how to save just user's id to variable ? >> >> Best regards, >> ABS >> >> >> > >> "save just user's id to variable " In the batch below;%1 set to static variable 'User' = "User name" (from command-line parameter) %1 reset to static variable 'User!' = "User_name" (no spaces) Dynamic Variable '%User!%' = userID Dynamic variable '%UserID%' = user name ::------------------------------------------------------ @echo off(Set User=%1) (Set User=%User:"=%) ||::> If exist, Erase quotes from parameter FOR /F "tokens=1 delims= " %%* in ('find /i "%User%" "c:\UID.txt"') Do ( set UserID=%%*) SetLocal (Call :RemoveSpaces %User: =_%)&(GoTo :EOF) :RemoveSpaces from original parameter (Set User!=%1)Goto :EndRemoveSpaces :EndRemoveSpaces <--- (Call Set %%User!%%=%UserID%) & (Call Set %%UserID%%=%User%):ShowResults echo.command-line parameter = "%User%" & echo.echo.Match: %UserID% %User% & echo: echo.&echo.Variables:&echo:_________________________________________ echo. (call echo %1=%%%1%%) ||::> show dynamic variable value echo. (Set %User!%) ||::> show dynamic Usr environment variable echo. (Set %UserID%) ||::> show dynamic UserID environment variable echo. (echo %User!%=%UserID%) ||::> show static variable and value echo. echo.&echo.&echo.&pause EndLocal :EOF \Rems::----------------------------------------------- Show quoteHide quote "Jeffery Hicks [MVP]" wrote: > Try something like this: > > FOR /F "tokens=1" %x in ('find /i "userb" users.txt') do @set zuser=%x > > If you use this in a batch file change %x to %%x. > > -- > Jeffery Hicks > Microsoft PowerShell MVP > http://www.scriptinganswers.com > http://www.powershellcommunity.org > > Now Available: WSH and VBScript Core: TFM > Coming Soon: Windows PowerShell: TFM 2nd Ed. > "abs" <nospam@wp.pl> wrote in message news:fh166n$phk$1@inews.gazeta.pl... > > Hi everyone. > > > > This is how my file containing list of users looks like (id username): > > > > 01 UserA > > 02 UserB > > 03 UserC > > ... > > > > I'm trying to write a batch file which could read the id of user whose > > name > > is passed as a parameter and save it to variable. I can find the line > > containing user's name: > > > > find "%1" UserB userlist.txt > > > > but how to save just user's id to variable ? > > > > Best regards, > > ABS > > > > > > >
how to modify dial-in property for a user account
Moving files from one directory to subdirectories Creating user's CN from Last and First name Using Windows Script that Zip Files using Winzip Trying to copy files\folders to UserProfile\Application Data List all users from a different domain Script to enable user access from Dial in tab in ADUC How to script Share Permissions Delete all files of certain type in folder and all subfolders Script software install if certain hardware exists |
|||||||||||||||||||||||