New
#831
That was something @Kari showed me how to do once, I believe it was for a reminder for the upcoming Anniversary Update at the time, after which I changed the text and target date.
You need one for PowerShell and PowerShell ISE
At the time when I showed how to do it, we were counting days to release of Anniversary Update, I just added a countdown to script :).
Anyway, the purpose was to show how to do a basic PowerShell script. This script sets working folder to whatever you want to when you launch PowerShell, be it in normal or elevated mode. It also shows how to do "If A, then B, else C" in PS script, and how to handel 12 and 24 hour time .
Script:
Code:$Hour = Get-Date -Format "HH:mm" $Now = Get-Date -Format "HH:mm (h:mm tt)" If ($Hour -lt "06:00") {Write-Host "It's quite late" $env:username". The time is "$Now} ElseIf ($Hour -lt "12:00") {Write-Host "Good morning" $env:username". The time is "$Now} ElseIf ($Hour -lt "18:00") {Write-Host "Good afternoon" $env:username". The time is "$Now} ElseIf ($Hour -ge "18:00") {Write-Host "Good evening" $env:username". The time is "$Now} Write-Host Set-Location $env:USERPROFILE
Save as Microsoft.PowerShell_profile.ps1 in folder %userprofile%\Documents\WindowsPowerShell for PowerShellShell, as Microsoft.PowerShellISE_profile.ps1 (letters ISE added to filename).
Result:
Script also works when powershell session is started in Command Prompt:
If the script asks if you want to run it every time you open PS, enable running local scripts:
Kari
Thanks Cliff S and Kari for taking the time to answer that one, how does one do the countdown timer?
Follow Kari's instructions step for step.
Here is a copy of mine, open it in Notepad and make any needed text changes(like your name, birthdate or event, and the user folder address):
Microsoft.PowerShellISE_profile.zip
Thanks Cliff S, I edited your script except the countdown results is wrong, it should be 161 days, not sure what I am doing wrong. This is my script:
when I run it, it says:Code:$Hour = Get-Date -Format "HH:mm" $Now = Get-Date -Format "HH:mm (h:mm tt)" $January01 = "01 January 2018" $NewYear = [system.datetime]$January01 $Today = Get-Date $ToGo = ($NewYear.DayOfYear - $Today.DayOfYear) If ($Hour -lt "06:00") {Write-Host "It's quite late Almighty1. The time is"$Now} ElseIf ($Hour -lt "12:00") {Write-Host "Good morning Almighty1. The time is"$Now} ElseIf ($Hour -lt "18:00") {Write-Host "Good afternoon Almighty1. The time is"$Now} ElseIf ($Hour -ge "18:00") {Write-Host "Good evening Almighty1. The time is"$Now} Write-Host $ToGo "days to go until 2018!" Write-Host
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
Good morning Almighty1. The time is 07:50 (7:50 AM)
-203 days to go until 2018!
PS C:\WINDOWS\system32>
You are taking DayOfYear for new years day (which is 1) and subtracting todays DayOfYear (204).1 - 204 = -203 which is what you are seeing. Your script above only works if the date you are comparing is further on in the same year.Code:PS C:\WINDOWS\system32> $NewYear.DayOfYear 1 PS C:\WINDOWS\system32> $Today.DayOfYear 204
Drop the DayOfYear from the calculation as you don't want it - like thisThis gives you various options to display...Code:PS C:\WINDOWS\system32> $ToGo = $NewYear - $TodayCode:PS C:\WINDOWS\system32> $ToGo Days : 161 Hours : 6 Minutes : 52 Seconds : 54 Milliseconds : 268 Ticks : 139351742683404 TotalDays : 161.286739216903 TotalHours : 3870.88174120567 TotalMinutes : 232252.90447234 TotalSeconds : 13935174.2683404 TotalMilliseconds : 13935174268.3404 PS C:\WINDOWS\system32> Write-Host $ToGo "to go until 2018!" 161.06:52:54.2683404 to go until 2018! PS C:\WINDOWS\system32> Write-Host $ToGo.Days "days to go until 2018!" 161 days to go until 2018! PS C:\WINDOWS\system32> Write-Host $ToGo.TotalSeconds "seconds to go until 2018!" 13935174.2683404 seconds to go until 2018!
Last edited by lx07; 23 Jul 2017 at 10:44.
Thanks lx07! That makes sense, was confused since Cliff's original script was for his next birthday which is still in 2017 as it didn't happen yet.
Sooo,
Magician is safe to disable, right? Like, I have AHCI and TRIM enabled, but disabling run at startup won't change that? After I've set it up, it's basically just a monitoring tool, correct? Like, it doesn't do anything on like a driver level?
Or something with caching?