PowerShell Practice Programs
PowerShell Practice Programs
Practice 1:
Create arrays 1 and 2 as below. The 3 rd array should show the sum of
each corresponding value in array 1 & 2
Array2
Array1 1
1 Array3
3
8 2
9
0 11
8
8 9
16
Practice 2:
Create 2 hash tables as below and the 3rd hash table should be
calculated as (days worked *salary per day)
Name Days worked
John 12
Joe 20
Mary 18
Name Salary per day
John 100
Joe 120
Mary 150
Output:
Name Salary
John 1200
Joe 2400
Mary 2700
Practice 3:
Ask a question “what is your name” and then display the answer
provided in “Green” color
Practice 4:
I) Ask the user for 2 values and then compare them and then
display the value which is bigger in the form as “The higher
number is : X”
II) Display the menu as below and ask the user to select the
country. Based on the choice entered, display the
corresponding country’s capital
Practice 5:
i. Open two instances of notepad on your machine and find their
Process ID. The output should only show the “Process Name” and “Id”.
ii. Create a folder “C:\Temp\Test” and copy paste any one sample CSV
and two TXT file in it.
First show the total files in the folder and then find only the csv file in
it and display its size in KB and MB as shown in the screenshot.
Practice 6:
Create the below CSV and save it locally on your computer.
Name Age
John 12
Joe 8
Mary 7
Tom 15
Lily 16
Emily 9
Practice 7:
Suppose there are 20 students (Roll Number 1-20) and they must be
randomly assigned a group out of 4 colors (Red, Green, Yellow, Blue).
The output table should look like something like below but please
note that the color assigned should be random to each student.
Roll Number Group
1 Red
2 Yellow
3 Blue
4 Red
5 Green
6 Yellow
Practice 8:
Open 3 instances of ‘Notepad’ on your machine. Write a code that
should display that ‘Notepad is running’ till it is open. Start closing
notepad one by one and once all 3 are closed, the loop should end.
Practice 9:
Open 3 instances of notepad. Write a code using ‘do while’ loop which
should display “Notepad is running” but an interval of 1 second. Once
all the instances have been closed, it should stop displaying that
“Notepad is running”. At the end, it should also show the number of
times, the statement was displayed.
Practice 10:
Perform the practice 9 as completed in ‘Do While’ loop but now using
‘Do Until’ loop.
Practice 11:
Ask user to first enter 2 numbers and then publish a menu to ask
which action should be performed on them.
Practice 12:
i) Using functions without parameter, find the count of total
services that are in running or stopped state.
ii) Using function with parameter, find the count of total services
that are in running or stopped state
Practice 13:
1)Write a menu-based script which when executed will first show
the below menu
2) If option 1 is selected, display a new menu and the previous one
should disappear.
3) Display the result and show another menu that will give the
options as below and perform the respective tasks.
4) If ‘1’ is selected, it should take you back to the ‘Main Menu’. If ‘2’
is selected, it should exit from the script and if any other entry is
made, it should display that the entry is incorrect and ask the user
to re-enter the option