I have the code below that I have been working on and I have an issue, I can not get it to send the variable message to the computer, if I take out the variable it works but that is not what I was trying to accomplish with it.
Function Send-PopupMessage {
#Requires -Version 2.0
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[String]$ComputerName,
[Parameter(Mandatory = $true)]
[String]$Message
)
Invoke-Command -ComputerName $ComputerName -Scriptblock {
$CmdMessage = "msg.exe * $Message"
Write-Host $CmdMessage
$CmdMessage | Invoke-Expression
}
}
This is not the same as the question linked because I am in a session to another computer using PSWA so I am not able to start another session from this. Also even when I changed my code to be more like the one in the "Duplicate" question I am still getting the same results that the cmd being sent to the other computer is
msg.exe * '' instead of msg.exe * 'Test Message'