This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
As MSH has no inputbox function,
you can ofcourse make your own Form :
(I have a couple of example on my blog).
I have three ( 2 of them usable) other possibilities
1) you can use the VB.NET inputbox but it has also the Focus Problem, you see with windows froms in MSH (I solve it with a Form by setting it TopMost, but that is here not possible as it already is fired).
So as this would be the most simple method, the inputbox staying out of focus (hidden) is making it almost useless.
MSH>[reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
MSH>$r = [Microsoft.VisualBasic.Interaction]::inputbox("Enter :","title")
MSH>$r
input
2) or you can use VBscript, that handles the focus right.
make this vbscript :
'InputBox.vbs
a = inputbox(wscript.arguments(0),wscript.arguments(1))
wscript.echo a
Make following Function :
MSH>function inputbox {cscript //nologo G:\Monad\inputbox.vbs $args[0] $args[1]}
Use like this.
MSH>inputbox "enter" "title"
input
and Add errorhandling as you like ;-)
the Vbscript way is the most simple.
3) or you can do the .NET part and compile it to an exe.
run this MSH script :
# Compile-VB.msh
# VB.Net .Exe Generator
# /\/\o\/\/ 2005
$provider = new-object Microsoft.VisualBasic.VBCodeProvider
$params = new-object System.CodeDom.Compiler.CompilerParameters
$params.GenerateExecutable = $true
$params.GenerateInMemory = $False
$refs = "System.dll","Microsoft.VisualBasic.dll","System.Data.DLL"
$params.ReferencedAssemblies.AddRange($refs)
# VB.NET EXAMPLE
$txtCode = @'
Imports Microsoft.VisualBasic
Imports System
Module Module1
Sub Main(ByVal strArgs() As String)
dim result as string
result = inputbox(strargs(0),strArgs(1))
console.writeline(result)
End Sub
End Module
'@
$results = $provider.CompileAssemblyFromSource($params, $txtCode)
$results
TempFiles : {C:\Documents and Settings\mow\Local Settings\Temp\2heysyo7.exe}
Evidence :
CompiledAssembly : 2heysyo7, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Errors : {}
Output : {}
PathToAssembly : C:\Documents and Settings\mow\Local Settings\Temp\2heysyo7.exe
NativeCompilerReturnValue : 0
MSH>& 'C:\Documents and Settings\mow\Local Settings\Temp\2heysyo7.exe' "test" "title"
lol
As you can see I did not use a Filename, You can copy it out of the Temp folder,
then you can rename the generated exe and use it then.
(this keeps it General, you can just past in some VB.net Code and compile it.)
generating a Class in Memory and then start it from MSH, as I may have seen in some of my former blog entries, will not work in this case as then we have got the focus problem again.
MSH>$r = G:\Monad\Inputbox.exe "test" "title"
MSH>$r
input
using a compiled EXE is the way I use from MSH (whith parameter and errorchecking that is ;-))
b.t.w. I also have the "Form version" as the only way the Inputbox shows that the Cancel button is pushed is that the return value is emply, some ones makeing a form for this also has his advantages (especialy if you have VS handy).
also it's on my list of "CMDlets to be...", so maybe it will make this blog sometime ;-)
enjoy,
gr /\/\o\/\/