Dec/092
Create a Share Remotely using the WMI Command-Line Tool
To manage Windows remotely through the command line interface, you can can use wmic (comes with windows).
Here’s the syntax to create a Windows File Share on a remote machine using a single line of code. With Windows NT some might remember rmtshare.exe which did the same thing, but crashes with more recent versions of Windows.
wmic /node:%REMOTESERVER% share call create “”, “%DESCRIPTION%”,”%MAX CONNECTIONS (LEAVE BLANK FOR UNLTD)%”, “%SHARENAME%”,”" , “%LOCAL PATH TO FOLDER%”, 0
Example:
wmic /node:SERVER1 share call create "", "User Homedrive for microtom","", "microtom$","" , "D:\Shares\Users\microtom", 0
You can find more information on WMIC here:
http://technet.microsoft.com/en-us/library/bb742610.aspx
1,123 views
Nov/092
Recursively delete Subdirectories from a command prompt
Some might have noticed that the “del” command will only remove files in a directory and it’s subdirectories.
If you want to delete Subdirectories from a given starting directory (without deleting the root directory itself) you might want to parse through the root folder and delete every directory that is found.
Here’s a small for loop which does the trick.
In this example, all folders within the %temp% folder that start with “OL” would be deleted (Since that is what the “dir” command would return). You might want to modify the path and the wild card to suit your requirements.
In a command line:
for /f %i in ('dir %temp%\OL* /B /D') do rd %i /Q /S
In a batch file:
for /f %%i in ('dir %temp%\OL* /B /D') do rd %%i /Q /S
1,952 views
Aug/090
Multiping Machines with a Batch
Here’s a quick and easy way to ping multiple computers using a batch file (actually 2 batch files).
You could actually use a one liner, but this one is a bit more fancy and much quicker as it runs the pings in parallel.
Copy paste the code below into the corresponting file (both must be in the same directory) and run whatsup.cmd assets.txt
File: whatsup.cmd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | if not defined debug @echo OFF set ok=0 set nok=0 set count=0 cls echo. echo Pinging all adapters echo. set inputfile=%1 for /f %%i in (%inputfile%) do ( set /A count=count+1 start /B %~dp0\whatsuploop.cmd "%%i" ) echo %count% Pings running :wait_to_complete sleep 3 set missing=0 for /f %%i in (%inputfile%) do ( if exist %temp%\%%i.ok set /A missing=missing+1 if exist %temp%\%%i.false set /A missing=missing+1 ) echo %missing% Pings complete of %count% if not %missing%==%count% goto :wait_to_complete if exist %temp%\WHATSDOWN.txt del /Q TMP\WHATSDOWN.txt if exist %temp%\WHATSUP.txt del /Q TMP\WHATSUP.txt echo. echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo Details: echo. for /f %%i in (%inputfile%) do ( if exist %temp%\%%i.ok set /A ok=ok+1&&echo [RUNNING] %%i>>%temp%\WHATSUP.txt if exist %temp%\%%i.ok del %temp%\%%i.ok if exist %temp%\%%i.false set /A nok=nok+1&&echo [STOPPED] %%i>>%temp%\WHATSDOWN.txt if exist %temp%\%%i.false del %temp%\%%i.false ) if exist %temp%\WHATSDOWN.txt type %temp%\WHATSDOWN.txt if exist %temp%\WHATSUP.txt type %temp%\WHATSUP.txt if exist %temp%\WHATSDOWN.txt type %temp%\WHATSDOWN.txt>WHATSDOWN.txt if exist %temp%\WHATSUP.txt type %temp%\WHATSUP.txt>WHATSUP.txt if exist %temp%\WHATSDOWN.txt del /Q %temp%\WHATSDOWN.txt if exist %temp%\WHATSUP.txt del /Q %temp%\WHATSUP.txt echo. echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo Summary: echo. echo [RUNNING] %ok% echo [STOPPED] %nok% echo. echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo. :EOF |
File: whatsuploop.cmd
1 2 3 4 5 6 7 8 | @echo off ping -n 1 -l 8 -f %1>NUL if %errorlevel%==0 ( echo.>%temp%\%1.ok ) else ( echo.>%temp%\%1.false ) exit |
File: assets.txt
1 2 3 4 | COMPUTER1 COMPUTER2 COMPUTER3 etc.. |
321 views
Aug/090
The Power of Command Lines
Years pass by but “Good Admins still don’t need a mouse!”
I remember a lot of situations where they said DOS will be replaced and will become obsolete. It’s windows 7 time and I can still open a DOS box by typing “cmd” into the Run command. No matter if they created a scripting host, a .net framework or a Powershell: To administer Windows based Operating systems the Command Line is faster and almost as powerfull than any of them. All you need is the right tools and a bit of knowledge.
What else can reboot 100 Servers in just a few Minutes without installing any 3rd Party Tool? Simply create a text file, add the desired node names and execute
for /f %i in ("servers.txt") do shutdown \\%i /r /t 1 /f
in a Command Line and the show starts!
Starting off with a single line such as a simple “Ping” or a “for” loop, you’ll soon realize that batch files can do much more than just that!
It’s been more than 10 Years since I’ve opened my first CMD on Windows and I am still opening at least one every day. If built in commands do not cover my needs and if I cannot find any Command Line Tool on the web to do the job, I definitely prefer creating tools that can be executed from a Command Line instead of that graphical stuff. Now if you’re a UNIX admin, you might wanna say “What is Graphical?”, if you’re a MAC user (do they have admins as well?) you might think “Where are the icons and why can’t i do a single click to do the trick?” and if you’re a Linux user you probably can’t read this because you’re still trying to figure out where you can get a Network Driver that actually works with your Hardware, but as a Windows Server Administrator you have just a great tool that has not changed too much over all these years.
Want to feel the power? Check out the “Adminstration Tools” section on this website and download the Tools that make your life easier!
168 views

(2 votes, average: 4.50 out of 5)