31 December, 2009

Simple delete of subdirectories only

Hi,

Just found a solution to delete subdirectories from the root of a disk.
Normally to delete a subdirectory you use the RD command but you cannot delete the root folder so you have a problem.

Not anymore...

================================
dir f: /B > dir.txt
for /f %%f in (dir.txt) do (rd f:\%%f /S /Q)
del dir.txt /q
================================

Enjoy.

14 September, 2009

Automatic backup of XenServer vm with vm-export

Hi,

I needed to schedule a weekly backup of my VM's in my XenServer.
When I googled it I found a script written by Jeff Riechers, this script was good but did not help me because I did not have enough storage to take a snapshot to each VM.
I had to tweak it and I improved the method of retrieving the uuid (no more temp files...).

The final script reads from a file (named serverlist.txt) the vm name and the host on it resides. This is because I noticed that when I shut down the VM it gets a deferent home server, so I forced it to start on a specific host.

Just schedule it with cscript and your good to go.

Link to the script

03 August, 2009

do a smart .NET 3.5 install...

The main problem (as I see it) with the .NET install, that it is not "smart" enough. I mean run it once or twice it will allways run the same install.
If you want to make sure your clients is .NET "enabled" just use my small startup script (or SCCM).

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

reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" /v Version | findstr "v3.5"
if %errorlevel%==0 goto end

"%~dp0dotnetfx35.exe" /q /norestart
exit /B %errorlevel%

:end
==========================================

02 August, 2009

run script only when the user got his desktop

Hi,

I had a problem, I needed to change all the workstations screen resolution at my client network.

I found a cool small tool named ResSwitch, the problem with it that it can only run when a user has it's desktop loaded.

I added the following lines to chack if the user desktop is ready.

====================================
:check_4_explorer
tasklist find "explorer"
if %errorlevel% == 1 goto check_4_explorer

"%~dp0ResSwitch.exe" /WIDTH:1280 /HEIGHT:1024
====================================

28 July, 2009

Cool way to run interactive CMD with SYSTEM Account

Just save it as a CMD file, run it and wait a minute… (dont run it in the 59 minute of the hour)

===========================================
Set sMinutes=%time:~3,2%
set/a sMinutes=%sMinutes%+1

if %sMinutes% LSS 10 (set sMinutes=0%sMinutes%)

echo %time:~0,2%:%sMinutes%
at %time:~0,2%:%sMinutes% /inter cmd.exe
===========================================

19 May, 2009

Smart Ping when restarting

Hi,
You restart a remote server because you installed some new MS updates and you need to know when it's back online.
What we all do?, start pinging the server and continue to do other things.
when we come back after few minutes to the ping window we see that the server is online but we missed to see it's gone offline.
The following script (I called it "Smart Ping") will check the output from the ping action and look for specific word to let you know that the server went down and went up again.

Fill free to change the words it searches as you see fit in your environment.

=======================================
echo off
cls
:dead
title Server [%1] is going to shut down [%time%]...
ping -n 1 -w 300 %1 find "Request timed out."
IF %ERRORLEVEL% == 0 (goto back_alive) ELSE (goto dead)
:back_alive
title Server [%1] is down [%time%]...
ping -n 1 -w 300 %1 find "TTL"
IF %ERRORLEVEL% == 0 (goto end) ELSE (goto back_alive)
:end
title Server [%1] is Back online [%time%]...
pause
=======================================

Enjoy...

10 May, 2009

How to get the DN from an NT name...

Hi,

If you are scripting you may came across the annoying problem of the DN name.
In everyday activity you use the NT name of an object from Active Directory but when you want to start scripting - no... you need the DN.

The following Script will help you convert on the fly the NT name to DN object.

===================================
private function TranslateNTName(ntname)
dim nto
dim result
const ADS_NAME_INITTYPE_SERVER = 2
const ADS_NAME_INITTYPE_GC = 3
const ADS_NAME_TYPE_1779 = 1
const ADS_NAME_TYPE_NT4 = 3
TranslateNTName=""
set nto = CreateObject("NameTranslate")
'on error resume next
nto.Init ADS_NAME_INITTYPE_GC , ""
nto.set ADS_NAME_TYPE_NT4, ntname
TranslateNTName = nto.Get(ADS_NAME_TYPE_1779)
on error goto 0
end function

wscript.echo TranslateNT4Name ("domain\user")
===================================

Enjoy

Get AD group members (including nesting)

I looked for some time now for a command that will give me all the members of a group even if it contains nesting groups.





I'm happy to inform you that the answer was allways under my nose.





The command was: DSGET.





The following syntax worked for me:


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


dsget group CN=Group_Name,OU=Groups,DC=domain,DC=local -members -expand


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





MS Link





You can mix it up with my tip on how to get the DN from an NT name and simplify the command...

16 April, 2009

Get real help with "Performance Advisor"

Hello,
I came across an excellent tool for Trouble Shooting from Microsoft named "Performance Advisor v2", if you need a real in-depth help - try this one.
It will give you pre-saved templates for all kind of servers and problems. And the most important - it will help understand the results.

I had performance issues on a Domain Controller and after using this tool, I could tell which server is stressing the DC and with what query !!!

Amazing...

Here is a link to the download: http://www.microsoft.com/downloads/details.aspx?FamilyID=09115420-8c9d-46b9-a9a5-9bffcd237da2&DisplayLang=en

[Will only work on Windows 2003 server...]


Update:
There is v3 at: http://msdn.microsoft.com/en-us/library/windows/hardware/dn481522.aspx  will work on newer versions (need SQL now...)

05 April, 2009

Install Software (mostly MS patches) by OS type

You want to install MS patch but there are 2 kind of patches, one for XP and one for Win2k3.
Here is a small script to let you do just this.
It basically query the registry for the OS type search for a string and run a program by the output.

=================================
reg query HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions find "WinNT"
if %errorlevel% == 0 (goto xp) else (goto server)
:xp

\\nt_dn\netlogon\timezonepatch\WindowsXP-KB955839.exe /quiet /norestart
goto end
:server

\\nt_dn\netlogon\timezonepatch\WindowsServer2003-KB955839.exe /quiet /norestart
:end
=================================

Enjoy...

02 April, 2009

Run Scripts With GPP

Hi,


You may work with GPP and noticed that you cannot run scripts with this excellent technology.



Well, I found a way to override this by adding a registry key in the user settings to the RunOnce key (HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce), this way the script only run once and also, if the user login at home (laptop user) the script will not run.


Very much like a logon script but using GPP.



01 April, 2009

See which machine is alive...

If you need to run on a list of machines with some command, you want to make sure that the workstations (or servers) are alive and pingble.
The following script allow you to do just that.
It contains 3 elements:
  1. "computers.txt" - the full list of computers in your LAN (probably from AD), names only!!!
  2. "Step1.cmd" - run's the next file in a loop on each line from "computers.txt"
  3. "Step2.cmd" - The command itself.

content of step1.cmd:
======================
for /f %%A in (computers.txt) do (step2.cmd %%A)
======================

content of step2.cmd:
======================
ping -n 1 -w 300 %1 find "TTL">nul
IF %ERRORLEVEL% == 0 (echo %1 >> alive.txt) ELSE (echo %1 >> dead.txt)
======================

Put them all in the same directory, execute step1.cmd and the script will split the big list into 2 small lists, alive.txt and dead.txt - the content is self applies...

By for now...