adding results of powershell script to text file


This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 1 year ago.

  • Author
  • #31210
    Profile photo of John Hartmann
    John Hartmann

    I emailed my Ph.D instructor, and I am still really lost on how to complete what needs to be completed. I would appreciate any help or tips.
    I made a script that you give a range of number to. You then input a number as your guess. It tells you if it is above or below the correct number. You keep guessing numbers until you guess the right number. Then I coded a timer to tell me how long the game was played. The part I need help with is: how to I add the number of times played, and the shortest and longest times to a text file. another part that stumped me, is the log needs to update after each run of the script. Attached is my code so far.

    #John Hartmann 10/22/2015
    #a guessing game

    $rand = new-object system.randon
    $randomnumber = $,11)

    write-host "this is a simple guessing game"
    write-host "input a range of numbers between"
    write-host "1 and 10, the program picks a"
    write-host "random number, you will guess"
    write-host "until you guess the write number"

    [int]$rangestart = Read-Host "enter starting value"
    [int]$rangestart = Read-Host "enter ending value"

    $starttime = (get-date)

    do {$a = read-host -prompt "What is your guess? "
    if ($a -gt $randomnumber) {Write-Host "Too High, Guess Again!"}
    elseif ($a -lt $Randomnumber) {Write-Host "Too Low, Guess Again!"}
    elseif ($a -eq $randomnumber) {Write-Host "You did it!! It took you $g tries!"}
    else {"You have to guess a number!!!"}
    $g = $g + 1
    } while ($a -ne $randomnumber)

    $endtime = (get-date)
    "elapsed time: $(($endtime-$starttime).totalseconds) seconds"

  • #31213
    Profile photo of Curtis Smith
    Curtis Smith

    Use the get-command cmdlet to see what is available to you for sending data out. Some potentially useful verbs could be send, out, export, etc.

You must be logged in to reply to this topic.