Helper Commands

BATCH / CMD

Uninstall Windows Updates:

Run the following (update the list to contain valid KB numbers) to uninstall updates on a local system:
1
@ECHO OFF
2
SET list=3133977 3137061 3138612 3138901 3139923
3
4
for %%a in (%list%) do (
5
%windir%\syswow64\wusa.exe /uninstall /kb:%%a /quiet /norestart /log​
6
)
Copied!

Get Remote Host Windows Updates

Run the following (update the hosts list with valid hostnames) to get .CSV output of updates on remote systems:
1
@echo off
2
SET dFormat=_%date:~-4,4%%date:~-10,2%%date:~-7,2%
3
SET sCMDparams=qfe get Caption, Description, HotfixID, InstallDate, InstalledBy /format:csv
4
SET hosts=HOSTNAME1 HOSTNAME2
5
6
ECHO %dFormat%
7
ECHO .
8
FOR %%f in (%hosts%) DO (
9
ECHO Processing %%f
10
ECHO Output file: %%f_%dFormat%.csv
11
wmic /NODE:%%f /output:%%f_%dFormat%.csv %sCMDparams%
12
)
13
ECHO .
14
ECHO Remember to delete the first blank line
15
ECHO .
16
ECHO .
17
ECHO Finished.
18
ECHO .
Copied!

Send a Message to Remote Computer

1
msg susie /SERVER:WKST-ABC.burmat.co "Please call 123-456-7890 x369"
Copied!
Or you can launch it to all users on a given computer if you don't know the username. Enable verbose mode (/V) and wait for a callback (/W) to get a callback when the user closes it:
msg * /V /W /SERVER:WKST-123 This is a test message

Restart Remote Machine (With Warning)

This script is better kept out in a public place and called with the a remote command utility to loop through a list of hostnames. You can just replace the %1 to hardcode a host if you want though.
1
@echo off
2
REM shutdown -m \\%1 /a
3
echo Start Checking %1
4
5
ping -n 1 -l 100 %1
6
IF %ERRORLEVEL%==1 GOTO BAD
7
shutdown -r -f -m \\%1 -t 300 -d up:125:1 -c "Please SAVE Your work. In 5 minutes, this machine will reboot for a policy updates (Msg time: %time%)"
8
GOTO GOOD
9
10
:BAD
11
ECHO %1,Failed,%date%,%time% >> BadPCs.txt
12
GOTO EXIT
13
14
:GOOD
15
ECHO %1,Good,%date%,%time% >> GoodPCs.txt
16
GOTO EXIT
17
18
:EXIT
19
echo Stop Checking %1
Copied!

BASH

Comment / Uncomment Lines

When you need to comment out or uncomment out a line, sed makes it pretty easy. Just change the word pattern to something identifiable:
1
sed -i '/pattern/s/^/#/g' apache2.conf # comment
2
sed -i '/pattern/s/^#//g' apache2.conf # uncomment
Copied!

POWERSHELL

Remotely Log User Out

1
PS C:\WINDOWS\system32> Invoke-Command -ComputerName 'SERVER01' -ScriptBlock { quser }
2
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
3
admin console 1 Active none 12/24/2018 10:35 AM
4
5
PS C:\WINDOWS\system32> Invoke-Command -ComputerName 'SERVER01' -ScriptBlock { logoff 1 }
Copied!
Last modified 2yr ago