Windows Scripting

From the powershell Window, you can issue Windows commands. From the integrated environment you can edit and create scripts:

Leap Year sample
Unicode Sample


CodeOutput
Contents of file seteg.bat
set x=TIM
echo %x%
echo "hello"
set x=John
set x=%x% Doe
echo x
echo %x%
This is the output from issuing the command seteg
C:\>seteg
C:\>set x=TIM
C:\>echo TIM
TIM
C:\>echo "hello"
"hello"
C:\>set x=John
C:\>set x=John Doe
C:\>echo x
x
C:\>echo John Doe
John Doe
C:\>

Contents of file inputeg.bat

REM turn echoing off
@echo off
REM now not echoed!
echo First parameter is: %1
prompt %1$G

This is the output from issuing the command inputeg with the parameter "Hello"
C:\>inputeg Hello
C:\>REM turn echoing off
First parameter is: Hello
Hello>

Now my prompt has changed!
To change the prompt back to the path followed by a greater than, issue the command prompt $P$G:

Hello>prompt $P$G
C:\>

Contents of file ifeg.bat

@echo off
REM echo turned off
if "%1" == "1" (
    echo You entered a one
) else echo Other

This is the output from issuing the command ifeg
C:\>ifeg 1

You entered a one
C:\>ifeg 3

Other
C:\>

Contents of file foreg.bat

@echo off
REM echo turned off
for %%I in (*.bat) do @echo %%I

This is the output from issuing the command foreg
C:\deborah\207\Notes>foreg
ifeg.bat
copycon.bat
inputeg.bat
seteg.bat
foreg.bat

C:\deborah\207\Notes>

Contents of file copycon.bat

@echo off
REM echo turned off
echo "enter a 1 or 2 followed by ctrl-Z "
copy con tempfile
REM Copy CON places user input into the file tempfile

for /f %%I in (tempfile) do set ANS=%%I

if "%ANS%" =="1" (
    echo You entered a one
) else if "%ANS%" == "2" (
    echo You entered a two
)else (
    echo You don't follow directions very well
)

This is the output from issuing the command copycon

C:\deborah\207\Notes>copycon
"enter a 1 or 2 followed by ctrl-Z "
1^Z
      1 file(s) copied.
You entered a one

C:\deborah\207\Notes>copycon
"enter a 1 or 2 followed by ctrl-Z "
2^Z
      1 file(s) copied.
You entered a two

C:\deborah\207\Notes>copycon
"enter a 1 or 2 followed by ctrl-Z "
asdfasd ^Z
      1 file(s) copied.
You don't follow directions very well

C:\deborah\207\Notes>copycon
"enter a 1 or 2 followed by ctrl-Z "
1
2
^Z
      1 file(s) copied.
You entered a two

C:\deborah\207\Notes>