Skip to main content

Posts

Showing posts from April, 2014

Beginning PowerShell from Step1 to Step1 (Part II)

                    Part of I of Beginning PowerShell from Step1 to Step1, it discusses on how to store variables on PowerShell, how to use For Loop statement and how to process conditional statements using the switch command. Learning PowerShell by actually doing it; is easier to learn and you will be able to appreciate how the platform will be able to help ease your life as an IT guy in your daily life at work. On this Part II of Beginning PowerShell, will use PowerShell to run or invoke a command line. As the title speaks of its content, Beginning PowerShell this are just simple scripts to follow.  And of course if PowerShell will always be your companion at work, as days pass by complex ideas or scripts will come along. But as the odds say, a long journey starts with a single step. So a good foundation, a simple start can lead a long, long way Here’s the goal:  A PowerShell script that will execute a...

Sort files using command line

Sort files by file size using command line. A simple one liner command to sort file by size. Command line below will sort from smallest file size capacity to the file with biggest size capacity. dir *.txt | sort /+20  >d:\txtsort.txt dir *.pdf | sort /+20  >d:\pdfsort.txt dir *.doc | sort /+20  >d:\docsort.txt dir *.avi | sort /+20  >d:\avisort.txt dir *.mp3 | sort /+20  >d:\mp3sort.txt dir *.mp4 | sort /+20  >d:\mp4sort.txt Get all files and sort it by size dir *.* | sort /+20  >d:\SortAllFiles.txt PowerShell can also achieve this result but a simple command line can do the job. It can be written on a batch script and run the batch file against a shared folder. To sort files by date using command line, use this command below: dir *.txt | sort  /+10 It work sort text files by its modified or creation date. To sort application based on memory usage use this command line below: Tasklist | sort ...

Batch file date format

How to get date in batch file scripts? Keeping track of log files with date on the filename is a good practice. Easier to manage and keeping track of the files is not difficult and whenever there’s a need to review the log files you can just open the exact date that you need to check. Using command line you can get time and date. Getting the date in command line comes in one format. Running this command:  echo %date% It will display an output like: Mon 04/21/2014 and this is the only format that can be displayed using the command above. But using batch file scripts it can be processed to some other formats that are a standard in an organization. If it is using DD-MM-YYYY, OR MM-YYYY-DD, or Day of the Week+ MM+YY+DD and other specified formats. The output of echo %date% which is “Mon 04/21/2014” is a 15 columns string including spaces. It’s quite important to know that the output is a 15 columns string; to trim the output to get the desired d...

How to use batch file to register DLLs or to move or copy files

Batch file scripts below will register DLLs, copy or moved files. Be careful in moving files as it would overwrite if there is an existing file on the destination folder.     This batch file script below would register DLL files in a specified folder. REM Start Copy Here REM Register DLL files @echo off set cnt=0 for %%v in (C:\MyCustomApp\*.dll) do (    regsvr32 /s "%%v"    call set /a cnt=%%cnt%%+1    ) echo Total dlls found and registered = %cnt% REM End of Batch File Using same batch file it can be tweak to copy any specified files to a particular folder. If you have a folder with PDF, Excel Files or other documents. And you just want to copy files or move files to another folder, batch scripts below would help. This simple batch file below would copy files to a specified folder. REM Start Copy Here REM Copy PDF Files to another folder @echo off set cnt=0 for %%v in (d:\MixFilesFo...

PowerShell check folder for modified files in the last X minutes

How to use PowerShell to check modified files or files on a particular folder? If you ever find yourself in a situation, to monitor file or files that was changed or modified, for the last few minutes. PowerShell will be able to solve the issue. This would be very useful in an environment where a file is shared by a group of people and anyone can access or modified the file. In order to check or keep track whether the file has been changed, PowerShell script is able to monitor and send an email to alert that the file has been modified. Use the script below and run it on Task Scheduler, at an interval of every hour if the $xminutes is set to 60. But of course if you want to check for every 30 minutes, then task scheduler should also be set to run every 30 minutes. How to run the script below on PowerShell? Use this command on Task Scheduler to run a PowerShell script. PowerShell –file “c:\path_to_your_PS_script\PowerShell_Name.ps1 -noexit Script ...

Define and use names in Excel formulas and in VBA

Using Excel 2010, cell address can be replaced by a name or in another point of view it is some sort of an alias for a cell address. You can define a name for a particular cell, based on its value. It’s quite easy to remember a name rather than a cell value if you are working in multiple workbooks. But of course it’s a personal preference whether to remember cell addresses or just use names. Excel 2010 has 1,045,876 rows and 16,384 columns. To define use name in Excel formulas, on the Excel ribbon click on “Formulas” and on the options available click on “Define Name”. (See screen shot below) On the worksheet, select the cell which a name will be defined and click on “Define Name”. After clicking define name option, a window will open and type the name for the cell address. (See screen shot below) After defining the name, on the name box (on the upper left corner of the worksheet) it will display the defined name instead of the cell address. (See...

How to launch and check device manager on Windows 7

Open device manager on Windows 7. 1. Click on start button. 2.  In the search box type "device manager" without quotes. (see screen shot below) 3. Wait for the results to populate and click on device manager. 4. Device manager window will open. 5. On device manager there are indicators to easily spot if there are issues on the system     A question mark would indicate that the driver is not installed properly or the system is not able to find the driver or some other issues. 6. To check whether the device is disabled, a small black arrow within a small circle would indicate that the device has been disabled. (see screen shot below) 7. How to see sub items or the specific properties within a particular device, click the right arrow. (see screen shot below) 8. To disable or enable a particular item, right click the item and options will open. If the device is enabled, you will have an option to disabled. And of cours...