OS Lab 3
OS Lab 3
LAB OBJECTIVE: To get familiar with windows power shell (command –line shell) and
working with its commands (cmdlets) and scripts.
INTRODUCTION
Windows PowerShell (PS) is a command-line shell and scripting language designed especially
for system administration. Its analogue in Linux is called as Bash Scripting. Built on the .NET
Framework, Windows PowerShell helps IT professionals to control and automate the
administration of the Windows operating system and applications that run on Windows Server
environment. Windows PowerShell commands, called cmdlets, let you manage the computers
from the command line. Windows PowerShell providers let you access data stores, such as the
Registry and Certificate Store, as easily as you access the file system.
Arithmetic operator in PS
Comparison Operators
Operator Description Example
ge (greater than or Compares first value to be greater than or equals to B -ge A will
equals to) second one. give true
Logical Operators
Variable declaration
$x = 10
Output function
write-host("This is first script")
Conditions
If: statement consists of a Boolean expression followed by one or more statements.
Syntax
Following is the syntax of an if statement −
if(Boolean_expression) {
// Statements will execute if the Boolean expression is true
}
$x = 10
DEPARTMENT OF INFORMATION TECHNOLOGY
FACULTY OF ENGINEERING AND TECHNOLOGY
UNIVERSITY OF SINDH, JAMSHORO
if($x -le 20){
write-host("This is if statement")
IF- esle
$x = 30
write-host("This is if statement")
}else {
Else-if
$x = 30
write-host("Value of X is 20")
write-host("Value of X is 30")
} else {
Exercise
Write Shell Script which checks a number that whether it is even or odd and prints the
message on screen
Write Shell Script which checks a number that whether it is positive or negative and
prints the message on screen
Write Shell Script which compares 2 numbers and prints the greater