Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Reboot script powershell for terminal servers W2K8R2

Posted on 2014-08-21
17
Medium Priority
?
524 Views
Last Modified: 2014-12-08
Hi,

We 'd need to make a reboot schedule/script for two terminal servers without a broker.

This is the idea: two terminal servers: x and y

* x should reboot every other day at 5 PM, f.e. Monday, Wednesday
* y should reboot the days in between at 5 PM, f.e. Tuesday, Thursday

*reminder (removable) should be given to users that server will be rebooted: "This server will be rebooted within x hours, please logoff by then".
*permanent reminder (not removable) should be given within the last hour: "This server will be rebooted in x hour/min (counting down clock), please logoff or there could be data loss. You can logon to server x/y and continue your work."
*any changes to config should be easily made (change in days, time) ... => GUI?

We'd use a chglogon /drainuntilrestart to make sure no new users logon.


Please advise on concept (how do you use/implement it). I'd prefer Powershell.

J.
0
Comment
Question by:janhoedt
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 15

Expert Comment

by:joharder
ID: 40277657
Were you planning to configure this as a scheduled task?  That will provide the ease and flexibility you're seeking.
0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 40277705
scheduled tasks would be the best

A nice countdown timer is located @ http://gallery.technet.microsoft.com/scriptcenter/Countdown-Timer-06ae1ce7
0
 
LVL 24

Accepted Solution

by:
yo_bee earned 2000 total points
ID: 40277738
I would just create a new Task under Task Scheduler and use the Shutdown /r /f /t 3600  /c "Your message" /d p:2:18 to schedule your shutdowns.

I am pretty sure that the shutdown command will alert the users that the server is being shutdown/rebooted.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2013-01-24T16:26:21.3941223</Date>
    <Author>Domain\User</Author>
  </RegistrationInfo>
  <Triggers>
    <TimeTrigger>
      <StartBoundary>2013-01-25T03:00:00</StartBoundary>
      <Enabled>true</Enabled>
    </TimeTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>Domain\user</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>shutdown</Command>
      <Arguments>/r /t 00 /d p:2:18</Arguments>
    </Exec>
  </Actions>
</Task>

Open in new window

0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 

Author Comment

by:janhoedt
ID: 40283101
Thanks but I'd need to able to deploy/change the settings centrally.
0
 

Author Comment

by:janhoedt
ID: 40285674
Let me clarify, it would be something like this:

Show default a popup with reboot schedules for the machine, f.e. user logs on to machine x = This server will be rebooted 1 September at 7 PM

enter-pssession remotemachine
'message 4 hours before reboot that server will be rebooted (for all users)
'message 1 hours before reboot that server will be rebooted (for all users)
'message 30 minutes before reboot that server will be rebooted (for all users)
msg * /v "This server will be restarted in x minutes. Please logoff and work on server y."
Countdown timer to restart then
chglogon /drainuntinrestart  'to not allow users to logon anymore until restart but leave connected users connected

'query open terminal server sessions and logg them off
reboot terminal server
0
 
LVL 15

Expert Comment

by:joharder
ID: 40297519
In order to meet your requirement to do this centrally, you can set this up as a scheduled task within a GPO, as a Group Policy Preference.

Go to Computer-->Preferences-->Control Panel-->Scheduled Task.
0
 

Author Comment

by:janhoedt
ID: 40298010
Ok thanks, but that doesn't help me with the script. The script is what I actually need to configure/make work.
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 40298130
You can do that or just go to each one of your TS and add the script to run at a scheduled time.
Either way will meet your needs, but you will need to make sure that the script is accessible to all servers.
0
 

Author Comment

by:janhoedt
ID: 40298146
Ok, but I don't need help with targetting, I need help with the script itself.
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 40298147
If you send the Shutdown Command to the server all sessions will get the alert.

Try it on your machine.

Shutdown /r /t 300 /c "the server is going to shutdown in 5 Mins please save all work" /d p:2:18
Once run you can abort it by entering a new command shutdown /a

Once you confirmed this I would schedule it on the servers.
0
 

Author Comment

by:janhoedt
ID: 40298385
Reboot command isn't the issue, is the full powershell script what I'm looking for, specifically the timer and the logoff of logged on users.

enter-pssession remotemachine
'message 4 hours before reboot that server will be rebooted (for all users)
'message 1 hours before reboot that server will be rebooted (for all users)
'message 30 minutes before reboot that server will be rebooted (for all users)
msg * /v "This server will be restarted in x minutes. Please logoff and work on server y."
Countdown timer to restart then
chglogon /drainuntinrestart  'to not allow users to logon anymore until restart but leave connected users connected

'query open terminal server sessions and logg them off
reboot terminal server
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 40298800
So you have the timer PS script from one of the other posters correct?
0
 

Author Comment

by:janhoedt
ID: 40298837
Yes.
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 40298914
Have you tested the Timer display yet to see if the users can see the message and count down?
0
 

Author Comment

by:janhoedt
ID: 40298989
No, I have not.
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 40300965
From what I can see you are using the MSG as well as the chglogon to accomplish the Alert as well as the lock down of the sessions
Do you have to have the Countdown Timer or can you just leverage the Message from the Shutdown command?
From my testing the msg command with /Time: display switch worked as well as the message from the shutdown command.
0
 

Author Comment

by:janhoedt
ID: 40312158
Thanks! I'll check asap.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question