Code below collect user input and uses switch case statement to check if the input matches, and if it matches a function is called that will execute commands.
Here’s the
code:
#get or
read from user input
$computer_name = read-host ("Enter Computer Name:")
switch ($computer_name )
{
#if the input is computer_1 then function
func_comuputer1 is called
computer_1 {func_computer1}
computer_2 {func_computer2}
}
#function called if computer_1 is the input
function func_computer1 {
write-host "You entered Computer_1"
#or replaced with other function like reboot / shutdown /or
other commands
#Restart-Computer -ComputerName computer_1
}
#function called if computer_2 is the input
function func_computer2 {
write-host "You entered Computer_2"
#or replaced with other function like reboot / shutdown /or
other commands
#Ex: Enter-Pssession computer_2
}
Code below will keep asking for input and will only exit if a specific string matches to exit the script.
Here’s the code:
do {
{
computer_1 {func_computer1}
computer_2 {func_computer2}
} until ($computer_name -eq "exit_computer")
function func_computer1 {
write-host "You entered Computer_1"
#or replaced with other function like reboot / shutdown /or
other commands
#Restart-Computer -ComputerName computer_1
}
function func_computer2 {
write-host "You entered Computer_2"
#or replaced with other function like reboot / shutdown /or
other commands
#Ex: Enter-Pssession computer_2
}
Cheers..till next time!
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment