With your suggestion, I changed it to
$yesterday = [DateTime]::Today.ToString('M/d/yyyy HH:mm ')
$NotLoggedOut = Get-LoggedOnUser -ComputerName Pluto | Where-Object {$_.LogonTime -lt $yesterday}
$Script={param($Command); Write-Host $Command; &cmd /c "$Command"}
$Command = Foreach ($User in $NotLoggedOut) {msg "$User.username Hello $User.Username You been logged in since $User.LogonTime"}
Invoke-Command -ComputerName Pluto -ScriptBlock $Script -ArgumentList $Command
Now it gives this error
msg : Invalid parameter(s)
At \UsersWhoHaveNotLoggedOut.ps1:56 char:46
+ $Command = Foreach ($User in $NotLoggedOut) {msg "$User.username Hello $User.Use ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Invalid parameter(s):String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Send a message to a user.
MSG {username | sessionname | sessionid | @filename | *}
[/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]
username Identifies the specified username.
sessionname The name of the session.
sessionid The ID of the session.
@filename Identifies a file containing a list of usernames,
sessionnames, and sessionids to send the message to.
* Send message to all sessions on specified server.
/SERVER:servername server to contact (default is current).
/TIME:seconds Time delay to wait for receiver to acknowledge msg.
/V Display information about actions being performed.
/W Wait for response from user, useful with /V.
message Message to send. If none specified, prompts for it
or reads from stdin.