Automation

 View Only
  • 1.  How can I display message-box information across multiple lines?

    Posted Dec 05, 2008 02:47 PM

    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.



  • 2.  RE: How can I display message-box information across multiple lines?
    Best Answer

    Posted Dec 05, 2008 03:15 PM

    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
    



  • 3.  RE: How can I display message-box information across multiple lines?

    Posted Dec 05, 2008 03:27 PM

    That worked great! Thanks very much.