Skip to main content

Posts

Showing posts with the label Batch File

How to use hibernate in windows from command line?

Hibernate option in Windows is an option to shutdown any Windows laptop and after turning on again the laptop, all resources that was open before shutting down; such as word document, excel or other application are still available and running. The user doesn't need to re-open the applications. User  can continue where he or she has left off. Cool, feature! Using command line, the cli command shutdown.exe provides an option on how to shutdown a Windows machine to hibernate. The option I believe is available for all Windows edition even Server edition. Why do we need to use hibernate in Windows? Well, there are plenty of reasons. One example, if you have a few browser tabs open but then you need to shutdown the machine and don’t want to re-open all the browser tabs then hibernate is a good option. Or if you’re downloading something and you need to check whether download was completed, or just need to check whether there were some errors during the download operations then hibern...

Create a backup using Robocopy

Creating a backup is a must if not a necessity for a SysAdmin job. Backup doesn't need to be complex or needs a very powerful software to do a backup. At the end of the day, whether it's a good commercial software creating a backup; what it does in the background is create another copy of the file or folders that needs to be backed up. So, for that reason a simple copy command with the existing tool in Windows can do a job also for some simple backup like logs or other files. Why need to backup the logs? In a security perspective and audit purposes, logs are very important. Of course, it will also depend on the contents of the log whether it is quite detailed or important data is captured like username, IP Address, time, files and folder being accessed and other data. Problems or issues may not be detected in real-time or issues maybe notice at a later time but the action that cause the issue happened some time ago as well, in which the only witness are the logs. A simple batch...

Windows CLI get CPU Name, IP, OS, Mem and computer Name

One of the task of a Windows Admin is to know what OSes are running on his or her environment. Aside from checking what type of OSes are running, making sure also that CPU and Memory on users computers are suitable enough, so users can be productive. If the user doesn't have enough resources to run any software to do users tasks won't be  productive at all since and may end up consuming a lot of coffee than doing their work. :) So, as an IT Admin checking all these things will help to have a smooth operations. IP Address is the communication link of the device to the router, and the IP Address also links to the hostname or computer name and will be ultimately linked also to the logged in user. Example, deploying a specific software to a single user. IP Address must be known  in advanced or else the software being deployed might end up in someone else computer and can be disastrous if the license will be tied automatically to the hostname or IP Address.  WMIC command below...

Check Windows version Home or Pro via command line

How to check Windows if it is a Home or Pro version? WMIC a command line tool that is able to check the Windows version, build number and also shows whether the OS is a Pro or Home version. In an AD environment having a Home version of Windows is not a good idea as the OS isn't able to join a domain. Here's the WMIC command line to check. Open the command line window by pressing windows key + r, and type: cmd then press enter A new window will appear and type this command line: wmic os get BuildNumber, Version, Caption  After typing the command line and pressing enter  key, it will show a similar output like the image below: It will display, BuildNumber, Caption which will show whether the OS is home or pro, and the Version of the OS. That's it, WMIC is a great tool. Cheers. Till next time. Stay safe! and keep things up! ================================ Free Android Apps: Click  links below to find out more: Excel Keyboard guide: https://play.google.com/store/apps/details...

Use PowerShell in Excel VBA

VBA in Excel is very helpful since it can run things without any human intervention, or technically it can run task and automate things and just get the result. VBA coupled with PowerShell can even be more interesting. Of course, there is always some drawback or pros and cons. Bad actor can take advantage of VBA and PowerShell to run malicious software on user’s computer. For most users who are not aware or doesn’t believe that VBA and PowerShell can be used to steal data, one common reaction is; Is it possible? Or you are just trying to exaggerate and scare people? As the odds say, to see is to believe. Or to see it in action is one thing and trying to educate users is another thing. Cyber Security is a task that everyone should be a part of, a chain is useless if one its link is weak. Which is basically, true in digital world. The company may spend thousands of moneys on Firewall, Anti-Virus and other devices or software to thwart attack but just a simple click on a Phishin...

Nano editor shortcut keys

Nano editor in Linux is quite handy when working with text files in terminal window. Here's some keystroke that is quite useful when using Nano or editing text file with Nano. Ctrl + i  is like pressing the "Tab" key Ctrl + y will   go to top of the current displayed window or the top of the current nano screen Ctrl + v will go to the end of the current displayed window or the end of the current nano screen Ctrl + m  will move current line below the current cursor position Ctrl  + d will delete empty line                or will delete tab spaces                or will delete a single character if the line has text on it Ctrl + k   will cut the current line or current line will be cut and copied to clipboard (like Ctrl + x in word document if the text is highlighted) Ctrl + u   will paste the line that was cut or whatever is on the clipboard (like Ctrl /+ v in word doc...

PowerShell switch case call function

Code below collect user input and uses switch case statement to check if the input matches, and if it matches a function is called that will execute commands. Here’s the code: #get or read from user input $computer_name = read-host ( "Enter Computer Name:" )   switch ( $computer_name )   {     #if the input is computer_1 then function func_comuputer1 is called   computer_1     { func_computer1 }     computer_2     { func_computer2 }   }     #function called if computer_1 is the input function func_computer1 {   write-host "You entered Computer_1" #or replaced with other function like reboot / shutdown /or other commands #Restart-Computer -ComputerName computer_1   }   #function called if computer_2 is the input function func_computer2 {   write-host "You entered Computer_2" #or replaced with other function like reboot / shutdown /or other c...

PowerShell launch an application and close it automatically

Code below will run an application and PowerShell will also close it after a few seconds. $process_id = Invoke-CimMethod Win32_Process -MethodName "Create" -Arguments @{ CommandLine = 'cmd /c "C:\dev\remind.bat"' } | Select-Object processid | ft -HideTableHeaders | Out-String   Start-Sleep -Seconds 2.5   stop-process $process_id   Sample contents of remind.bat: @echo off echo "Shutdown the server. Do it now." Notepad ================== Notepad is on the batch file so the command window will stay on the top of any running applications. Sample output of the above code:   Code below will run calculator and close after a few seconds specified on the code: Invoke-CimMethod Win32_Process -MethodName "Create" -Arguments @{ CommandLine = 'calc.exe' } | Select-Object processid | ft -HideTableHeaders | Out-String   Start-Sleep -Seconds 2.5   $get_process_id = Get-Process ...