Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 PowerShell
 Display Help files
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 04/26/2008 :  11:55:41 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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  Show Profile  Visit DonJones's Homepage  Reply with Quote
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
Go to Top of Page

JSCLMEDAVE
Administrator

USA
4808 Posts
Status: offline

Posted - 04/26/2008 :  3:13:02 PM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
Claus you are on the right track..!

Here is a link that explains Exchange 2007 implementing a Get-Tip cmdlet. This may help...
http://blogs.msdn.com/powershell/archive/2006/08/31/Tip-of-the-Day.aspx

I was also looking at Improved Tip-of-the-Day Dialog
By Robert Pittenger -
http://www.codeproject.com/KB/dialog/tipdemo.aspx

It would be cool if you could pull it into this type of app.

Tim-

"Will the woman who left her 9 kids at Wrigley field please come and claim them? - they're beating the Cubs 5-0"

Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 04/28/2008 :  06:49:36 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 04/28/2008 :  08:10:43 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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
Go to Top of Page

JSCLMEDAVE
Administrator

USA
4808 Posts
Status: offline

Posted - 04/28/2008 :  09:38:50 AM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
Very good point...

Tim-

"Will the woman who left her 9 kids at Wrigley field please come and claim them? - they're beating the Cubs 5-0"

Go to Top of Page

jaxdave
Honorable But Hopeless Addict

USA
2211 Posts
Status: offline

Posted - 04/28/2008 :  10:44:31 AM  Show Profile  Reply with Quote
very nice. thanks claus
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 04/28/2008 :  10:53:38 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 04/28/2008 :  1:04:15 PM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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
Go to Top of Page

JSCLMEDAVE
Administrator

USA
4808 Posts
Status: offline

Posted - 04/29/2008 :  4:46:25 PM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
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-

"Will the woman who left her 9 kids at Wrigley field please come and claim them? - they're beating the Cubs 5-0"


Edited by - JSCLMEDAVE on 04/29/2008 8:14:48 PM
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 04/29/2008 :  5:05:37 PM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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
Go to Top of Page

JSCLMEDAVE
Administrator

USA
4808 Posts
Status: offline

Posted - 04/30/2008 :  09:00:22 AM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
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-

"Will the woman who left her 9 kids at Wrigley field please come and claim them? - they're beating the Cubs 5-0"

Go to Top of Page

DonJones
Here To Stay

USA
176 Posts
Status: offline

Posted - 04/30/2008 :  09:29:47 AM  Show Profile  Visit DonJones's Homepage  Reply with Quote
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
Go to Top of Page

DennisMCSE
Moderator

Canada
1955 Posts
Status: offline

Posted - 05/01/2008 :  2:55:21 PM  Show Profile  Visit DennisMCSE's Homepage  Look at the Skype address for DennisMCSE  Reply with Quote
Claus, it looks like you're famous now:

http://blogs.msdn.com/powershell/archive/2008/04/27/get-random.aspx


DennisMCSE

Blog: http://itprofirewalker.spaces.live.com/



Follow me on Twitter http://twitter.com/Firewalker96


Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
2784 Posts
Status: offline

Posted - 05/01/2008 :  5:11:47 PM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
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
Go to Top of Page

DennisMCSE
Moderator

Canada
1955 Posts
Status: offline

Posted - 05/01/2008 :  7:07:47 PM  Show Profile  Visit DennisMCSE's Homepage  Look at the Skype address for DennisMCSE  Reply with Quote
You may not be able to Trademark it, but, can I have your autograph? :-)


DennisMCSE

Blog: http://itprofirewalker.spaces.live.com/



Follow me on Twitter http://twitter.com/Firewalker96


Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2009 Mark Minasi Go To Top Of Page
This page was generated in 0.2 seconds. Snitz Forums 2000