Skip to main content

Posts

Showing posts from December, 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 ...

PowerShell working with registry keys

Basic PowerShell commands to work with Windows Registry. Don't mess up with the registry, if you're not sure of what you are doing. Messing up with the registry for fun is just good in a virtual environment with no important data at all.   To list software registry keys on path HKCU type this command below: Get-ChildItem -Path hkcu:\software   | Select Name It will list all the software registry keys, it's good to list all the software registry keys and check for any illicit software installed by malwares or viruses. If there's a lot of software installed on the PC it will be a long list. But PowerShell comes handy when it comes to filtering. Code below will filter for any Keys in HKCU path that has "Ad" values on it. Use the parameter "-like" and not "-eq", -eq or equal will match 100% and will not return any value if no match at all. Get-ChildItem -Path hkcu:\software   | Where-Object {$...

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: Status    Name                  DisplayName                            ------       ----                     -----------                            Running   vhdsvc              Hyper-V Image Management Service Get-Service cmdlet also accepts wildcard, so t...

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. ====================================== $xUpdate =Get-WmiObject -Class WIN32_QuickFixEngineering | select HotFixID foreach ($LineUpdatex in $xxUpdate) { write-host $LineUpdatex `n } ========================...

Find current wallpaper in Windows 7

Find or get the current background or wallpaper in Windows 7. Browse to this path: C:\Users\UserName_J\AppData\Roaming\Microsoft\Windows\Themes Just type it on windows explorer address bar, replace "UserName_J" with your user name and press enter. The "Themes" folder will open and the current background or wallpaper will be in this folder. Or press "Windows Key + R" to open run box; then type %appdata% then browse to Roaming, Microsoft, Windows and Themes. Typing %appdata% will open the appdata folder of the current user, this will work in Windows 7 and Windows 8 OS. PowerShell version to check for wallpaper: http://quickbytesstuff.blogspot.sg/2015/11/powershell-check-wallpaper-location.html

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  Appli...

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 ...