批量附加数据

时间:2017-06-29 19:00:04

标签: batch-file scripting

这是登录脚本的一部分。每次用户登录计算机时,脚本都会运行。脚本需要做的是每次运行时都记录到同一个文件,但我不希望它覆盖数据。我希望它添加到下面的行。我无法搞清楚,这就是我到目前为止所做的一切:

if not exist "C:\Windows\LogonScript" mkdir C:\Windows\LogonScript"
(echo Username: %USERNAME%
systeminfo | findstr /c:"Host Name"
systeminfo | findstr /c:"Domain"
systeminfo | findstr /c:"OS Name" 
systeminfo | findstr /c:"System Manufacturer"
systeminfo | findstr /c:"System Model"
systeminfo | findstr /c:"System type"
systeminfo | findstr /c:"Total Physical Memory" 
ipconfig | findstr IPv4
echo Hard Drive Information:
wmic LOGICALDISK where drivetype=3 get caption,size,FreeSpace) > C:\Windows\LogonScript\%COMPUTERNAME%.txt

xcopy /s C:\Windows\LogonScript\%COMPUTERNAME%.txt \\ess\Home\cgoodwin\Scripts

exit

1 个答案:

答案 0 :(得分:1)

以下代码段将使用我在评论中给出的答案附加。另外它应该快得多,(通过运行真正慢的systeminfo命令的单个实例)

If Not Exist "C:\Windows\LogonScript\" MD "C:\Windows\LogonScript"
(Echo UserName:                  %UserName%
SystemInfo|FindStr/IL /C:"Host Name:" /C:"Domain:" /C:"OS Name:"^
 /C:"System Manufacturer:" /C:"System Model:" /C:"System Type:"^
 /C:"Total Physical Memory:"
For /F "Tokens=2 Delims=:" %%A In ('IPConfig^|Find "IPv4"'
) Do Echo=IP Address:               %%A
Echo(
Echo Logical Disk Information:
WMIC LogicalDisk Where DriveType=3 Get Caption, Size, FreeSpace|More
)>>"C:\Windows\LogonScript\%ComputerName%.txt"