46
Technical Workshop 1 ADVANCED SYSTEMS MANAGEMENT Thursday January 29 th 2009 Presented By Arik Fletcher

Basics of Batch Scripting

Embed Size (px)

Citation preview

  • 1. Technical Workshop 1
    ADVANCED SYSTEMS MANAGEMENT
    Presented By Arik Fletcher
    Thursday January 29th 2009

2. Why Are We Here?
These workshops aim to relay a simple mantra:
A little TIME, EFFORT, and the right RESOURCES combined with TRAINING, PRACTICE, and TEAMWORK will vastly improve your KNOWLEDGE, ABILITY, and EXPERIENCE.
KNOWLEDGE
TEAMWORK
TIME
TRAINING
RESOURCES
EXPERIENCE
PRACTICE
EFFORT
ABILITY
Technical Workshop 1 - Advanced Network Management
3. Agenda
Technical Workshop 1 - Advanced Network Management
Administration Essentials09:45 10:30
Discussion:IT Support Expectations
Exercise:Task Management and Automation
Tutorial:The Realities of Automation
BREAK10:30 10:40
Scripting Essentials10:40 12:10
Overview:Introduction to Scripting
Tutorial:Syntax and Reference Documents
Tutorial:Structure and Sample Code
Exercise:Script Writing and Troubleshooting
BREAK12:10 12:20
Toolkit Essentials12:0 13:00
Overview: Utility DVD contents
Discussion:Recommended Tools
4. Administration Essentials
TASK MANAGEMENT FOR SYSTEMS ENGINEERS
Technical Workshop 1 - Advanced Network Management
5. IT Support:Expectations
Interviews with staff at the Computer Depot in the University of Vermont.
This video focuses on what IT Support Technicians expect from their computers.
Technical Workshop 1 - Advanced Network Management
6. What Do You Expect From Your Computers?
Technical Workshop 1 - Advanced Network Management
7. Recommended Admin Tasks
Daily Checks:
Server Services
Server Event Logs
Server Hardware Status
Firewall Logs and Status
Backup Status
Antivirus Updates
Weekly Checks:
Server Disk Space
Mail Store & Database Space
Technical Workshop 1 - Advanced Network Management
Monthly Checks:
Restore Status
Server Security Updates
Network Application Patches
Server Disk Fragmentation
Workstation Hardware Status
Printer Hardware Status
Documentation Status
Quarterly Checks:
Workstation Builds
8. Where Does The Day Go?
If you feel like this guy...
dont panic, help is at hand!
Technical Workshop 1 - Advanced Network Management
9. Automated vs. Manual Tasks
Automated Checks:
Server Services
Server Event Logs
Server Hardware Status
Firewall Logs and Status
Backup Status
Antivirus Updates
Server Disk Space
Mail Store & Database Space
Server Security Updates
Network Application Patches
Server Disk Fragmentation
Workstation Hardware Status
Printer Hardware Status
Technical Workshop 1 - Advanced Network Management
Manual Checks:
Restore Status
Documentation Status
Workstation Builds
10. Follow The A.R.P.C.E.D. Law
Technical Workshop 1 - Advanced Network Management
11. The Truth Is Out There...
Search before indulging in a potentially long and complex coding project
Someone else has been there before and has probably written a script
If in doubt, ask the team!
Technical Workshop 1 - Advanced Network Management
12. All The Time In The World...
Scripting is a long-term gain, but a short-term loss...
A script can save you time once completed, but it will need a fair amount of time and energy to be invested in its initial development.
Even when your script is done, you will find yourself spending further time and resources on testing and improving it.
Technical Workshop 1 - Advanced Network Management
13. Can You Handle The Truth?
Technical Workshop 1 - Advanced Network Management
TAKE THE RED PILL:
Stay in Wonderland and I show you how deep the rabbit-hole goes...
TAKE THE BLUE PILL:
The story ends, you wake up in your bed and believe whatever you want to believe...
THE CHOICE IS YOURS...
14. Scripting Essentials
A LOOK AT WINDOWS SHELL SCRIPTING
Technical Workshop 1 - Advanced Network Management
15. Scripting Essentials Overview
What is shell scripting?
What can/cant it do?
What else is out there?
How do I get started?
Where do I learn more?
Will this happen to me?
Technical Workshop 1 - Advanced Network Management
16. What is Shell Scripting?
A collection or batch of commands run in sequence to complete a task or set of tasks.
Quick and easy method of automating the most common admin or user tasks.
An essential tool for both improving task efficiency and time management.
Technical Workshop 1 - Advanced Network Management
17. What can/cant shell scripts do?
Technical Workshop 1 - Advanced Network Management
18. What Else Is Out There?
Technical Workshop 1 - Advanced Network Management
19. Code Writing Guidelines
Technical Workshop 1 - Advanced Network Management
20. When In Rome (or America)...
Scripts are designed to be written in American English.
Regional Settings will not change the commands
Correct spelling is critical- It is the American Way!
e.g. COLOR, Favorites, Organization, Customize, etc
Technical Workshop 1 - Advanced Network Management
21. Shell Command Symbols
Technical Workshop 1 - Advanced Network Management
22. Shell Prompt Modification
Technical Workshop 1 - Advanced Network Management
23. Arguments & Variables
ARGUMENTS
Represented by single % symbol
Values set by end user
Numbered from 1 (0 is script)
Generally used as switchese.g. ArguVars.cmd/test
VARIABLES
Identified by enclosed % symbols
Values set by OS or script writer
Named by OS or script writer
Can be used as argumentse.g. ArguVars.cmd%os%
Technical Workshop 1 - Advanced Network Management
24. Environmental Variables
Technical Workshop 1 - Advanced Network Management
25. Environmental Variables (cont.)
Technical Workshop 1 - Advanced Network Management
26. Internal & External Commands
INTERNAL COMMANDS
Part of CMD shell
No file extensions
Cannot run without shell
Help command can be usede.g. HELP DIR
EXTERNAL COMMANDS
Separate from CMD shell
Usually .exe or .com extensions
Can be run outside of shell
External help is usually needede.g. MSTSC/?
Technical Workshop 1 - Advanced Network Management
27. Internal Commands
Technical Workshop 1 - Advanced Network Management
28. Internal Commands (cont.)
Technical Workshop 1 - Advanced Network Management
29. External Commands
Technical Workshop 1 - Advanced Network Management
30. External Commands (cont.)
Technical Workshop 1 - Advanced Network Management
31. Recommended Code Layout
@ECHO off- only show output
CLS- clear screen
:START- label start of code
TITLE- window/script title
REM- author/copyright
:RUN- label body of code
REM- command notes
ECHO- a command to run
:FINISH- label end of code
REM- closing comments
GOTO :EOF- exit the script
Technical Workshop 1 - Advanced Network Management
32. Importance of Comments and Layout
Technical Workshop 1 - Advanced Network Management
33. FOR
Used to iterate (repeat) tasks
USAGE:
Uses lettered arguments with double % symbol in scripts and single % symbol from shell
Requires in and do functions
COMMON SWITCHES:
Follow numeric series: FOR /l
Perform file functions: FOR /f
Technical Workshop 1 - Advanced Network Management
34. IF
Allows for conditional tasks
USAGE
Follow with not for negatives
Uses else in place of multiples
Case sensitive unless /i is used
Uses double = symbol in scripts and single = symbol in shell
COMMON USES:
File Check: IFexist %path%
Variable Check: IFdefined os
Compare: IF%1==%path%
Technical Workshop 1 - Advanced Network Management
35. SET
Creates temporary variables
Values from script writer or user
Performs arithmetic functions
COMMON USES:
Set Variable: SETvar=value
Calculate: SET/a var=equation
Prompt:SET/p var=question
Technical Workshop 1 - Advanced Network Management
36. Green Code is Good Code
RE-USABLE CODE:
Mini-script within main script
Reduces development time
Guarantees fewer mistakes
Improves code legibility
USAGE GUIDELINES:
Use labels to identify routines
Use arguments and variables
Should be after end of script
Must be called not directed to
Technical Workshop 1 - Advanced Network Management
37. I can only show you the door, you're the one that has to walk through it...
Technical Workshop 1 - Advanced Network Management
38. Script This!
Print a line of text
Clear the screen
Change window color
View a text file
Save output to a file
Create a variable
Compare a variable
Repeat a file task
Calculate an equation
ECHOvalue
CLS
COLOR value
TYPEpathfile.ext
IPCONFIG> file.ext
SETvar=value
IF %var%==value
FOR/f%%ain (cmd) do
SET/avar=equation
Technical Workshop 1 - Advanced Network Management
39. Un-script This!
Disables command echo
Change window title
Run the SUBTASK routine
Exit the script
Show a file in single pages
Check for variable
Check if command worked
Prompt user for value
Perform a task five times
@ECHO off
TITLE value
CALL :SUBTASK
GOTO:EOF
TYPEfile.ext |MORE
IFDEFINEDvar
IF %errorlevel%==0
SET/p var=value
FOR/l%%ain (1,1,5) do
Technical Workshop 1 - Advanced Network Management
40. Scripting Resources
Web Links
Books
CS Portal Script Repositoryhttp://tinyurl.com/cspscripts
Frank-Peter Schultze Scriptshttp://tinyurl.com/fpschultze
TSCMD FAQ: Scripting Trickshttp://tinyurl.com/tscmdfaq
TechNet A-Z Command Referencehttp://tinyurl.com/mscmdref
Backup Exec 11d Documentshttp://tinyurl.com/be11docs
Backup Exec 12d Documentshttp://tinyurl.com/be12doczip
Windows NT Shell ScriptingISBN: 1-57870-047-7
Zero Administration for WindowsISBN: 1-56592-508-4
Windows 2000 Active DirectoryISBN: 1-56592-638-2
Windows 2000 Scripting BibleISBN: 0-7645-4677-5
Windows Desktop Deployment Resource KitISBN: 0-7356-1898-4
Windows Command Pocket ConsultantISBN: 0-7356-2262-0
Technical Workshop 1 - Advanced Network Management
41. Toolkit Essentials
VITAL TOOLS AND UTILITIES FOR ALL TECHIES
Technical Workshop 1 - Advanced Network Management
42. Technical Workshop 1 - Advanced Network Management
43. Utility Disc DigiWiz miniPE2-XT
Technical Workshop 1 - Advanced Network Management
44. Utility Disc Hirens Boot CD
Technical Workshop 1 - Advanced Network Management
DOS Utility Boot CD
with additional Windows Tools
45. Recommended Tools
Script Writing:
Notepad2
Notepad++
System Information:
AIDA32
EZAudit
Password Reset:
Password Renew
NT Offline Password Reset
Product Key Recovery:
Magic Jelly Bean Keyfinder
NirsoftProduKey
File Compression:
IzArc2Go
7-Zip
Disk Cloning:
Symantec Ghost
Acronis True Image
Disk Partitioning:
Partition Magic
Paragon Partition Manager
Partition Recovery:
TestDisk
Ontrack Easy Recovery Pro
Deep Data Recovery:
NTFS Undelete
GetDataBack-NTFS/GetDataBack-FAT
User Friendly Data Recovery:
Recuva
Restoration
Technical Workshop 1 - Advanced Network Management
46. Recommended Tools (cont.)
Floppy/USB Key Cloning:
WinImage
AntiSpyware:
SDFix
Webroot Spy Sweeper
CD Image Creation:
LCISOCreator
ISO Buster
CD Burning:
ImgBurn
Express Burn
Disk Defragmentation:
Defraggler
JkDefrag
File Copier:
FastCopy
SyncToy
System Optimisation:
CCleaner
WinASOEasyTweak
Driver Backup and Restore:
Smart Driver Backup
DriverBackup!
PE Editor:
Resource Hacker
PE Resource Explorer
Personal Antivirus:
Avast!
NOD32
Technical Workshop 1 - Advanced Network Management