jakalan7 Posted December 3, 2019 Posted December 3, 2019 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!!
bald_pig Posted December 3, 2019 Posted December 3, 2019 Should be Get-Content: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-6 1
Sephiroth Posted December 3, 2019 Posted December 3, 2019 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 } 1
jakalan7 Posted December 3, 2019 Author Posted December 3, 2019 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now