Anchor | ||||
---|---|---|---|---|
|
Include Page | ||||
---|---|---|---|---|
|
...
Using the "Local Group Policy Editor", it is possible to add the execution of a Powershell script at Windows shutdown. As this operation is performed with the "system
" account, some operations have to be performed if depending on the chosen mode is "rsh
" or "ssh
"method chosen (opa0
, rsh
or ssh
).
Warning |
---|
Please note shutdown scripts are executed when the shutdown is executed either from the "Windows Start" menu or using the shutdown command line. They are not always executed when clicking on the "Restart" button from the Windows Update tool. |
opa0 mode preparation
If the combination of username/password or is used, there is no need for configuration change.
If an encrypted file is used to store the password , there is no need for configuration.using the "cryptedpsys
" parameter, it must be created on a session as "system
" account.
To do so, open a cmd.exe
window as Administrator and run the following command:
C:\WINDOWS\system32>C:\Charon\psexec.exe -i -s cmd.exe |
A new window will popup. To check you're connected as "system", run:
|
Run the following command to create the encrypted file:
|
Example:
|
Div | ||
---|---|---|
| ||
Run the Powershell script in check mode:
C:\WINDOWS\system32>powershell -file c:\charon\charon_cleanshutdown.ps1 -config c:\charon\myds20vms.ini -check |
then check the "OPA0 was successful
" message is displayed followed by "Command successfully completed.
"
Note |
---|
It is recommended to move the |
rsh mode preparation
Warning |
---|
A proxy has to be defined at OpenVMS level hence the local " It is then highly recommended to install an English version of Windows to avoid issues with accents and non standard characters when creating this proxy. |
...
|
The run Run the Powershell script in check mode:
C:\WINDOWS\system32>powershell -file c:\charon\charon_cleanshutdown.ps1 -config c:\charon\myds20vms.ini -check |
then check the "RSH was successful
" message is displayed followed by "Command successfully completed.
"
Note |
---|
It is recommended to move the |
Div | ||
---|---|---|
| ||
ssh mode preparation
Execute the same operations as described in chapter "Using ssh" for Tru64 or VMS to create a key pair with "SYSTEM
" user with a different identity file.
...
|
Create a new ssh trust as described in the "Using ssh" chapter.
Tip |
---|
Remember to specify a different identity file in the .ini file. This can be done thanks to the " |
The run Run the Powershell script in check mode:
C:\WINDOWS\system32>powershell -file c:\charon\charon_cleanshutdown.ps1 -config c:\charon\myds20vms.ini -check |
then check the "SSH was successful
" message is displayed followed by "Command successfully completed.
"
Note |
---|
It is recommended to move the |
Div | ||
---|---|---|
| ||
Windows settings - Local group policy
...
The PowerShell window is displayed during Windows shutdown thanks to the enabled "Display instructions in shutdown scripts as they run" feature and the putty / OPA0 window is opened thanks to the "openconsolecmd
" and "openconsolearg
" parameters in the .ini file.
Full log as defined in the .ini file:
Code Block | ||
---|---|---|
| ||
20200326:154759:INFO :0: Using 'C:\Charon\myds20vms_shutdown.log' as log file / append
=
Parameters taken from configuration file:
commandparams=-o Ciphers=+3des-cbc -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=+ssh-dss
guestsystem=192.168.152.149
identityfile=C:\Charon\win10bmrsa
identityfsys=C:\Charon\win10bmrsa_system
logfile=C:\Charon\myds20vms_shutdown.log
mode=ssh
openconsolearg=-load OPA0 -P 10007
openconsolecmd=C:\Program Files\CHARON\Build_20203\x64\putty
os=VMS
servicename=ds20vms
sshbin=C:\Program Files (x86)\OpenSSH\ssh.exe
username=system
waitbeforestop=10
=
20200326:154759:INFO :0: 'ssh' will be used
20200326:154759:INFO :0: Using 'C:\Charon\win10bmrsa_system' as identity file.
20200326:154759:INFO :0: Service 'ds20vms' is Running (Display name: ds20vms)
20200326:154759:INFO :0: Testing guest system '192.168.152.149' response
20200326:154802:INFO :0: Opening console.
20200326:154802:INFO :0: Invoking 'ssh' command and executing shutdown as WIN10-MAIN$ ...
20200326:154802:INFO :0: C:\Program Files (x86)\OpenSSH\ssh.exe -i C:\Charon\win10bmrsa_system -q -l system -o BatchMode=yes -o Ciphers=+3des-cbc -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=+ssh-dss 192.168.152.149 '@SYS$MANAGER:CHARON_SHUTDOWN.COM'
20200326:154804:INFO :0: Output results:
20200326:154804:INFO :0:
20200326:154804:INFO :0: $ PURGE /KEEP=20 SYS$MANAGER:CHARON_SHUTDOWN.LOG
20200326:154804:INFO :0: $ RUN /DETACH SYS$SYSTEM:LOGINOUT.EXE /INPUT=SYS$MANAGER:CHARON_SHUTDOWN -
20200326:154804:INFO :0: /OUTPUT=SYS$MANAGER:CHARON_SHUTDOWN.LOG /UIC=[1,4]
20200326:154804:INFO :0: %RUN-S-PROC_ID, identification of created process is 00000129
20200326:154804:INFO :0: $ ENDIF
20200326:154804:INFO :0: $ ENDIF
20200326:154804:INFO :0: $ EXIT
20200326:154804:INFO :0: $
20200326:154804:INFO :0: $ !
20200326:154804:INFO :0: $ ! Force any output to the standard output device.
20200326:154804:INFO :0: $ ! Most useful when client is Un*x.
20200326:154804:INFO :0: $ !
20200326:154804:INFO :0: $ ! V5.4-03
20200326:154804:INFO :0: $ ! WRITE SYS$OUTPUT -
20200326:154804:INFO :0: $ ! "ssh-rcmd 'f$getjpi("","USERNAME")' logged out at 'f$time()'" ! V5.4-02
20200326:154804:INFO :0:
20200326:154804:INFO :0: $ WRITE SYS$OUTPUT ""
20200326:154804:INFO :0:
20200326:154804:INFO :0: $
20200326:154804:INFO :0: $ IF (SSHD$ERROR .NES. SSHD$INPUT_OUTPUT)
20200326:154804:INFO :0: $ ENDIF
20200326:154804:INFO :0: $
20200326:154804:INFO :0: $ ! SS_NORMAL, SSH was succcessful, command should send its error over net.
20200326:154804:INFO :0: $ EXIT 1
20200326:154804:INFO :0: Checking command results...
20200326:154804:INFO :0: Command successfully completed.
20200326:154806:INFO :0: Testing connection to '192.168.152.149' = True
20200326:154829:INFO :0: Testing connection to '192.168.152.149' = False
20200326:154839:INFO :0: Sleeping for 10 seconds...
20200326:154849:INFO :0: Stopping service ds20vms
20200326:154850:INFO :0: Service is Stopped
20200326:154850:INFO :0: Done. |
...
class | pagebreak |
---|
OPA0 console log (needs to be defined in the Charon configuration file):
...
language | text |
---|
...
Tip |
---|
It is recommended to check the log files once the Windows server has rebooted:
|
Include Page | ||||
---|---|---|---|---|
|