Filewatch script to send message using msg.exe

I have this script to create a popup on the workstation. However 1) it required elevation to show more than one popup and 2) I need this to run on the server.

Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {

$name = $Event.SourceEventArgs.Name

$changeType = $Event.SourceEventArgs.ChangeType

$timeStamp = $Event.TimeGenerated

$wshell = New-Object -ComObject Wscript.Shell

$wshell.Popup("The file '$name' was $changeType at $timeStamp",0,"Done",0x1)

#Write-Host "The file '$name' was $changeType at $timeStamp" -fore green

Out-File -FilePath c:\outlog.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp"}

Is it possible to modifiy this so it will send a pop message using the msg.exe command to pre-determined workstations?

If so, any pointers? I'm lost.

Thanks

June 24th, 2015 2:42pm

what isn't working with msg?  I must be missing something because simply inserting

msg /server:$srvr 'message'

will send 'message' to $srvr.  Iterate if you want to send to a list of servers.

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2015 5:57pm

No.  Just use MSG at a prompt.

MSG /SERVER:W8test * "hello world"`

June 24th, 2015 6:02pm

Hi not_sure_,

You can also refer to the function Send-NetMessage, which is written by the command msg.exe , you can provide bulk servernames, message and the timeout:

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." 
    } 
}


Send-NetMessage "hello!" -Computername vm2,vm3 -Seconds 30 -VerboseMsg -Wait

Refer to:

https://gallery.technet.microsoft.com/scriptcenter/Send-NetMessage-Net-Send-0459d235

If there is anything else regarding this issue, please feel free to post back.

Best Regards,

Anna Wang

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 5:05am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics