powershell - Using the Get-Date cmdlet -


i taking scripting class part of degree , stumped on powershell script. have use get-date time how long game played, , create log file stores number of games played, , shorted , longest games played. log file must created outside script, must update within script. put code have far below.

$rand = new-object system.random $number= $rand.next(0,11) clear-host  do{ $a = read-host -prompt "enter number between 1 , 10" if ($a -gt $number) {write-host "number high"} elseif ($a -lt $number) {write-host "number low"} elseif ($a -eq $number) {write-host "you did it!! took $x tries!"} else {"you have guess number!!!"} $x = $x + 1  } while ($a -ne $number) $path = c:\temp\logfile.log.txt 

to time execution, grab date before , after you've done work, , subtract 2 timespan representing time took

$starttime = get-date # script goes here $endtime   = get-date $timetaken = $endtime - $starttime write-host "a total of $($timetaken.totalseconds) has passed" 

you use stopwatch class accomplish this:

$watch = [system.diagnostics.stopwatch]::startnew() # script goes here $watch.stop() $timetaken = $watch.elapsed write-host "a total of $($timetaken.totalseconds) has passed" 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -