| Author |
Topic  |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 04/26/2008 : 11:55:41 AM
|
As the old saying says: "A powershell help file a day, keeps Don Jones away"
On the plane back to Denmark, I wrote a little PowerShell script, that will show a "help file" every day.
What it does is write a number to a txt file, and count that number up every time the script is run, so you do not get the same help file two times. It is not pretty, but it seems to work 
[int]$HelpNr = Get-Content -Path c:\scripts\test.ini
$vhelp = Get-Help * | Get-Help
$i=0
foreach ($vvhelp in $vhelp){
$i++
if ($i -eq $HelpNr) {$vvhelp}
}
$HelpNr++
Set-Content -Path c:\scripts\test.ini -Value $HelpNr
|
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
|
|
DonJones
Here To Stay
 
USA
176 Posts
Status: offline |
Posted - 04/26/2008 : 1:07:05 PM
|
You'll love v2 when the next CTP releases (soon!):
Get-Help | Get-Random 1
(Syntax subject to change). This'll grab ALL the help topics and display a random one - so you're also seeing the "about" help topics mixed in with cmdlets.
For your script, consider doing something with the $profile variable for your file path, rather than a hardcoded file path. Finally, consider wrapping this in a function named Get-DailyHelp or something. That way, the function can be more easily included in the auto-run profile script so it runs as shell startup - or put into a new v2 module file!
Also, since there's no ONE right way to do anything, I'll offer an alternative. Assuming $i contains the number of the help file you want...
Get-Help | Select -first $i | Select -last 1
So if $i was 10, that would grab the 10th help file in the system. You'd then increment $i as you've done and write it out to that file. Another addition might be to have it check the date of the test.ini file, and only increment $i if the date on the file is older than today's date. That way, multiple runs of the same script on the same day will result in the same help file for that day.
|
- Don Jones Weekly PowerShell tips and other IT content www.ConcentratedTech.com |
 |
|
|
JSCLMEDAVE
Honorable But Hopeless Addict
    
USA
4104 Posts
Status: offline |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 04/28/2008 : 06:49:36 AM
|
I still haven't changed the static file location (Still considering best way to do that)
But I have made a function out of it, and it will check the date/time to make sure you only get 1 hint a day (Just to make sure you do not risk getting brain overload).
Function Get-Quote {
$FileContent = Get-Content -Path c:\scripts\test.ini
[int]$HelpNr = $FileContent[0]
$vhelp = Get-Help * | Get-Help
$i=0
foreach ($vvhelp in $vhelp)
{
$i++
if ($i -eq $HelpNr) {$vvhelp}
}
$TimSpan = New-TimeSpan -Start $FileContent[1] -End (Get-Date).ToString()
If ($TimSpan.days -gt 0)
{
$HelpNr++
Set-Content -Path c:\scripts\test.ini -Value $HelpNr
Add-Content -Path c:\scripts\test.ini -Value (Get-Date).ToString()
}
}
|
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
Edited by - Xenophane on 04/28/2008 07:58:24 AM |
 |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 04/28/2008 : 08:10:43 AM
|
Tim I looked into the Improved Tip-of-the-Day Dialog, but it is a standard VC++ component, that you can use if you make a VC++ app.
So in order to use it, you would have to write a VC++ application, that can read the "help files" and show them to you. (Bit off the PowerShell topic)
But I found playing around with PowerShell, getting my little script working, actually taught me a lot.. Especially because I read the help files while testing the script.  |
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
 |
|
|
JSCLMEDAVE
Honorable But Hopeless Addict
    
USA
4104 Posts
Status: offline |
Posted - 04/28/2008 : 09:38:50 AM
|
| Very good point... |
Tim-
"I was trying to find a good definition for minutiae, but found there was just too much useless information." |
 |
|
|
jaxdave
Honorable But Hopeless Addict
    
USA
2144 Posts
Status: offline |
Posted - 04/28/2008 : 10:44:31 AM
|
| very nice. thanks claus |
 |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 04/28/2008 : 10:53:38 AM
|
Ok, I am glad that I do not have much to do a work :)
Spent several hours playing around with PowerShell to get you a GUI Tim 
function Get-Daily {
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$fontNormal = new-object System.Drawing.Font("Microsoft Sans Serif",12,[Drawing.FontStyle]'Regular')
$FileContent = Get-Content -Path c:\scripts\test.ini
[int]$HelpNr = $FileContent[0]
$form = new-object Windows.Forms.form
$form.Size = new-object System.Drawing.Size @(1000,800)
$form.text = "PowerShell Command overview"
$RichTB = new-object System.Windows.Forms.RichTextBox
$RichTB.Dock = [System.Windows.Forms.DockStyle]::Fill
$RichTB.Font = $fontNormal
$form.Controls.Add($RichTB)
$vhelp = Get-Help * | Select -first $HelpNr| Select -last 1 | get-help | out-string
$RichTB.appendText($vhelp)
$TimSpan = New-TimeSpan -Start $FileContent[1] -End (Get-Date).ToString()
if ($TimSpan.Seconds -gt 0)
{
$HelpNr++
Set-Content -Path c:\scripts\test.ini -Value $HelpNr
Add-Content -Path c:\scripts\test.ini -Value (Get-Date).ToString()
}
$Form.Add_Shown({$form.Activate()})
[void]$form.showdialog()
}
I still haven't come up with a bright idea for storing the date/number info yet... But I will... Even if I have to figure out to put it in the registry :) |
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
 |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 04/28/2008 : 1:04:15 PM
|
The test.ini needs to be in the following format
1
28-04-2008 19:02:54
Line 1 is the number of help files displayed, and line 2 is the date, the file was updated. |
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
 |
|
|
JSCLMEDAVE
Honorable But Hopeless Addict
    
USA
4104 Posts
Status: offline |
Posted - 04/29/2008 : 4:46:25 PM
|
Get you a GUI Tim..?
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") [reflection.assembly]::loadwithpartialname("System.Drawing") $icon = new-object system.drawing.icon("C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\Setup.ico") $notify = new-object system.windows.forms.notifyicon $notify.icon = $icon $notify.visible = $true $notify.showballoontip(30,'$jerk = get-member | Where {$_.Name -like "Clause"}',"Ive GOT your GUI Clause <g> ",[system.windows.forms.tooltipicon]::Warning)
Edit - updated AGAIN! This will work if you have .NET v3 and the file C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\Setup.ico Not sure why this is needed. Its not on my work PC but is everywhere else... |
Tim-
"I was trying to find a good definition for minutiae, but found there was just too much useless information." |
Edited by - JSCLMEDAVE on 04/29/2008 8:14:48 PM |
 |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 04/29/2008 : 5:05:37 PM
|
Hey it doesn't work  |
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
 |
|
|
JSCLMEDAVE
Honorable But Hopeless Addict
    
USA
4104 Posts
Status: offline |
Posted - 04/30/2008 : 09:00:22 AM
|
Is there a specific single property for each of the help files, where you could code into the script (forgive my non scripting skills) If day = 127 (out of the entire year 365) then pull help ??? to a popup window upon logon..?
If we just went with the cmdlets it would start over after 130. However we could also pull the aliases as well. That way there is no need to write anything to a text file. |
Tim-
"I was trying to find a good definition for minutiae, but found there was just too much useless information." |
 |
|
|
DonJones
Here To Stay
 
USA
176 Posts
Status: offline |
Posted - 04/30/2008 : 09:29:47 AM
|
There's not an "index number" for help files, no - because they can be added in by anyone, there'd be no way to guarantee uniqueness. What you COULD do is...
# if $d = day of year get-help | select -first $d | select -last 1
No exactly a model of efficiency, but it'd work. Until you added the Exchange cmdlets (350+), at least :). |
- Don Jones Weekly PowerShell tips and other IT content www.ConcentratedTech.com |
 |
|
|
DennisMCSE
Moderator
    
Canada
1856 Posts
Status: offline |
|
|
Xenophane
Honorable But Hopeless Addict
    
Denmark
2661 Posts
Status: offline |
Posted - 05/01/2008 : 5:11:47 PM
|
Woow.... I am famous.... You think I can tradeMark it ?? 
|
SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
You can read my blog at www.xipher.dk |
 |
|
|
DennisMCSE
Moderator
    
Canada
1856 Posts
Status: offline |
|
| |
Topic  |
|