messaging lan application

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
joseph
Posts: 1
Last visit: Sat Apr 19, 2014 2:09 am

messaging lan application

Post by joseph »

hello everyone

I'm trying to create a simple lan messaging application using powershell I tried the message command this is what I made after some research
PowerShell Code
Double-click the code block to select all.
$Start_Time       =              Get-Date -Format T

$logFile          =                    ‘Not_Reachable_PCs.txt’

$Message          =               Read-Host -Prompt “Type Your Message Here”      

$ComputerName     =       Read-Host -Prompt “Type Computer Name Here”    

$Time             =       "6666" 

$Session          =       “*”

$ComputerName     =       $ComputerName -split ‘,’

if ($ComputerName -match “:”)

                      {

                      $Path = $ComputerName


                      $ComputerName = Get-Content $path

          }

                      $Total = $ComputerName.count 

                                foreach ($Computer in $ComputerName )

                                                {

                                                                if (Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0)

                                {

                                                                Write-Host “Sending Message to $Computer…….” -ForegroundColor yellow

                                msg $Session /Server:$Computer /Time:$Time $Message

                                                                Write-Host “Message Successfully Sent to $Computer” -ForegroundColor Green

                                                                }

                                                                else

                                                                                {

                                                                Out-File -FilePath $logFile -InputObject $Computer -Append -Force

                                                                                                Write-Host “$Computer is not Reachable…” -ForegroundColor red

                                                                                }

                                                }

                                $Not_Reachable_Count  = @(Get-Content $logFile).count

        $End_Time   =    Get-Date -Format T

        $Minute = (New-TimeSpan -Start $Start_Time -End $End_Time).Minutes

        $Second = (New-TimeSpan -Start $Start_Time -End $End_Time).Seconds

                                Write-Host Start at $Start_Time, End At $End_Time, Took About $Minute Minutes $seconds Seconds

                                Write-Host “Total $Total Computer Processed, $Not_Reachable_Count computers were offline. The list is stored in $logFile” -ForegroundColor white
it's not bad but the message from the sender appears in a popup and not in the console any idea how to make the messages from both sides appear in the same console like any regular messaging software

thanks in advanced
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: messaging lan application

Post by jvierra »

It can't be done.

You cannot easily do this if you are not an experienced systems programmer.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: messaging lan application

Post by jvierra »

You would do better with PowerShell if you are more careful with the format of your code . Be careful of "smart quotes" and eliminate the sue of excess variables and redundant operations.

Here is an example with some ideas of how to better approach this.

I know - it still doesn't solve your problem.
PowerShell Code
Double-click the code block to select all.
$logFile          = 'Not_Reachable_PCs.txt'
$Message          = Read-Host -Prompt 'Type Your Message Here' 
$ComputerName     = Read-Host -Prompt 'Type Computer Name Here'    
$Time             = "6666"
$Session          = '*'
$ComputerName     =  $ComputerName -split ','
$UnReachable      = 0

$StartTime=[datetime]::Now

if($ComputerName -match “:”){
    $Path = $ComputerName
    $ComputerName = Get-Content $Path
}

$Total = $ComputerName.count

foreach ($Computer in $ComputerName ){
    if (Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0){
        Write-Host "Sending Message to $Computer……." -ForegroundColor yellow
        msg $Session /Server:$Computer /Time:$Time $Message
        Write-Host "Message Successfully Sent to $Computer" -ForegroundColor Green
    }else{
        $Not_Reachable_Count+=1
        Out-File -FilePath $logFile -InputObject $Computer -Append -Force
        Write-Host "$Computer is not Reachable…" -ForegroundColor red
    }
}

Write-Host "Start at $Start_Time, End At $End_Time, Took About $([datetime]::Now - $Start_Time)"
Write-Host "Total $($ComputerName.count) Computer Processed, $UnReachable computers were offline. The list is stored in $logFile" -ForegroundColor white
This topic is 9 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked