gygon

PowerShell Ping Test

Posted by gygon on Wednesday, November 16th, 2011

Used this little script the other day for a basic network test to an access point I was testing. It just pings the device every 10 seconds (or whatever you set it at) and only outputs when there is an error and the time it occurred. Made for an easy way to leave this running over […]

continue reading

Using PowerShell to monitor a web server

Posted by gygon on Monday, November 14th, 2011

A couple years ago I posted about a PowerShell script that would read in a web page. I used that to setup a basic web site test to go through a list of web sites/servers and make sure they were up and running and email an alert if they were down or the size of […]

continue reading

Monitoring the Event Log with PowerShell

Posted by gygon on Saturday, March 21st, 2009

One of my goals with learning more about PowerShell is to be able to monitor the event logs on servers and notify me via email when certain events happen. The system I’m looking to monitor are not part of a domain, are in remote locations on isolated networks. Some of the main things I’m looking […]

continue reading

Copy file and append date and time

Posted by gygon on Thursday, December 9th, 2010

Recently set this up for someone and then had someone else looking to do the same thing about a week later. Figured it would be good to post it here for future reference.

The first example adds just the date:


@echo off
REM *****************************************************
REM **  DatedBackup.bat
REM **  This batch file will make a backup copy of
REM **  the file "example.xlsx" and append the current
REM **  date in YYYYMMDD format to the current directory
REM **
REM *****************************************************
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C%%B%%A
)
copy "example.xls" example_%All%.xls
exit

The second example adds both the date and timestamp:


@echo off
REM *****************************************************
REM **  DatedBackup.bat
REM **  This batch file will make a backup copy of
REM **  the file "examplefile.pdf" and append the current
REM **  date (in YYYYMMDD format) and timestamp
REM **  to the current directory
REM **
REM *****************************************************
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C%%B%%A
)
@For /F "tokens=1,2,3 delims=:,. " %%A in ('echo %time%') do @(
Set Hour=%%A
Set Min=%%B
Set Sec=%%C
Set Allm=%%A.%%B.%%C
)
@For /F "tokens=3 delims=: " %%A in ('time /t ') do @(
Set AMPM=%%A
)
copy "examplefile.pdf" examplefile_%All%_%Allm%%AMPM%.pdf
exit

Some reference:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/for.mspx?mfr=true

http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-usi

Posted in: Tech, Tips, Windows.

Comments are closed.