/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Monad IRC Bot "," Getting performanceMonitor info from Monad "," Monad -and More bytes with -band = shorter script "," Tip from Monad "," MSH AD querying with .NET 2.0 framework "," get AD user allowed Logonhours from MSH "," MSH Show-Byte Function "," Let monad "drop" some chars "," getting an Inputbox in MOnad "," Get AD info into a nested HashTable from MSH "," ")

Tuesday, December 13, 2005

 


MSH prompt-User function with Help



From a Newsgroups-post I came to this script to ask the users something with Helptext (after my original answer on a seemingly simple question, and a lot of help from others on that tread,
first warning me for the use of $? (will not be set to $true if Command is succesfull), then a CheckExitCode Function, and tips that did lead me to this.

I came to the following function.

Prompt-YesNo

$n = ([System.Management.Automation.Host.ChoiceDescription]"&No")
$n.helpmessage = "No, don't go on"

$Y = ([System.Management.Automation.Host.ChoiceDescription]"&Yes")
$y.helpmessage = "Yes, go on"

$YN= ($Y,$N)

Function Prompt-YesNo ($Caption = "Continue", $Message = "Do You wan't to go on",$choices = $YN){
  $host.ui.PromptForChoice($caption,$Message,[System.Management.Automation.Host.ChoiceDescription[]]$choices,0)
}



so Now you can do this :

$answer = Prompt-YesNo

if ($answer -eq 0) {"go on"else {"Stop"}


the result will look like this (normal the check line will not be seen ;-)

MSH>$answer = Prompt-YesNo

Continue
Do You wan't to go on
[Y] Yes  [N] No  [?] Help (default is "Y"): ?
Y - Yes, go on
N - No, don't go on
[Y] Yes  [N] No  [?] Help (default is "Y"):
MSH>if ($answer -eq 0) {"go on"else {"Stop"}
go on
MSH>$answer = Prompt-YesNo

Continue
Do You wan't to go on
[Y] Yes  [N] No  [?] Help (default is "Y"): n
MSH>if ($answer -eq 0) {"go on"else {"Stop"}
Stop
MSH>


I think this is a very cool way to get input from the user the same way as a CMDlet.

thanks from here to all that helped on the channel.

microsoft.public.windows.server.scripting

I think to newsgroup is a good learning start for MSH,
I think the help there is great !!
and helping other will bring you to ideas.

enjoy, and maybe see you on the NG

gr /\/\o\/\/


Comments: Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?