Question

In: Computer Science

I would like to see a PowerShell script(for purely inspirational work to use as an inspiration...

I would like to see a PowerShell script(for purely inspirational work to use as an inspiration for helping to develop my skills as a hobby.

*** This should all be done in a loop **

Before beginning, You will need a simple text file with three weeks of scores between Michigan and Michigan State. Example:

UM21, MSU 14

UM28, MSU 35,

UM14, MSU 3

1) Then I need a loop that reads in the attached text file

2) Read the scores by school and determine if MSU or Michigan won or lost

3) - if the wolverines win, have user put the score into the win file (win.txt)

                ** UM win over MSU55-10 **

    - if the wolverines encounter a loss, put the score in the loss file (loss.txt)

               ** wolverines lose to spartans 24-17 **

  NOTE: the permission must be changed on the file in order to write to it

  *** the file permission switching must be done in separate script ***

4) please zip contents of wolverines and sparty directories

Solutions

Expert Solution

The powershell script is given below(the important lines are commented):-

foreach($line in Get-Content C:\Users\user\Documents\scores.txt) {

#Splitting each line of the file to scores of UM and MSU
$arr = $line.split(",")

$len1 = $arr[0].length - 2
$len2 = $arr[1].length - 5

#Extracting the actual score values from the scores of UM and MSU
$value1 = $arr[0].Substring(2,$len1)
$value2 = $arr[1].Substring(5,$len2)
  
  
# As the values are in String,converting them to integer for comparision purposes
$integer1 = [convert]::ToInt32($value1,10)
$integer2 = [convert]::ToInt32($value2,10)


if($integer1 -gt $integer2){
#Writing the output to the win.txt file
Write-Output ('** UM win over MSU ' + $($integer1) + '-' + $($integer2) + ' **') | Out-File -Append -FilePath C:\Users\user\Documents\win.txt

}
else{
#Writing the output to the lose.txt file
Write-Output ('** wolverines lose to spartans ' + $($integer1) + '-' + $($integer2) + ' **') >> C:\Users\user\Documents\lose.txt
}

#Re-initializing the output for using again in the loop   
$arr = @()
$value1 = 0
$value2 = 0
$integer1 = 0
$integer2 = 0
}


#You can use the below command to zip the text files into an archive but as it is available in Powershell 5.0 which I don't have
#Compress-Archive -Path C:\Users\user\Documents\*.txt -Update -DestinationPath archive.zip


Related Solutions

I work in Supply Chain in the Procurement Dept. I would like to use my dept...
I work in Supply Chain in the Procurement Dept. I would like to use my dept for this assignment. Please do not copy what's already in Chegg. Process Improvement Project For this assignment select either your own organization or an organization about which you know enough to review the supply chain processes and identify a process that can be improved in your sphere of influence. Phase I: Improvement Opportunity Write 500-750 words on improvement opportunity in your sphere of influence....
In PowerShell ISE create a script. Use the text file “its3410Users.txt” (found on Canvas) and import...
In PowerShell ISE create a script. Use the text file “its3410Users.txt” (found on Canvas) and import the users into your domain controller. The user file has a first name, last name, and department. Using this information, create users with the following specifications: Username will be first name.last name User Principal Name will be first name.last [email protected] The department signifies the OU that the user will be placed into If the department does not exist, create it Fill in the first...
How would I work the following problems out? I would like someone to show their work...
How would I work the following problems out? I would like someone to show their work so I could better understand the answers and thought process. Genetics Problems For the first couple of problems, you will be working with guinea pigs. Their coat color shows an example of complete dominance - black (B) is dominant over brown (b). 1. A heterozygous black male is crossed with a heterozygous black female. What would be the resulting phenotypic ratio in the offspring?...
I would like to see a proof of the Central Limit Theorem that applies to a...
I would like to see a proof of the Central Limit Theorem that applies to a simple probability dice scenerio, say rolling a 6 x amount of times. The goal is to help me understand the theorem with a simple example. Thanks!
Hi I would like to see an example in c++ of Stack As Linked List I...
Hi I would like to see an example in c++ of Stack As Linked List I need a seek() function which receives a double number X and which returns in which position in the stack is X. If the value X is not in the stack, the function should return -1
I am in a statistics class. When I graduate, I would like to work in an...
I am in a statistics class. When I graduate, I would like to work in an area where I can help restructure businesses that are failing and make them successful. My professor has asked me where in my career that I think I will use the process of data collection. He has asked me to provide 2 examples. This is my first statistics class, so I don't really know of how to give him any examples. Can you please give...
I Have practice PICOT questions that I would like to see if my answers are close...
I Have practice PICOT questions that I would like to see if my answers are close to correct. Read the scenario, choose the one form of PICOT question that fits the scenario. state if its INTERVENTION ETIOLOGY, DIAGNOSIS OR DIAGNOSTIC TEST, PROGNOSIS/PREDICTION, or MEANING PICOT Scenarios 1. The patient is a 73-year-old white woman admitted to the hospital with heart failure. She is compliant and seldom misses her medications. On admission, her medications were furosemide 40 mg po qd, enalapril...
I Have practice PICOT questions that I would like to see if my answers are close...
I Have practice PICOT questions that I would like to see if my answers are close to correct. Read the scenario, choose the one form of PICOT question that fits the scenario. state if its INTERVENTION ETIOLOGY, DIAGNOSIS OR DIAGNOSTIC TEST, PROGNOSIS/PREDICTION, or MEANING. I have to use these templates for creating the PICOT question. Question Templates for Asking PICOT Questions INTERVENTION In ____________________(P), how does ____________________ (I) compared to ____________________(C) affect _____________________(O) within ___________(T)? ETIOLOGY Are____________________ (P), who have...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell that says payment is undefined. I am trying to create a main.js file that imports the function from the hr.js file; call the function passing the necessary arguments and log the result to the console. main.js var Dev = require("./hr.js") const { add } = require("./hr.js") var dev_type = 1; var hr = 40; console.log("your weekly payment is " + payment(dev_type, hr)) dev_type =...
I would just like to know if ANOVA would be the correct test to use for...
I would just like to know if ANOVA would be the correct test to use for the following problem below? Fancy Fish, a fine dining upscale restaurant in Northridge, California and 2016 Open Table Diners’ Choice award winner, is enjoying its eighteenth season of providing delectable food, exceptional service, and beautiful outdoor dining experiences. “Saturday - Half-off Bottled Wine Night” has made Fancy Fish one of the San Fernando Valley’s favorite restaurants. Every Saturday night, guests can enjoy half-off every...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT