Save ping results to TXT file - windows

I am trying to build a script that will save some ping result info to a text file. The only info I really need is date, time, ipaddress, % of loss, and average time.
I have been able to make parts of this work.
I can get the time and date to save to the text file but nothing else.
The other problem I'm having is when I do get it to save to a text file it saved 100s of results to the file. I only want it to save the final result. Then when I rerun the file it would add a new entry to the text file.
Here is a sample of what I have been playing with:
#echo on
SET ip=10.22.222.54
#echo. %date% at %time% to %ip%>>PingLogs.txt
ping %ip% -n 1 >>Logs.txt
stop
This is what I expect it to look like when saving to a text file:
06/07/2019 : 21:54 : 10.22.222.54 - 0% - 0ms,
06/07/2019 : 20:18 : 10.22.222.54 - 0% - 0ms,

Use a for /f loop to catch the output of a command. As your command ping output several lines, it needs a lot of analyzing to find out the correct tokens and delimiters to get the desired parts. Then just reassemble them to your needs and put a loop around:
#echo off
set "IP=www.google.de"
:loop
set "loss="
for /f "tokens=1,9 delims=( " %%a in ('ping -n 1 %IP% ^|findstr "%% ms,"') do (
if not defined loss (set "loss=%%a") else (set "average=%%b")
)
echo %date% : %time% : %IP% - %loss% - %average%
goto :loop
(Note: findstr "%% ms," looks for lines that contain a % (has to be escaped with another %) and/or the string ms, - exactly the two lines, we need). You could also use `findstr "loss Average", but then the script would only work on English Windows versions. I like to keep my scripts as language independent as possible.
Output:
07.06.2019 : 19:40:39,37 : www.google.com - 0% - 13ms
07.06.2019 : 19:40:41,25 : www.google.com - 0% - 13ms
07.06.2019 : 19:40:43,24 : www.google.com - 0% - 15ms
07.06.2019 : 19:40:45,25 : www.google.com - 0% - 13ms
07.06.2019 : 19:40:47,24 : www.google.com - 0% - 13ms
Note: date/time format depends on locale settings - yours probably look different.
Note: with ping -n 1 don't expect loss to be anything other than either 0% or 100%
Note: with ping -n 1, Minimum, Maximum and Average all are the same (this script takes Average nevertheless, so if you use something other than /n 1, the output is still what you expect)

If you needed to ensure that the date and time format were always presented in the same way, you could use this .bat file script to call a PowerShell script. Put both of these scripts in the same directory.
=== pip.bat
powershell -NoLogo -NoProfile -File "%~dp0pip.ps1" >pip.txt
=== pip.ps1
$Computers = #('localhost', 'asdfa')
foreach ($Computer in $Computers) {
if ($tc = Test-Connection -ComputerName $Computer -Count 1 -ErrorAction SilentlyContinue) {
ForEach-Object {
"{0} : {1} : {2} - {3}% - {4}" -f #(
(Get-Date -f "MM/dd/yyyy")
, (Get-Date -f "HH:mm")
, $tc.Address
, "0"
, $tc.ResponseTime
)
}
} else {
"{0} : {1} : {2} - {3}% - {4}" -f #(
(Get-Date -f "MM/dd/yyyy")
, (Get-Date -f "HH:mm")
, $Computer
, "100"
, 0
)
}
}

Related

How to copy multiple files at once to different directories using robocopy?

I have several files inside different folders and I'm trying to copy them to another different folder.
For example:
[source] [dest]
C:\Users\Downloads\a\a.txt C:\Users\Downloads\222\a.txt
C:\Users\Downloads\b\b.jpg C:\Users\Downloads\333\b.jpg
C:\Users\Downloads\xyz\c.exe C:\Users\Downloads\yyy\c.exe
...
How I could create a script to be executed on cmd and using robocopy copy all files at once?
My attempt:
#echo off
set obj[0].source="C:\Users"
set obj[0].dest="C:\Users\a"
set obj[0].file="x.txt"
set obj[1].source="C:\Users"
set obj[1].dest="C:\Users\b"
set obj[1].file="y.txt"
FOR /L %%i IN (0 1) DO (
call echo source = %%obj[%%i].source%%
call echo dest = %%obj[%%i].dest%%
robocopy %%obj[%%i].source%% %%obj[%%i].dest%% %%obj[%%i].file%%
)
pause
Error:
2022/12/22 21:03:36 ERROR 2 (0x00000002) Accessing Source Directory C:\Users\%obj[0].source%\
The system cannot find the file specified.
Press any key to continue . . .
The path is wrong, whats happening?
With Powershell you can do like this :
$Paths=#{
"C:\Users\Downloads\a\a.txt"="C:\Users\Downloads\222\a.txt"
"C:\Users\Downloads\b\b.jpg"="C:\Users\Downloads\333\b.jpg"
"C:\Users\Downloads\xyz\c.exe"="C:\Users\Downloads\yyy\c.exe"
}
$Paths.GetEnumerator() | ForEach-Object {write-host Robocopy $_.Key $_.Value}
And the result is like this one :
Robocopy C:\Users\Downloads\xyz\c.exe C:\Users\Downloads\yyy\c.exe
Robocopy C:\Users\Downloads\a\a.txt C:\Users\Downloads\222\a.txt
Robocopy C:\Users\Downloads\b\b.jpg C:\Users\Downloads\333\b.jpg
Further reading : Read all items in a PowerShell hash table with a loop
EDIT : Tested with xcopy
$Paths=#{
"E:\Batch\SpeedTest\Shortcut-PS.bat"="E:\temp\a\"
"E:\Batch\SpeedTest\SpeedTest_Hackoo_Ookla.bat"="E:\temp\b\"
"E:\Batch\SpeedTest\OLD_SpeedResult.txt"="E:\temp\c\"
}
$Paths.GetEnumerator() | ForEach-Object {xcopy /D $_.Key $_.Value}
Results :
E:\Batch\SpeedTest\SpeedTest_Hackoo_Ookla.bat
1 fichier(s) copi‚(s)
E:\Batch\SpeedTest\OLD_SpeedResult.txt
1 fichier(s) copi‚(s)
E:\Batch\SpeedTest\Shortcut-PS.bat
1 fichier(s) copi‚(s)

Are there certain MAC address vendor codes that don't work on windows or is there something else wrong with my code?

Following #Asian's question and my recent interest in powershell, I tried to replicate the script I provided to answer Asian's question, however I am not having the same success that I did with the batch script. If you do not want to view the previous question, here is my batch-file for changing your MAC Address:
#echo off
dism >nul
if %errorlevel% NEQ 0 goto Elevate
(call )
netsh interface set interface Wi-Fi disable
timeout /t 1 /nobreak >null
netsh interface set interface Wi-Fi enable
choice /c RC /m "Would you like to randomize your MAC adress or customize it?"
if %Errorlevel% EQU 2 goto custom
set loopcount=5
:loop
set /a loopcount=loopcount-1
if %loopcount% LEQ 0 (goto exitloop)
set /a "ascii = %random% * 26 / 32768 + 65"
cmd /c exit /b %ascii%
set "rl1=%rl1%%=ExitCodeAscii%"
goto loop
:exitloop
set MAC="0E%random:~0,2%%rl1:~0,2%%random:~0,2%%rl1:~3,2%%rl1:~-1%%random:~0,1%"
goto after
:custom
echo What would you like to change your MAC address to?
echo Remember to always have the second digit of your MAC address to always be a 2, 6, A, or E
echo Format: AABBCCDDEEFF
echo/
set /p MAC="Input your MAC address here (no spaces or hyphens)> "
:after
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0011" /v NetworkAddress /d %MAC% /f >null
netsh interface set interface Wi-Fi disable
timeout /t 1 /nobreak >null
netsh interface set interface Wi-Fi enable
echo Operation Successful
echo %mac% is your new MAC address
pause
goto :eof
:Elevate
Echo Error: The requested operation requires elevation
Echo Run file again as admin
Echo Closing file in 10 seconds...
timeout /t 10 /nobreak >nul
goto :eof
I tried to replicate it in powershell, however the script is very volatile on whether it works or not:
[string]$admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
if ($admin -eq "False"){
echo "Error: The requested operation requires elevation`nRun file again as administrator"
pause
exit}
rv * -ErrorAction SilentlyContinue
echo "This file will temporarily disable your Wi-Fi adapter"
While (!($C1)){
$choice1 = Read-Host -Prompt "Would you like to proceed? [Y/N]"
switch ($choice1) {
"N" {echo "Ok, press any key to exit this file:"
cmd /c pause > $null; exit}
"Y" {echo "Ok, proceeding with operation"; [int]$C1 = 1; break}
}
if (!($C1)){echo "Invalid input"}
}
rv * -ErrorAction SilentlyContinue
netsh interface set interface Wi-Fi disable;
$getwifi = netsh interface show interface | findstr "Wi-Fi"
if ($getwifi.substring(0,7) -ne "disable"){echo "Unexpected error: Press any key to exit"
cmd /c pause > $null; exit}
echo "Wi-Fi has been succesfully disabled, proceeding with operation"
While (!($C1)){
$choice1 = Read-Host -Prompt "Would you like to randomize your MAC Address or customize it? [R/C]"
switch ($choice1) {
"R" {
$test = #(...) | get-random
<# $test is a random value in a list of 25000+ MAC Address vendor codes provided in
https://gitlab.com/wireshark/wireshark/raw/master/manuf with the colons removed and columns
besides the MAC column removed as well #>
$test2 = [string](get-random -minimum 10 -maximum 99)+(-join ((65..90) | Get-Random -Count 2 | % {[char]$_}));
$test3 = [string](get-random -minimum 1 -maximum 9)+(-join ((65..90) | Get-Random -Count 1 | % {[char]$_}));
$MAC = $test + $test2 + $test3;
$C1 = 1}
"C" {$C1 = 2}
}
if (!($C1)){echo "Invalid input"}
}
if(!($MAC)){
do{
echo "What would you like to change your MAC address to?`nRemember to always have the second digit of your MAC address to always be a number`nFormat: 11BBCCDDEEFF";
$MAC = read-host -prompt "Input your MAC address here [no spaces or hyphens]";
if ($MAC.length -eq 12){$C1 = 1};
if (!($MAC.length -eq 12)){echo "Invalid input: Follow the format"; rv MAC}
} while(!($MAC))
}
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0011" /v NetworkAddress /d $MAC /f >$null
netsh interface set interface Wi-Fi enable
echo "Operation Successful"
echo "$MAC is your new MAC address"
pause
Again, $test is a random value in a list of 25000+ MAC Address vendor codes provided in https://gitlab.com/wireshark/wireshark/raw/master/manuf with the colons removed and columns besides the MAC column removed as well. I believe the issue is in the $test variable where the computer will just reject a certain MAC address. If this is not the issue, can someone explain to me what is the issue, and if there are certain codes that will always work in changing the MAC address successfully, please provide me them. Thank you in advance.
Some addresses that work include:
AABBCCDDEEFF
001122334455
00AA11BB22CC
Other variants of 00----------
6E80F12CC8C9
I will write more sample addresses down when I test them.
Try macaddr=$(echo $FQDN|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/') &> /dev/null && echo macaddr. This will generate a random MAC address and echo it to you. This only works in Ubuntu/Bash though.
You can also do (1..12 | %{ '{0:X}' -f (Get-Random -Max 16) }) -join '' in PowerShell.

Test if computer is available on network

I work on a company which has many Shop. Each shop has his own IP address :
SHOP 1 = 192.168.1.0/24, SHOP 2 = 192.168.2.0/24, SHOP 3 = 192.168.3.0/24, etc...
I have a number of Windows computers (between 1 and 9) on the same subnet (255.255.255.0) on each shop.
Each computer has a static IP address : 1st = 192.168.1.10, 2nd = 192.168.1.20, 3rd = 192.168.1.30, 4th = 192.168.1.40, etc.
The HQ of my company can deploy softs ONLY on the first computer on each shop (licences issue).
Here, we will try to install Xerox drivers on ALL windows computer on all shop.
I made 3 batch script :
The first, launched as the superadmin of the computer, install a new user with admin rights to install drivers
The second, launched as the new user, install Xerox drivers and set as default the printer.
The third, launched as the superadmin of the computer, try to install Xerox drivers on other computers of the same shop :
Loop over my 9 ip address (for /l %%G in (...) do (...)
For each IP address, test if it ping.
Do a ftp transfer between the computer 1 and the IP address (drivers packages + scripts)
PsExec64.exe to run the first script
PsExec64.exe to run the second script
The first and the second script works perfectly, we'll not speak about them.
Where I need help is on the thrid.
I try 3 scripts :
The first :
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
ping -n 1 %subnet%%%G | findstr "TTL="
if %errorlevel%==0 (
echo Ping %subnet%%%G : OK >> log_ping_errorlevel.txt
) else (
echo Ping %subnet%%%G : KO >> log_ping_errorlevel.txt
)
)
Here the log_ping_errorlevel.txt with 2 computers on my subnet :
Ping 192.168.1.20 : OK
Ping 192.168.1.30 : OK
Ping 192.168.1.40 : OK
Ping 192.168.1.50 : OK
Ping 192.168.1.60 : OK
Ping 192.168.1.70 : OK
Ping 192.168.1.80 : OK
Ping 192.168.1.90 : OK`
I tried to surround %errorlevel% and 0 by simple quote but I get the same result.
Here an extract of the output if I run the batch in cmd window :
C:\Temp\Xerox_Install>(
ping -n 1 192.168.1.90 | findstr "TTL="
if '0'=='0' (echo "Ping 192.168.1.90 : OK" 1>>log_ping_errorlevel.txt ) el
se (echo "Ping 192.168.1.90 : KO" 1>>log_ping_errorlevel.txt )
)
It seems that the errorlevel is always = 0 in my script, IDK why.
The second :
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
ping -n 1 %subnet%%%G && set pingtest=ok
if '%ping_test%'=='ok' (
echo Ping %subnet%%%G : OK >> log_ping_errorlevel.txt
) else (
echo Ping %subnet%%%G : KO >> log_ping_errorlevel.txt
)
)
Here the log_ping_set.txt with 2 computers on my subnet :
Ping 192.168.1.20 : OK
Ping 192.168.1.30 : OK
Ping 192.168.1.40 : OK
Ping 192.168.1.50 : OK
Ping 192.168.1.60 : OK
Ping 192.168.1.70 : OK
Ping 192.168.1.80 : OK
Ping 192.168.1.90 : OK`
I think the ping command result is always 0 then the setter pingtest can be executed.
The third :
Because I'm stuck with the ping command, I tried the if exist folder on remote computer :
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
if exist \\%subnet%%%G\C$\Temp\ (
echo Remote folder reachable >> log_folder_reachable.txt
) else (
echo ERROR 404 - Remote folder not found >> log_folder_reachable.txt
)
)
Here the log_folder_reachable.txt with 2 computers on my subnet :
Remote folder reachable
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
It works BUT the if exist timeover is about 160 seconds and I don't want to wait for 160 seconds before going to the next computer...
Can someone help me with any method but not using external tools ?
You should read SO items about delayedexpansion.
if %errorlevel%==0 (
in the first script should be
if not errorlevel 1 (
[obviously, reverse the logical condition and remove the "not"]
if errorlevel 1 means "if errorlevel is 1 or greater than 1" and is interpreted on the run-time value of errorlevel.
Next:
ping -n 1 %subnet%%%G && set pingtest=ok
if '%ping_test%'=='ok' (
should be
set "ping_test="
ping -n 1 %subnet%%%G && set "ping_test=ok"
if defined ping_test (
Notes
you are setting pingtest in your ping command, then you are attempting to test ping_test
Even had the variablename been correct, the purpose for the quotes in an if statement is to combine the contents as a single string. Single-quotes don't cut the mustard, double-quotes are required.
With the code you have, ping_test once set will retain its value for the next loop, you need to clear it before theping.
The replacement code first sets the value of ping_test to nothing. The quotes delimit the variable name and value so that trailing spaces on the line are not included in the value assigned. The ping command then may set the value of ping_test to (ok, but any value other than nothing (ie something) is valid). The if defined command interprets the run-time value of the variable.
The third part - well, getting desperate, but no need to go this far as the changes I've outlined should solve the problem.
In regards to your first set of code where you said you tried to use delayed expansion it should look like this. Tested and works on my network.
#echo off
setlocal enabledelayedexpansion
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
ping -n 1 %subnet%%%G | findstr "TTL="
if !errorlevel!==0 (
echo Ping %subnet%%%G : OK >> log_ping_errorlevel.txt
) else (
echo Ping %subnet%%%G : KO >> log_ping_errorlevel.txt
)

Get last n lines or bytes of a huge file in Windows (like Unix's tail). Avoid time consuming options

I need to retrieve the last n lines of huge files (1-4 Gb), in Windows 7.
Due to corporate restrictions, I cannot run any command that is not built-in.
The problem is that all solutions I found appear to read the whole file, so they are extremely slow.
Can this be accomplished, fast?
Notes:
I managed to get the first n lines, fast.
It is ok if I get the last n bytes. (I used this https://stackoverflow.com/a/18936628/2707864 for the first n bytes).
Solutions here Unix tail equivalent command in Windows Powershell did not work.
Using -wait does not make it fast. I do not have -tail (and I do not know if it will work fast).
PS: There are quite a few related questions for head and tail, but not focused on the issue of speed. Therefore, useful or accepted answers there may not be useful here. E.g.,
Windows equivalent of the 'tail' command
CMD.EXE batch script to display last 10 lines from a txt file
Extract N lines from file using single windows command
https://serverfault.com/questions/490841/how-to-display-the-first-n-lines-of-a-command-output-in-windows-the-equivalent
powershell to get the first x MB of a file
https://superuser.com/questions/859870/windows-equivalent-of-the-head-c-command
If you have PowerShell 3 or higher, you can use the -Tail parameter for Get-Content to get the last n lines.
Get-content -tail 5 PATH_TO_FILE;
On a 34MB text file on my local SSD, this returned in 1 millisecond vs. 8.5 seconds for get-content |select -last 5
How about this (reads last 8 bytes for demo):
$fpath = "C:\10GBfile.dat"
$fs = [IO.File]::OpenRead($fpath)
$fs.Seek(-8, 'End') | Out-Null
for ($i = 0; $i -lt 8; $i++)
{
$fs.ReadByte()
}
UPDATE. To interpret bytes as string (but be sure to select correct encoding - here UTF8 is used):
$N = 8
$fpath = "C:\10GBfile.dat"
$fs = [IO.File]::OpenRead($fpath)
$fs.Seek(-$N, [System.IO.SeekOrigin]::End) | Out-Null
$buffer = new-object Byte[] $N
$fs.Read($buffer, 0, $N) | Out-Null
$fs.Close()
[System.Text.Encoding]::UTF8.GetString($buffer)
UPDATE 2. To read last M lines, we'll be reading the file by portions until there are more than M newline char sequences in the result:
$M = 3
$fpath = "C:\10GBfile.dat"
$result = ""
$seq = "`r`n"
$buffer_size = 10
$buffer = new-object Byte[] $buffer_size
$fs = [IO.File]::OpenRead($fpath)
while (([regex]::Matches($result, $seq)).Count -lt $M)
{
$fs.Seek(-($result.Length + $buffer_size), [System.IO.SeekOrigin]::End) | Out-Null
$fs.Read($buffer, 0, $buffer_size) | Out-Null
$result = [System.Text.Encoding]::UTF8.GetString($buffer) + $result
}
$fs.Close()
($result -split $seq) | Select -Last $M
Try playing with bigger $buffer_size - this ideally is equal to expected average line length to make fewer disk operations. Also pay attention to $seq - this could be \r\n or just \n.
This is very dirty code without any error handling and optimizations.
When the file is already opened, it's better to use
Get-Content $fpath -tail 10
because of "exception calling "OpenRead" with "1" argument(s): "The process cannot access the file..."
This is not an answer, but a large comment as reply to sancho.s' answer.
When you want to use small PowerShell scripts from a Batch file, I suggest you to use the method below, that is simpler and allows to keep all the code in the same Batch file:
#PowerShell ^
$fpath = %2; ^
$fs = [IO.File]::OpenRead($fpath); ^
$fs.Seek(-%1, 'End') ^| Out-Null; ^
$mystr = ''; ^
for ($i = 0; $i -lt %1; $i++) ^
{ ^
$mystr = ($mystr) + ([char[]]($fs.ReadByte())); ^
} ^
Write-Host $mystr
%End PowerShell%
With the awesome answer by Aziz Kabyshev, which solves the issue of speed, and with some googling, I ended up using this script
$fpath = $Args[1]
$fs = [IO.File]::OpenRead($fpath)
$fs.Seek(-$Args[0], 'End') | Out-Null
$mystr = ''
for ($i = 0; $i -lt $Args[0]; $i++)
{
$mystr = ($mystr) + ([char[]]($fs.ReadByte()))
}
$fs.Close()
Write-Host $mystr
which I call from a batch file containing
#PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\myscript.ps1' %1 %2"
(thanks to How to run a PowerShell script from a batch file).
Get last n bytes of a file:
set file="C:\Covid.mp4"
set n=7
copy /b %file% tmp
for %i in (tmp) do set /a m=%~zi-%n%
FSUTIL file seteof tmp %m%
fsutil file createnew temp 1
FSUTIL file seteof temp %n%
type temp >> tmp
fc /b tmp %file% | more +1 > temp
REM problem parsing file with byte offsets in hex from fc, to be converted to decimal offsets before output
type nul > tmp
for /f "tokens=1-3 delims=: " %i in (temp) do set /a 0x%i >> tmp & set /p=": " <nul>> tmp & echo %j %k >> tmp
set /a n=%m%+%n%-1
REM output
type nul > temp
for /l %j in (%m%,1,%n%) do (find "%j: "< tmp || echo doh: la 00)>> temp
(for /f "tokens=3" %i in (temp) do set /p=%i <nul) & del tmp & del temp
Tested on Win 10 cmd Surface Laptop 1
Result: 1.43 GB file processed in 10 seconds

Batch script or CMD for daily task on directory content by date

I admit I am a noob when it comes to CMD and bat scripting hence maybe my question has already been answered but I couldn't find it because I am unfamiliar with the terminology.
Basically I am currently running CMD to create a txt file for a directory content, that works fine but I would like to improve this process and started to look into a batch file to run this for multiple directories and by date but only get confused with the commands.
I would really appreciated if you maybe show me the right direction to look up the possible commands. Here is was I am basically trying to achieve:
Scan Directory 1, create log file with all content (filename) with modification of date DDMMYYYY and save under Directory 1 (existing on Desktop)
Repeat above for Directory 2, 3, 4 etc.
Now I am not sure how to approach this and where to start. It looks so simply yet I am have not managed to get to work.
assuming you are on Vista or better and your date format is dd/mm/yyyy:
for /d %%a in ("%userprofile%\Desktop\Directory*") do (
for %%b in ("%%~fa\*") do (
set "fname=%%~fb"
for /f %%c in ("%%~tb") do set "fdate=%%c"
setlocal enabledelayedexpansion
echo !fname! !fdate:/=! >> "%%~fa\LOGFILE.TXT"
endlocal
)
)
First of all your batch script to parse current date-time will be locale specific. As long as you do not plan to use it on non-US Windows it will be fine. My solution was to use simple VBS script to generate current timestamps
So code of my batch file looks like
#echo off
call GetToday.bat
call %TEMP%\SetToday.bat
SET LOGFILE=Log.%TODAY%.log
echo %LOGFILE%
Use your log here
GetToday.bat:
#echo off
set TOOLS_HOME=%~dp0
cscript /NoLogo %TOOLS_HOME%\Today.vbs >%TEMP%\SetToday.bat
call %TEMP%\SetToday.bat
Today.vbs:
Dim d
d = Now
WScript.Echo "SET TODAY=" & Get2Digit(Year(d)) & Get2Digit(Month(d)) & Get2Digit(Day(d))
Function Get2Digit(value)
if 10 > value Then
Get2Digit = "0" & value
Else
Get2Digit = Right(value, 2)
End If
End Function
However given Today.vbs generates today date in form YYMMDD. From my experience such suffixes are much more useful, you could just sort you files by name to find specific date
In PowerShell something like this should work:
$folders = 'C:\path\to\Directory1', 'C:\path\to\Directory2', ...
$refDate = (Get-Date '2013-05-27').Date
$recurse = $false
foreach ($d in $folders) {
$output = Join-Path $d 'filelist.txt'
Get-ChildItem $d -Recurse:$recurse | ? {
-not $_.PSIsContainer -and $_.LastWriteTime.Date -eq $refDate
} | % { $_.Name } | Out-File $output
}
If you want to recurse into the subfolders of the scanned folders you need to change $recurse to $true and perhaps change $_.Name to $_.FullName, so you get the filename with the full path instead of just the filename.

Resources