locked
Terminal server: set in maintenance for reboot RRS feed

  • Question

  • Hi,

    I would like to do the following:

    1.Send a message to a remote server that people should logoff
    This message should appear every minute till a certain hour, f.e. 5:30 PM

    Something like
    While($True)
                {
                            msg * /server:servername "This server will go in maintenance . Please logoff.
                            Start-Sleep -s 10
                }


    2.Last 5 minutes, server should come in drain mode
    Enter server is drain mode
    chglogon /drainuntilrestart


    3.When it is 5:30 people should be logged off
    Something like
    Get-TSsession -computername servername -username users | stop-tssession -force

    (4.send a message to a user that server is in drainmode)

    5.Reboot server and send message that it is back online.

    Please advise.
    J.

    Jan Hoedt

    Friday, July 31, 2015 12:08 PM

Answers

  • This is where I was looking for:

    $Server = "Server01" $AnnoyMyUsersUntil = "14:00" $PissOffUsersTotally = "14:05" $a=0 DO { $now = get-date $now.ToShortTimeString() sleep 2 if ($now.ToShortTimeString() -lt $AnnoyMyUsersUntil) { write-host annoy user msg /server * $server Server going down at half 5 init } if ($now.ToShortTimeString() -ge $AnnoyMyUsersUntil -and $now.ToShortTimeString() -le $PissOffUsersTotally -and $a -lt 1) { $a $a++ write-host Stop user logging in #dont think this is a remote capable command... chglogon /drainuntilrestart #dont think this is a remote capable command... } elseif($now.ToShortTimeString() -ge $PissOffUsersTotally) { write-host Time to logoff # $userinit = ((quser /server $server) -replace '\s{2,}', ',' | ConvertFrom-Csv) foreach ($session in $userinit.id) { $Session logoff.exe /server $server $session } } } Until ($now.ToShortTimeString() -ge $PissOffUsersTotally)



    Jan Hoedt

    • Marked as answer by janhoedt Tuesday, August 4, 2015 11:30 AM
    Tuesday, August 4, 2015 11:30 AM

All replies

  • You are not asking a question.  You are asking for a solution.  This forum is for scripting questions and is not a free consulting forum.


    \_(ツ)_/

    • Proposed as answer by Mike Laughlin Friday, July 31, 2015 3:20 PM
    Friday, July 31, 2015 1:52 PM
  • This is where I was looking for:

    $Server = "Server01" $AnnoyMyUsersUntil = "14:00" $PissOffUsersTotally = "14:05" $a=0 DO { $now = get-date $now.ToShortTimeString() sleep 2 if ($now.ToShortTimeString() -lt $AnnoyMyUsersUntil) { write-host annoy user msg /server * $server Server going down at half 5 init } if ($now.ToShortTimeString() -ge $AnnoyMyUsersUntil -and $now.ToShortTimeString() -le $PissOffUsersTotally -and $a -lt 1) { $a $a++ write-host Stop user logging in #dont think this is a remote capable command... chglogon /drainuntilrestart #dont think this is a remote capable command... } elseif($now.ToShortTimeString() -ge $PissOffUsersTotally) { write-host Time to logoff # $userinit = ((quser /server $server) -replace '\s{2,}', ',' | ConvertFrom-Csv) foreach ($session in $userinit.id) { $Session logoff.exe /server $server $session } } } Until ($now.ToShortTimeString() -ge $PissOffUsersTotally)



    Jan Hoedt

    • Marked as answer by janhoedt Tuesday, August 4, 2015 11:30 AM
    Tuesday, August 4, 2015 11:30 AM