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 |
#======================================================================== # Generated On: 17.03.2014 13:45 # Generated By: Stéphane van Gulick - www.PowerShelldistrict.com #======================================================================== #region Source: Startup.pfs #---------------------------------------------- #region Import 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 #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