Week 3 - Tools - Windows Scripting to Automate Tools (Windows CLI) Flashcards

1
Q

List some basic windows commands re the file system

A

CD (change directory)
MD (make directory)
RD (remove directory)
Dir (list contents of a directory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List some basic windows commands re file manipulation

A

-Copy (copy file)
-Xcopy (copy complete directory trees)
-Del (delete)
-Move (move)
-Type (prints the contents of a file to the screen)
-More (cuts output of command into pages for better readability)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List some other useful windows commands

A

Commands:
-Echo (prints text to screen)
-Type (prints content of a file to the screen)
-Set (prints list of environment variables but you can also define own variables using this)
-Cls (clear screen)
-Doskey (/history prints command history)

Special commands & characters:
- /? (prints help)
- | (inserts the output of the first command into the second)
- > (redirects the output of a command to a text file - always creates a new output file)
-&raquo_space; (as above but appends to the end of a file if it exists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Summarise the two main ways to script in Windows

A
  1. Batch scripting.
    You create a text file with a list of commands to be executed sequentially.
    - can be windows commands
    - or external utilities
    - basic logic & variables
    Easy to learn, straightforward
    Text file (e.g.notepad)

batch files are saved as
.bat extension or
.cmd extension
Can start them by double clicking the file in windows explorer or in CL by type their name and press enter.

  1. Powershell
    - Comprehensive programming environment
    - uses windows API
    - steeper learning curve

We are going to focus on batch scripting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Batch Scripting. EXAMPLE - helloworld.bat

A

In command line.
- write: echo @echo off > helloworld.bat
this tells the system to display only plain (the echo off part). The > is telling it to output to a new text file called helloworld.bat

  • on next line write: echo echo Hello World&raquo_space; helloworld.bat
    This puts the text content ‘Hello World’ into the helloworld.bat file.
  • then use the ‘type’ command to show the contents of the file by writing: type helloworld.bat (it will display the words Hello World)
  • then write helloworld.bat and enter and it will write ‘Hello World’ to the screen
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Batch Scripting - Variables

A

Two relevant types of variables:

ENVIRONMENT variables
- ‘set’ command gives list of all environment variables that are on the system.
- set command can also be used to declare your own variables by putting the word ‘set’ then the variable name and = value you want to put in it.
- set /p variable=prompt (interactive)
- %variable% (echo %variable%)

COMMAND LINE PARAMETERS
- batchfile.bat param1 param 2
- param1 to %1 (to get value of parameter 1)
- param2 to %2 (to get value of parameter 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Batch scripting - Logic

A

Commands to bring logic / structureto your batch files

  • If (makes the execution of the command depend on a certain condition)
  • For (makes it possible to run a comman a specific number of times)
  • Rem (remark - makes it possible to put text in your script that explains the logic & the commands that you used - important if you need to make changes later and can allow someone else to read it. )

-Goto (makes it possible to jump to another location in your batch file. that location has to be defined by a label which is :labelname

  • Call (makes it possible to call another batch file from within your fiirst file)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly