GuruAnt
Contributor
Contributor

How can I display message-box information across multiple lines?

Jump to solution

I'd like to be able to display guest information in a multi-line message box. I've managed to get all the information I need, but I can't format it to come out on multiple lines. I tried vbNewLine in single-quotes, but it still just displays vbNewLine in the box.

Here's what I have so far (stitched together from other people's code I found):

Function Show-Inputbox {
Param([string]$message=$(Throw "You must enter a prompt message"),
[string]$title="Input",
[string]$default
)

[http://reflection.assembly|http://reflection.assembly]::loadwithpartialname("microsoft.visualbasic") | Out-Null
[http://microsoft.visualbasic.interaction|http://microsoft.visualbasic.interaction]::InputBox($message,$title,$default)

}

$strVM = Show-Inputbox -message "What is the name if the machine?" -title "Guest Info" -default machine_name
$vm = Get-VM -Name $strVM

if ($vm.PowerState -eq "PoweredOn") {
$event = Get-VIEvent -Entity $vm | where-object {$_.fullFormattedMessage -like "Task: Power on Virtual Machine"}
$VM.Name
$VM.PowerState
(Get-VMGuest -VM $VM).IPAddress[0]
$event[0].username
}

$strMessageText = $VM.Name+$VM.PowerState+(Get-VMGuest -VM $VM).IPAddress[0]+$event[0].username

$a = new-object -comobject wscript.shell
$b = $a.popup($strMessageText,0,"Guest Info",1) 


Does anyone have any ideas on how to do this? Or alternative ways of displaying the info (in a non-scary way for users)?

Also, any hints as to how to optimise thise code would be apppreciated, it takes a while to run.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

In PowerShell a newline is `n (back-tick + n).

You can do it like this

$strMessageText = $VM.Name + "`n" + $VM.PowerState + "`n" + (Get-VMGuest -VM $VM).IPAddress[0] + "`n" + $event[0].username


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

In PowerShell a newline is `n (back-tick + n).

You can do it like this

$strMessageText = $VM.Name + "`n" + $VM.PowerState + "`n" + (Get-VMGuest -VM $VM).IPAddress[0] + "`n" + $event[0].username


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
GuruAnt
Contributor
Contributor

That worked great! Thanks very much.

0 Kudos