Solved

How can this be done - powershell msgbox

Posted on 2014-02-27
5
4,799 Views
Last Modified: 2014-03-06
Alright, i know the following can be locally on my computer to display a message box
[system.reflection.assembly]::LoadWithPartialName("system.windows.forms")
[system.windows.forms.messagebox]::Show("YOur system needs to be accesses for maintence please finish all your work")

Open in new window

but how the heck can i get it to show on remote computers? I know i can use the msg command that is built into windows but some systems don't have that function.

i'm guessing something along the lines of
[system.reflection.assembly]::LoadWithPartialName("system.windows.forms")
$creds = get-credential
.... -computername testbox -credential $cred | [show.windows.form.messagebox]::Show("message here")

Open in new window

0
Comment
Question by:bbimis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 250 total points
ID: 39893444
Put all of the code to execute into a scriptblock, and run it with invoke-command:
invoke-command -computer testbox -script {<#code here>}

Open in new window

0
 
LVL 40

Assisted Solution

by:footech
footech earned 250 total points
ID: 39893558
I was thinking the same thing, but it looks like you run into an error since it's an interactive element.
There's probably some way to do this with Windows forms, I just don't know it yet.
One thing I found did work on Win7 system is to use a  combination of PowerShell Remoting and msg.exe.
$block = { msg console /time:15 "Message to user"}
Invoke-Command -ComputerName computername -ScriptBlock $block

Open in new window

0
 

Author Comment

by:bbimis
ID: 39895632
well wouldn't msg /server:[computername] * "message here" do the same thing ?
that works on windows 7 machines if they have the built in msg

my goal is along these lines but i can't figure out how to get the code to work.
$computer = "testpc"
Send-NetMessage "testing" -Computername $computer -Seconds 30 -VerboseMsg -Wait

Function Send-NetMessage{
<#  
.SYNOPSIS  
    Sends a message to network computers
 
.DESCRIPTION  
    Allows the administrator to send a message via a pop-up textbox to multiple computers
 
.EXAMPLE  
    Send-NetMessage "This is a test of the emergency broadcast system.  This is only a test."
 
    Sends the message to all users on the local computer.
 
.EXAMPLE  
    Send-NetMessage "Updates start in 15 minutes.  Please log off." -Computername testbox01 -Seconds 30 -VerboseMsg -Wait
 
    Sends a message to all users on Testbox01 asking them to log off.  
    The popup will appear for 30 seconds and will write verbose messages to the console. 

.EXAMPLE
    ".",$Env:Computername | Send-NetMessage "Fire in the hole!" -Verbose
    
    Pipes the computernames to Send-NetMessage and sends the message "Fire in the hole!" with verbose output
    
    VERBOSE: Sending the following message to computers with a 5 delay: Fire in the hole!
    VERBOSE: Processing .
    VERBOSE: Processing MyPC01
    VERBOSE: Message sent.
    
.EXAMPLE
    Get-ADComputer -filter * | Send-NetMessage "Updates are being installed tonight. Please log off at EOD." -Seconds 60
    
    Queries Active Directory for all computers and then notifies all users on those computers of updates.  
    Notification stays for 60 seconds or until user clicks OK.
    
.NOTES  
    Author: Rich Prescott  
    Blog: blog.richprescott.com
    Twitter: @Rich_Prescott
#>

Param(
    [Parameter(Mandatory=$True)]
    [String]$Message,
    
    [String]$Session="*",
    
    [Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
    [Alias("Name")]
    [String[]]$Computername=$env:computername,
    
    [Int]$Seconds="5",
    [Switch]$VerboseMsg,
    [Switch]$Wait
    )
    
Begin
    {
    Write-Verbose "Sending the following message to computers with a $Seconds second delay: $Message"
    }
    
Process
    {
    ForEach ($Computer in $ComputerName)
        {
        Write-Verbose "Processing $Computer"
        $cmd = "msg.exe $Session /Time:$($Seconds)"
        if ($Computername){$cmd += " /SERVER:$($Computer)"}
        if ($VerboseMsg){$cmd += " /V"}
        if ($Wait){$cmd += " /W"}
        $cmd += " $($Message)"

        Invoke-Expression $cmd
        }
    }
End
    {
    Write-Verbose "Message sent."
    }
}

Open in new window

0
 
LVL 40

Expert Comment

by:footech
ID: 39895754
I believe it depends on whether you have the firewall configured to allow it (referring to whether msg /server would work or not).  It doesn't for me and I haven't tried to diagnose it.  If you have PS Remoting configured then the network communication happens over that so you don't have to worry about any additional firewall configuration.

That script is just a wrapper for msg.exe.
0
 

Author Closing Comment

by:bbimis
ID: 39910318
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question