Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # Pipe find specifid string into systeminfo output so only that line is exported
  2. systeminfo | find "System Boot Time" > SystemBootTime.txt
  3.  
  4. #Insert file contents into new variable
  5. $BootTimeString = Get-Content .\SystemBootTime.txt
  6.  
  7. #Edit contents of the previous variable to make it ead like a date and make a new variable from it
  8. $BootTimeValue = $BootTimeString.TrimStart("System Boot Time: ") -replace '[,]'
  9.  
  10. #force the fomatting of the previous variables content into a datetime type and place in a new variable
  11. $BootTime = [datetime]::ParseExact("$BootTimeValue", 'dd/MM/yyyy HH:mm:ss', $null)
  12.  
  13. #Get the current time
  14. $Now = Get-Date
  15.  
  16. #Compare the boot time with the current time and format the output into total minutes and current seconds.
  17. NEW-TIMESPAN -Start $BootTime -End $Now | Select-Object @{Label="Minutes";Expression={[math]::Floor($_.TotalMinutes)}}, Seconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement