Archive for category Batch Scripting
Open Windows Firewall ports for SQL Server 2008
Posted by shawson in Batch Scripting, SQL Server, Windows on November 4, 2011
http://support.microsoft.com/kb/968872
As noted in the article, you can run this batch file;
@echo ========= SQL Server Ports =================== @echo Enabling SQLServer default instance port 1433 netsh firewall set portopening TCP 1433 "SQLServer" @echo Enabling Dedicated Admin Connection port 1434 netsh firewall set portopening TCP 1434 "SQL Admin Connection" @echo Enabling conventional SQL Server Service Broker port 4022 netsh firewall set portopening TCP 4022 "SQL Service Broker" @echo Enabling Transact-SQL Debugger/RPC port 135 netsh firewall set portopening TCP 135 "SQL Debugger/RPC" @echo ========= Analysis Services Ports ============== @echo Enabling SSAS Default Instance port 2383 netsh firewall set portopening TCP 2383 "Analysis Services" @echo Enabling SQL Server Browser Service port 2382 netsh firewall set portopening TCP 2382 "SQL Browser" @echo ========= Misc Applications ============== @echo Enabling HTTP port 80 netsh firewall set portopening TCP 80 "HTTP" @echo Enabling SSL port 443 netsh firewall set portopening TCP 443 "SSL" @echo Enabling port for SQL Server Browser Service's 'Browse' Button netsh firewall set portopening UDP 1434 "SQL Browser" @echo Allowing multicast broadcast response on UDP (Browser Service Enumerations OK) netsh firewall set multicastbroadcastresponse ENABLE
Command Line- create a folder named with todays date
Posted by shawson in Batch Scripting on August 23, 2011
mkdir %date:~-4,4%%date:~-7,2%%date:~0,2%
will produce a folder named like this; YYYYMMDD
Thanks to Mr Carmichael for this..
Command line to delete every file older than 30 days
Posted by shawson in Batch Scripting on February 19, 2010
I found a new command line directive i’d never heard of today, along with a brilliant example of it’s use- once you have changed your working directory, running this will remove any files or folders older than 30 days;
FORFILES /D -30 /C "CMD /C IF @isdir==FALSE (echo Deleting File @file) & (ATTRIB -H @file) & (DEL /F /Q @file) ELSE (echo Deleting Directory @file) & (ATTRIB -H @FILE) & (RD /S /Q @FILE)"
As an example, I’ve since used this to iterate over a bunch of folders, deleting any files over 30 days;
d:
for /f "delims=|" %%f in ('dir /b D:\_SQL_Backup\') DO (
cd \_SQL_Backup
cd %%f
FORFILES /D -14 /C "CMD /C IF @isdir==FALSE (echo Deleting File @file) & (ATTRIB -H @file) & (DEL /F /Q @file)"
)
Umbraco Installation – folder permissions setup
Posted by shawson in Batch Scripting, Umbraco on November 30, 2009
Just a real quick batch script i knocked up which sets the appropriate permissions to the various folders in the root of a fresh umbraco install- just drop this into a batch file, and run it from the root of your umbraco install;
REM 2009.10.22 SY - Set permissions- user/ folders from "Install Umbraco 4 on Windows Vista" guide icacls app_code /grant "Network Service":(OI)(CI)(F) icacls bin /grant "Network Service":(OI)(CI)(F) icacls config /grant "Network Service":(OI)(CI)(F) icacls css /grant "Network Service":(OI)(CI)(F) icacls data /grant "Network Service":(OI)(CI)(F) icacls masterpages /grant "Network Service":(OI)(CI)(F) icacls media /grant "Network Service":(OI)(CI)(F) icacls python /grant "Network Service":(OI)(CI)(F) icacls scripts /grant "Network Service":(OI)(CI)(F) icacls umbraco /grant "Network Service":(OI)(CI)(F) icacls usercontrols /grant "Network Service":(OI)(CI)(F) icacls xslt /grant "Network Service":(OI)(CI)(F) pause
Command line Batch File to Remove Direcories, using a Wild Card!
Posted by shawson in Batch Scripting, Command Line on October 28, 2009
We have a bunch of web services which log details of requests that come in, in folders named using the current date- in the format YYYY-MM-DDD-HH-MM-SS. I wanted to produce a simple cleanup batch file which we could run every month to bin all logs for transactions which happened 3 months ago- using the dos commands which exist on Windows Server 2003.
The dos “del” command allows you to delete using wild cards – so for example “dev 2009-07-*” would erase any files starting with “2009-07-”; However this doesn’t work with folders- so it fell to the rd (remove directory) command- but this doesn’t support wild cards (I’m assuming for safety- to stop you permanently erasing 100′s of folders and their contents accidently- remember there’s no recycle bin when you delete from the command line!).
To get around this I created a simple Batch file which accepted a wildcard as a parameter, then removes all those folders at the current level (it wont check recursivly). Just in case this is of use to anyone else, here’s the code;
REM - performs a remove directory, with wildcard matching - example ; rd-wildcard 2007-* dir %1 /b >loglist.txt setlocal enabledelayedexpansion for /f %%a in (./loglist.txt) do ( rd /s /q %%a ) del /q loglist.txt endlocal