echo %date% %time%
또는
echo %date% & echo %time%
이렇게 하면 두줄로 표시 된다.
응용하기
echo %date% %time% >> d:\txt.txt
이렇게 하면 출력 해서 txt 파일에 넣는다.
기타
powershell -Command "& { $datetime = (Get-Date).ToString('yyyyMMddHHmmss'); Compress-Archive -Path '%ProgramFiles%\IPBan\ipban.config' -DestinationPath ('%ProgramFiles%\IPBan\ipbanconfig' + $datetime + '.zip'); }"
이렇게 하면 날짜 시간으로 압축 가능 하다.
Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
powershell -Command "Get-Date -Format \"yyyy-MM-dd_HH-mm-ss\""
for /f %a in ('powershell -Command "Get-Date -Format \"yyyy-MM-dd_HH-mm-ss\""') do echo %a >> d:\txt.txt
cmd /c powershell -Command "Get-Date -Format 'HH:mm:ss'"
14:53:21
현재 시간
cmd /c powershell -Command "Get-Date -Format 'HH:mm:ss'" > d:\txt.txt
현재 시간 저장 txt 파일로
cmd /c powershell -Command "Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ff'"
2023-06-12 14:55:49.99
백분의 일초 ff 를 몇개 하냐에 따라서 다른 것 같다.
cmd /c powershell -Command "Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ff'" > d:\txt.txt
type d:\txt.txt
2023-06-12 14:55:49.99
cmd /c powershell -Command "Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff'"
2023-06-12 14:52:30.081
년 월 일 천분의 일초
cmd /c powershell -Command "Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff'" > d:\txt.txt
type d:\txt.txt
2023-06-12 14:52:30.081
set CURRENT_USER=%USERNAME%
schtasks /create /sc ONEVENT /tn "이벤트_뷰어_작업" /tr "%windir%\System32\cmd.exe /c netstat -anob >> d:\txt2.txt && powershell -Command "Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ff'" >> d:\txt.txt && exit" /rl HIGHEST /ru "%CURRENT_USER%" /f /ec Security /mo "*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and EventID=4625]]"
틀린 예문 입력 되지 않는다.
schtasks /create /sc ONEVENT /tn "이벤트_뷰어_작업" /tr "%windir%\System32\cmd.exe /c netstat -anob >> d:\txt2.txt && powershell -Command \"Get-Date -Format 'yyyy-MM-dd HH:mm:ss.ff'\" >> d:\txt2.txt && exit" /rl HIGHEST /ru "%CURRENT_USER%" /f /ec Security /mo "*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and EventID=4625]]"
아래와 같이 해야 된다. AI가 고쳐줌 ㅎㅎb \
기존 스크립트에서 PowerShell 명령 부분을 이중 인용 부호(\")로 묶어주었습니다.
하지만 아쉽게 작동 하지 않는다 ㅠ 실패
첫댓글 C:\Windows\system32>echo ^%date^% ^%time^%
%date% %time%
C:\Windows\system32>echo echo %%date%% %%time%%
echo %date% %time%
schtasks /create /tn "이벤트_뷰어_작업" /tr "%windir%\System32\cmd.exe /c netstat -anob >> d:\txt2.txt && echo echo ^%date^% ^%time^% >> d:\txt2.txt && exit" /sc ONEVENT /rl HIGHEST /ec Security /mo "*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and EventID=4625]]" /f
실패 아직 잘되진 않는다
schtasks /create /tn "SaveEvent" /sc onevent /ec Security /mo *[System/EventID=4625] /tr "for /f %a in ('powershell -Command \"Get-Date -Format \"yyyy-MM-dd_HH-mm-ss\"\"') do echo %a >> d:\txt.txt" /f 테스트 안될것 같다.