The main problem with the output you have reported, is that it appears to have assumed the returned output of your %DATE%
and %TIME%
variables. Those values can be configured differently for the locale, machine and/or logged in user, and in your case does not match the %DATE%
assumption of dd#MM#yyyy
, (where #
represents the item sepatators). Yours is clearly either ddd d#M#yyyy
, ddd dd#MM#yyyy
, ddd M#d#yyyy
. or ddd MM#dd#yyyy
There aremany questions and answer already on this site which show methods of getting the date and time using a none locale or otherwise configured format, the most useful, non PowerShell method of doing that uses the built-in WMIC.exe utility.
Just for something a little bit different, i.e. not using net.exe at all, and instead using WMIC.exe:
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "{="
Set "}="
For /F Tokens^=6^ Delims^=^" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe OS Get CSName^,LocalDateTime /Format:MOF 2^>NUL') Do If Not Defined { (Set "{=%%G") Else (SetLocal EnableDelayedExpansion
Set "}=%%G"
For %%H In ("!}:~,4!_!}:~4,2!_!}:~6,2!__!}:~8,2!_!}:~10,2!_!}:~12,2!;!{!") Do (EndLocal
Set "{=%%~H"))
For /F "Tokens=1,* Delims==" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe Group Where "Name='Administrators'" Assoc:List /ResultClass:Win32_UserAccount 2^>NUL ^| %SystemRoot%\System32\findstr.exe "^Name="') Do For /F "Tokens=*" %%I In ("%%H") Do If Not Defined } (Set "}=%%I") Else (SetLocal EnableDelayedExpansion
For %%J In ("!}!") Do (Endlocal
Set "}=%%~J;%%I"))
Set "CSVBaseName=%{:;="&:"%"
(Echo %{%;%}%;) 1>"C:\Temp\%CSVBaseName%.csv"
If you wanted to still use net.exe, i.e. 'a little bit different' was not what you wanted, then the following should perform the same task:
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "{="
Set "}="
For /F Delims^=^ EOL^= %%G In ('%SystemRoot%\System32\net.exe LocalGroup
Administrators 2^>NUL') Do (If Not Defined { (Set "{=%%G") Else (
SetLocal EnableDelayedExpansion
For /F Delims^= %%H In ("!{!") Do (EndLocal
Set "{=%%H;%%G"
Set "}=%%H"))
Set /P "=%%G" 0<NUL | %SystemRoot%\System32\findstr.exe "^\-\-*$" 1>NUL && (
Set "{="))
If Not Defined } GoTo :EOF
For /F Delims^=^ EOL^= %%G In ('%SystemRoot%\System32\HOSTNAME.EXE'
) Do Set "{=%%G;%}%"
For /F Tokens^=6^ Delims^=^" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe OS Get
LocalDateTime /Format:MOF 2^>NUL') Do Set "}=%%~nG"
Set "}=%}:~,4%_%}:~4,2%_%}:~6,2%__%}:~8,2%_%}:~10,2%_%}:~-2%"
(Echo %}%;%{%;) 1>"C:\Temp\%}%.csv"
The differences with this being, that it does not assume a specific number of lines to skip, it does not expect the end user language to be English, it uses the reported HostName, as opposed to the ComputerName, (which may not necessarily match), and once again does not rely on the end users computer configuration for defining the date and time string.