I am going to teach you something you most likley don’t know about your self ? Yes yes, that is possible !
You know your birthdate, your birthday, and how old you are expressed in “years”. But have you ever though of how long you have been living in days ? minutes or even seconds ? Well, here you go !
I wrote this script in not even an hour. this will tell you in a very basic way, for how many days, minutes, seconds, hours you have been happily living on our little blue planet 😀
The script is pretty straightforward, and has been developped just because I was a bit “bored” (Yeah, that must be my nerdy side ;)).
Here is the code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
#======================================================================== # Generated On: 17.03.2014 13:45 # Generated By: Stéphane van Gulick - www.PowerShelldistrict.com #======================================================================== #region Source: Startup.pfs #---------------------------------------------- #region Import Assemblies #---------------------------------------------- [/fusion_builder_column][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"][void][Reflection.Assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") [void][Reflection.Assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") #endregion Import Assemblies #Define a Param block to use custom parameters in the project #Param ($CustomParameter) function Main { Param ([String]$Commandline) #Note: This function starts the application #Note: $Commandline contains the complete argument string passed to the packager #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path #Note: To get the console output in the Packager (Forms Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList) #TODO: Initialize and add Function calls to forms if((Call-MainForm_pff) -eq "OK") { } $global:ExitCode = 0 #Set the exit code for the Packager } #endregion Source: Startup.pfs #region Source: MainForm.pff function Call-MainForm_pff { #---------------------------------------------- #region Import the Assemblies #---------------------------------------------- [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") #endregion Import Assemblies #---------------------------------------------- #region Generated Form Objects #---------------------------------------------- [System.Windows.Forms.Application]::EnableVisualStyles() $MainForm = New-Object 'System.Windows.Forms.Form' $Mtxb_Birthday = New-Object 'System.Windows.Forms.MaskedTextBox' $Gbx_TimeType = New-Object 'System.Windows.Forms.GroupBox' $Rbtn_Minutes = New-Object 'System.Windows.Forms.RadioButton' $Rbtn_Seconds = New-Object 'System.Windows.Forms.RadioButton' $Rbtn_Hours = New-Object 'System.Windows.Forms.RadioButton' $Rbtn_Days = New-Object 'System.Windows.Forms.RadioButton' $Dtp_BornDate = New-Object 'System.Windows.Forms.DateTimePicker' $Lbl_AliveSince = New-Object 'System.Windows.Forms.Label' $lbl_Birthdate = New-Object 'System.Windows.Forms.Label' $Btn_Check = New-Object 'System.Windows.Forms.Button' $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' #endregion Generated Form Objects #---------------------------------------------- # User Generated Script #---------------------------------------------- $OnLoadFormEvent={ #TODO: Initialize Form Controls here $Now = Get-Date $Rbtn_Days.Checked = $true $Dtp_BornDate.ShowCheckBox = $true $Dtp_BornDate.Checked = $false $Dtp_BornDate.MaxDate = $Now $Mtxb_Birthday.Text= "16/04/1983" $Lbl_AliveSince.Text = "www.PowershellDistrict.com" } $Btn_Check_Click={ $Now = Get-Date if ($Dtp_BornDate.Checked -eq $true){ $BrithDate = $Dtp_BornDate.Value } else{ $BrithDate = $Mtxb_Birthday.Text } #$BrithDate = Get-Date $Mtxb_Birthday.Text $TimeSpan = New-TimeSpan -start $BrithDate -end $Now if ($Rbtn_Hours.Checked){ $TimeType = "hours" } if ($Rbtn_Days.Checked){ $TimeType = "days" } if ($Rbtn_Seconds.Checked){ $TimeType = "seconds" } if ($Rbtn_Minutes.Checked){ $TimeType = "minutes" } switch ($TimeType) { "Days" { $Alive = $TimeSpan.totaldays } "hours" { $Alive = $TimeSpan.totalhours } "minutes" { $Alive = $TimeSpan.totalminutes } "seconds" { $Alive = $TimeSpan.Totalseconds } default { $TimeType = "Days" $Alive = $TimeSpan.totaldays } } [int]$Alive=$Alive $Lbl_AliveSince.Text = "You have been alive for $($Alive) $TimeType ! :D" } $Dtp_BornDate_ValueChanged={ #TODO: Place custom script here $Mtxb_Birthday.Text = $Dtp_BornDate.Value } # --End User Generated Script-- #---------------------------------------------- #region Generated Events #---------------------------------------------- $Form_StateCorrection_Load= { #Correct the initial state of the form to prevent the .Net maximized form issue $MainForm.WindowState = $InitialFormWindowState } $Form_StoreValues_Closing= { #Store the control values $script:MainForm_Rbtn_Minutes = $Rbtn_Minutes.Checked $script:MainForm_Rbtn_Seconds = $Rbtn_Seconds.Checked $script:MainForm_Rbtn_Hours = $Rbtn_Hours.Checked $script:MainForm_Rbtn_Days = $Rbtn_Days.Checked $script:MainForm_Dtp_BornDate = $Dtp_BornDate.Value } $Form_Cleanup_FormClosed= { #Remove all event handlers from the controls try { $Dtp_BornDate.remove_ValueChanged($Dtp_BornDate_ValueChanged) $Btn_Check.remove_Click($Btn_Check_Click) $MainForm.remove_Load($OnLoadFormEvent) $MainForm.remove_Load($Form_StateCorrection_Load) $MainForm.remove_Closing($Form_StoreValues_Closing) $MainForm.remove_FormClosed($Form_Cleanup_FormClosed) } catch [Exception] { } } #endregion Generated Events #---------------------------------------------- #region Generated Form Code #---------------------------------------------- # # MainForm # $MainForm.Controls.Add($Mtxb_Birthday) $MainForm.Controls.Add($Gbx_TimeType) $MainForm.Controls.Add($Dtp_BornDate) $MainForm.Controls.Add($Lbl_AliveSince) $MainForm.Controls.Add($lbl_Birthdate) $MainForm.Controls.Add($Btn_Check) $MainForm.AutoScaleMode = 'Inherit' $MainForm.ClientSize = '326, 308' $MainForm.Name = "MainForm" $MainForm.StartPosition = 'CenterScreen' $MainForm.Text = "I am Alive ! :D" $MainForm.add_Load($OnLoadFormEvent) # # Mtxb_Birthday # $Mtxb_Birthday.Location = '106, 63' $Mtxb_Birthday.Mask = "00/00/0000" $Mtxb_Birthday.Name = "Mtxb_Birthday" $Mtxb_Birthday.Size = '72, 22' $Mtxb_Birthday.TabIndex = 6 $Mtxb_Birthday.ValidatingType = [System.DateTime] # # Gbx_TimeType # $Gbx_TimeType.Controls.Add($Rbtn_Minutes) $Gbx_TimeType.Controls.Add($Rbtn_Seconds) $Gbx_TimeType.Controls.Add($Rbtn_Hours) $Gbx_TimeType.Controls.Add($Rbtn_Days) $Gbx_TimeType.Location = '5, 91' $Gbx_TimeType.Name = "Gbx_TimeType" $Gbx_TimeType.Size = '309, 60' $Gbx_TimeType.TabIndex = 5 $Gbx_TimeType.TabStop = $False $Gbx_TimeType.Text = "Time type" # # Rbtn_Minutes # $Rbtn_Minutes.Location = '133, 21' $Rbtn_Minutes.Name = "Rbtn_Minutes" $Rbtn_Minutes.Size = '79, 24' $Rbtn_Minutes.TabIndex = 0 $Rbtn_Minutes.TabStop = $True $Rbtn_Minutes.Text = "Minutes" $Rbtn_Minutes.UseVisualStyleBackColor = $True # # Rbtn_Seconds # $Rbtn_Seconds.Location = '215, 21' $Rbtn_Seconds.Name = "Rbtn_Seconds" $Rbtn_Seconds.Size = '87, 24' $Rbtn_Seconds.TabIndex = 0 $Rbtn_Seconds.TabStop = $True $Rbtn_Seconds.Text = "Seconds" $Rbtn_Seconds.UseVisualStyleBackColor = $True # # Rbtn_Hours # $Rbtn_Hours.Location = '69, 21' $Rbtn_Hours.Name = "Rbtn_Hours" $Rbtn_Hours.Size = '69, 24' $Rbtn_Hours.TabIndex = 0 $Rbtn_Hours.TabStop = $True $Rbtn_Hours.Text = "Hours" $Rbtn_Hours.UseVisualStyleBackColor = $True # # Rbtn_Days # $Rbtn_Days.Location = '6, 21' $Rbtn_Days.Name = "Rbtn_Days" $Rbtn_Days.Size = '61, 24' $Rbtn_Days.TabIndex = 0 $Rbtn_Days.TabStop = $True $Rbtn_Days.Text = "Days" $Rbtn_Days.UseVisualStyleBackColor = $True # # Dtp_BornDate # $Dtp_BornDate.Location = '30, 35' $Dtp_BornDate.Name = "Dtp_BornDate" $Dtp_BornDate.Size = '241, 22' $Dtp_BornDate.TabIndex = 4 $Dtp_BornDate.add_ValueChanged($Dtp_BornDate_ValueChanged) # # Lbl_AliveSince # $Lbl_AliveSince.Location = '30, 210' $Lbl_AliveSince.Name = "Lbl_AliveSince" $Lbl_AliveSince.Size = '241, 75' $Lbl_AliveSince.TabIndex = 3 $Lbl_AliveSince.TextAlign = 'MiddleCenter' # # lbl_Birthdate # $lbl_Birthdate.Location = '75, 9' $lbl_Birthdate.Name = "lbl_Birthdate" $lbl_Birthdate.Size = '149, 23' $lbl_Birthdate.TabIndex = 2 $lbl_Birthdate.Text = "Type in your brithdate" # # Btn_Check # $Btn_Check.Location = '30, 157' $Btn_Check.Name = "Btn_Check" $Btn_Check.Size = '241, 50' $Btn_Check.TabIndex = 0 $Btn_Check.Text = "Check" $Btn_Check.UseVisualStyleBackColor = $True $Btn_Check.add_Click($Btn_Check_Click) #endregion Generated Form Code #---------------------------------------------- #Save the initial state of the form $InitialFormWindowState = $MainForm.WindowState #Init the OnLoad event to correct the initial state of the form $MainForm.add_Load($Form_StateCorrection_Load) #Clean up the control events $MainForm.add_FormClosed($Form_Cleanup_FormClosed) #Store the control values when form is closing $MainForm.add_Closing($Form_StoreValues_Closing) #Show the Form return $MainForm.ShowDialog() } #endregion Source: MainForm.pff #region Source: Globals.ps1 #-------------------------------------------- # Declare Global Variables and Functions here #-------------------------------------------- #Sample function that provides the location of the script function Get-ScriptDirectory { if($hostinvocation -ne $null) { Split-Path $hostinvocation.MyCommand.path } else { Split-Path $script:MyInvocation.MyCommand.Path } } #Sample variable that provides the location of the script [string]$ScriptDirectory = Get-ScriptDirectory #endregion Source: Globals.ps1 #Start the application Main ($CommandLine) |
Anyways, if you like the little tool, or whatsoever, just leave me a comment here below ^^
Enjoy 😀
Nice work for your first steps in PowerShell Studio 😀
What if I was born on another timezone ? 😉
Can this be included in the script ?
Fx