Send-Message.psm1

Function Send-Message{
Param(

    [Parameter(Mandatory=$false,Position=0)]
    [string]$Message="Reminder: Please save all your documents before you leaving the office, your computer will reboot this Sunday!",

    [Parameter(Mandatory=$false,Position=1)]
    [string]$ComputerName="localhost",

    [Parameter(Mandatory=$false,Position=2)]
    [string]$Title="IT Department",

    [Parameter(Mandatory=$false,Position=3)]
    [ValidateSet("Standard","Custom")]
    [string]$Type="Standard",

    [Parameter(Mandatory=$false,Position=4)]
    [switch]$UseHostList,

    [Parameter(Mandatory=$false,Position=3)]
    [string]$HostListFile="C:\Script\Host.list"
)

#$date = @(@(0..7) | % {$(Get-Date "2:00").AddDays($_)} | ? {($_ -gt $(Get-Date)) -and ($_.DayOfWeek -ieq "Sunday")})[0]

if ($UseHostList) {

    $ComputerNameList = Get-Content $HostListFile
    
    foreach ($ComputerName in $ComputerNameList)
    {
        Invoke-WmiMethod -ComputerName $ComputerName -Path win32_process -Name create -ArgumentList msg.exe ""* $Message "" > $null
    }

}
else {

    Invoke-WmiMethod -ComputerName $ComputerName -Path win32_process -Name create -ArgumentList "msg.exe * $Message" > $null
}
}