Jump to content

Powershell Query - Msg * Client - But reference another .txt doc?


Recommended Posts

Posted

Hello everyone,

 

I was hoping someone may be able to help me with a Powershell query. I have a script which I can use to send out a message to all of our teacher's computers, this could be used to relay any critical messages that teachers need to see right away.

 

I've pasted the code below, in theory to send a message I'd open it in Notepad, go to edit, press replace and replace % with the message that needs to be sent, before running it as admin, I've tested it on a few machines and it works well:

 

Msg * /server:Computer01 "%"

Msg * /server:Computer02 "%"

Msg * /server:Computer03 "%"

 

However, here's where the problem is, I've been asked if a daily message can be sent out just before the end of school, to alert teacher's of any students who have after-school detentions.

 

I can just set a scheduled task to run the script once a day at the end of school, but, the list of students names would be different every day, and with the best will in the world, the IT department won't always have the time to update a scheduled script with the student's names in every day, it just wouldn't be viable for us to do it.

 

So, my question is - is there any way within PowerShell I can tweak the basic batch file above so that where the "%" is, I can insert the text a separate .txt document on an NTFS drive, so then I can tell the staff - "Put your message in the .txt file on SharedDrive/Notices/Notice.txt and that is what will be sent out at 15:15"??

 

Any help would be much appreciated, thank you in advance!!

Posted

Following on from @bald_pig, this should work...

$Text = Get-Content C:\text_file.txt
Foreach ($Line in $Text) {
   Msg * /server:Computer01 $Line
   Msg * /server:Computer02 $Line
   Msg * /server:Computer03 $Line
}

  • Thanks 1
Posted
Following on from @bald_pig, this should work...

$Text = Get-Content C:\text_file.txt
Foreach ($Line in $Text) {
   Msg * /server:Computer01 $Line
   Msg * /server:Computer02 $Line
   Msg * /server:Computer03 $Line
}

 

That's great, all working - easy as that!

 

Thank you both!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...