2017-07-17 131 views
0

我想创建一个Windows批量登录脚本,收集每个用户的系统信息和用户名/计算机名,并将其输出到一个日志文件(而不是为每个用户创建一个单独的文件)。所以,我需要这样的东西echo %username%-%computername% >> file.txtsysteminfo|find /i "original" >> file.txt,我管理的是这样做的:输出systeminfo登录脚本

systeminfo|find /i "original" >> \\share\sysinfo.log 
echo %username%-%computername% >>\\share\user.log 
type \\share\user.log > \\share\Results\systeminfo.log 
type \\share\sysinfo.log >> \\share\Results\systeminfo.log 

每当有人登录时,它输出到一个文件,但该用户名和系统的系统信息是分开的。我需要他们输出到单独的列,例如:

Username-ComputerName Original Install Date 
Jo-PC1     17/16/2016, 09:14:34 
Dan-PC2     17/03/2015, 11:00:05 

回答

0

请注意,堆栈溢出不是一个写代码为我服务。不管怎么说,我可耻的MC ND在我question


@echo off 

setlocal enableextensions disabledelayedexpansion 
rem Prepare padding for two column 
set "Width=30" 
setlocal enabledelayedexpansion 
set "padding= " 
for /l %%a in (1 1 %Width%) do set "padding=!padding! " 
endlocal & set "padding=%padding%" 

rem return "Username-ComputerName Original Install Date" 
echo Username-ComputerName   Original Install Date>File.ext 

rem Prepate two files to store username-computerName and install date lists 
for %%d in ("%temp%\username-computerName.%random%%random%%random%.tmp") do (
for %%f in ("%temp%\installName.%random%%random%%random%.tmp") do (

    rem Retrieve the list of username-computerName and install date into the temp files 
    type user.log > "%%~fd" 2>nul 
    type date.log > "%%~ff" 2>nul 

    rem Assign each temporary file to a separate stream 
    rem and call the code to process them 
    9<"%%~fd" 8<"%%~ff" call :dumpPairs 

    rem Clean up temporary files 
) & del /q "%%~ff" 
) & del /q "%%~fd" 

rem All done, leave 
cls 
type File.ext 
pause 
goto :eof 


rem Read stream 9 to retrieve username-computerName - Clean var on failure 
rem Read stream 8 to retrieve install date - Clean var on failure 
rem If both variables are uninitialized, there is nothing more to do 
rem Concatenate both information and padding 
rem Echo the padded results 
rem Repeat the process 

:dumpPairs 
<&9 set /p "username-computerName=" || set "username-computerName=" 
<&8 set /p "installName="  || set "installName=" 
if not defined username-computerName if not defined installName goto :eof 

set "line=%username-computerName%%padding%" 
setlocal enabledelayedexpansion 
echo(!line:~0,%Width%! !installName!>>File.ext 
endlocal 

goto :dumpPairs 

的解释已经是脚本里面偷走了脚本(and edited),所以我不会解释太多。

  • 只是得到的结果为2个文件
  • 回声在一起

输出部分

rem All done, leave 
cls 
type File.ext 
pause 
goto :eof 

所以你可能需要一些调整。