Skip to main content

Posts

Showing posts from 2014

Shutdown network computer using command line

To shutdown list of  PC or servers on the network using command line or via batch file.

Copy and paste line below to notepad and save it as "ShutPC.bat".

FOR /F  %%i  IN (d:\PCList.txt)  DO  Shutdown /M \\%%i  /S  /F 


Whatever list in "PCList.txt" will be shutdown.

To experiment on how the batch file will run or just to read the text file to make sure it will run automatically, do an 'echo' command.

FOR /F  %%i  IN (d:\PCList.txt)  DO Echo "Shutdown /M \\%%i  /S  /F  "

Shutdown a single server or PC:

Shutdown /M \\PC001  /S /F

Shutdown /M \\FileServer  /S /F



/F - will force the server or PC to shutdown. 

Run the batch file using a task scheduler so no need to monitor or execute the script manually.

PowerShell can also do powerful way of shutting down network computers, but old habits are hard to break..so command line still can do wonders and work best.

Automation is a lazy task for an smart IT administrator.


PowerShell get services on remote computers

To check or monitor services on remote computers using PowerShell is a one liner code.
To check Hyper-V Image Management Services on Server1:
Get-service -name vhdsvc -ComputerName Server1
Output will be:
StatusNameDisplayName --------------------- RunningvhdsvcHyper-V Image Management Service
Get-Service cmdlet also accepts wildcard, so to list all services starting with "v".
Type this command:
Get-service -name v* -ComputerName Server1
It will list all services starting with the letter "v".
Display name” or “service name” can be used as input parameter for the get-service cmdlet.


Get-service -name "DHCP Client" -ComputerName Server1


Get-service -name "DHCP" -ComputerName Server1
Both commands will resolve the "DHCP" service.
"DHCP Client" is the display name for DHCP service.
Get-service cmdlet will display the output; provided that the remote computer and the user account used to query have the appropriate rights on the re…

PowerShell get windows update

Updates are good if they will not mess up with the Operating System.
But since nothing is perfect in this world, updates could crash the system or worse create problems that will puzzle the IT guy.

Different hardwares, different third party softwares installed or custom applications, install on  a server or computer. That some updates will work perfectly on other systems but may create issues on other systems.
Troubleshooting the whole system trying to figure out what could be the culprit, but on the end messing up the whole system.
Bottom line, some updates may introduce some issues or mess up the system.
If you need PowerShell to list  all the updates, here is a simple code snippet to list all the KB Hotfix ID updates installed on the system.

Delete word Hyperlinks via VBA

This simple VBA code will delete all the hyperlinks on the active document.

Reading a word document with hyperlinks, is quite annoying sometimes.

If the hyperlink is accidentally click then it will open a browser and disrupt the momentum of reading the document.

And worse if the document link, points to a malicious website then it will be another issue.

Use the VBA code below to delete all hyperlinks on a word document.

The code will also display the number of lines on the document and also the total number of hyperlinks on the document.

===============================

Sub HyperLines()

 Dim nLines, i, x


 Selection.WholeStory


 i = Selection.Hyperlinks.Count


 nLines = Selection.Range.ComputeStatistics(Statistic:=wdStatisticLines)


 MsgBox "Number of Lines:" & nLines & " Number of Hyperlinks:" & i



 For x = 1 To nLines


 Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=x


 On Error Resume Next
 Application.ActiveDocument.Hyperlinks(1).Delete


 Next x

End Sub


=…

Disable Replace Text in Word using VBA

In word while you are typing, Word is smart enough to replace typing errors.

But if you are not typing in English language, it will be a mess if word will automatically replace the word.

Solution is to disable the feature "Replace Text as you type."

This simple VBA code snippet will disable the options "Replace Text as you type".

Disable is set to "False".

Application.AutoCorrect.ReplaceText = False


It can be done manually by clicking on: (Word 2010 procedure)

1. File
2. Options
3. Proofing
4. Auto Correct Options
5. AutoCorrect Tab
6. Untick "Replace text as you type"
7. Click "OK" 2 times to exit

But the one liner VBA code is quite simple rather than clicking so many times.

To enable via VBA just set the value to True.

Word VBA macro get username

A Word VBA macro to get username and record the date and time the document was opened and closed.

Private Sub Document_Open() -- Will run the macro if the document is open

Private Sub Document_Close() -- Will run the macro if the document is close

To run the macro, create a text file on this location.

D:\DocMonitor\wordUserClose.txt

D:\DocMonitor\wordUserOpen.txt

Change the file name and the location to any path and any desired file name.

==============================

Private Sub Document_Open()

Dim xUserName As String
Dim xDate As String
xUserName = Application.UserName

Dim xfileSystem, xwriteStream

xDate = Now()

Set xfileSystem = CreateObject("Scripting.FileSystemObject")
'fs.CreateTextFile "D:\DocMonitor\wordUserOpen.txt"
Set xwriteStream = xfileSystem.OpenTextFile("D:\DocMonitor\wordUserOpen.txt", 8, 0)
xwriteStream.WriteLine vbCrLf

xwriteStream.WriteLine Open Date and Time
xwriteStream.WriteLine xDate
xwriteStream.WriteLine xUserName
xwriteStream.Close


Set xfileS…