<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andrew Morgan &#187; Batch</title>
	<atom:link href="http://andrewmorgan.ie/tag/batch/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmorgan.ie</link>
	<description>Grumpy ramblings</description>
	<lastBuildDate>Fri, 30 Jun 2017 09:24:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>Administration Automation Part 1:</title>
		<link>http://andrewmorgan.ie/2008/09/server-build-automation-part-1/</link>
		<comments>http://andrewmorgan.ie/2008/09/server-build-automation-part-1/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 21:07:20 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[users]]></category>

		<guid isPermaLink="false">http://andymorgan.wordpress.com/?p=119</guid>
		<description><![CDATA[Every company has there build specs, their dummy accounts, after installation software and other internal doo dad&#8217;s they feel are vital to the build. Even with imaging you can never guarantee its all done right so i always prefer to script the end of install just to make sure its clean, fresh and right each time a system comes off the build line. Heres a few pointers i threw together to get your &#8220;post build&#8221; script in order starting with [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright" src="/wp-content/uploads/2008/07/images.jpg?w=144&amp;h=108&amp;h=108" alt="" width="144" height="108" />Every company has there build specs, their dummy accounts, after installation software and other internal doo dad&#8217;s they feel are vital to the build. Even with imaging you can never guarantee its all done right so i always prefer to script the end of install just to make sure its clean, fresh and right each time a system comes off the build line.</p>
<p>Heres a few pointers i threw together to get your &#8220;post build&#8221; script in order starting with dummy accounts, passwords and user memberships.</p>
<p><strong>Renaming the administrators account (admrename.vbs):</strong></p>
<p style="padding-left:30px;">strComputer = &#8220;.&#8221;<br />
Set wshShell = WScript.CreateObject( &#8220;WScript.Shell&#8221; )<br />
strComputerName = wshShell.ExpandEnvironmentStrings( &#8220;%COMPUTERNAME%&#8221; )</p>
<p>Const ADS_UF_DONT_EXPIRE_PASSWD = &amp;H10000</p>
<p>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; &amp; strComputer &amp; &#8220;rootcimv2&#8243;)<br />
Set colAccounts = objWMIService.ExecQuery _<br />
(&#8220;Select * From Win32_UserAccount Where LocalAccount = True And Name = &#8216;Administrator'&#8221;)</p>
<p>For Each objAccount in colAccounts<br />
objAccount.Rename &#8220;ADM&#8221; &amp; <strong>strComputerName</strong></p>
<p>The above script will rename the Administrator account to ADMcomputername, it can easily be changed to a static name deleting the &amp; <strong>strComputerName </strong>and adding the full name in the &#8220;&#8221; &#8216;s.</p>
<p><strong>Creating a local account using the command line (batch):</strong></p>
<p style="padding-left:30px;">net user<strong> patchacc passw0rd </strong>/add /comment:&#8221;Patch account&#8221; /fullname:&#8221;windows Patch account&#8221; /active:yes /passwordchg:no /passwordreq:yes</p>
<p>the above script will create a username (patchacc) with password (passw0rd), the account will also be enabled.</p>
<p><strong>Add an account to the local administrators(batch):</strong></p>
<p style="padding-left:30px;">net localgroup /add administrators patchacc</p>
<p>The above command adds the username patchacc to the local group administrators, you can use the above command to add a domain account using net localgroup /add administrators domainusername.</p>
<p><strong>Setting a password to never expire (pwd.vbs):</strong></p>
<p style="padding-left:30px;">Set objUser = GetObject(&#8220;WinNT://&#8221; &amp; strcomputer &amp; &#8220;/<strong>username</strong>&#8220;)<br />
objPasswordNoChangeFlag = objUser.UserFlags XOR ADS_UF_DONT_EXPIRE_PASSWD<br />
objUser.Put &#8220;userFlags&#8221;, objPasswordNoChangeFlag<br />
objUser.SetInfo</p>
<p>The above scriptlet will simply set the password to the &#8220;username&#8221; account to never expire, dont try to do it with net user, it doesnt work&#8230; ever.</p>
<p><strong>Creating a dummy administrator account:</strong></p>
<p style="padding-left:30px;">net user <strong>Administrator Notreal123 </strong>/add /comment:&#8221;Bogus Admin Account&#8221; /fullname:&#8221;Bogus Admin Account&#8221; /active:no /passwordchg:no /passwordreq:yes</p>
<p>The above script will create a disabled user called administrator (rename the current administrator first), with password of Notreal123.</p>
<p>After the jump is an example of how to tie them all into one super script and the source files.</p>
<p><a href="http://www.4shared.com/file/64993533/ef9ff324/users.html" target="_blank">http://www.4shared.com/file/64993533/ef9ff324/users.html</a></p>
<p><span id="more-119"></span></p>
<p>REM copy the entire cotents of the zip to a share name on your network, add the share to the below statement.<br />
set netdir=servernameshare</p>
<p>@echo Creating Patch account &amp; net user patchacc passw0rd /add /comment:&#8221;Patch account&#8221; /fullname:&#8221;windows Patch account&#8221; /active:yes /passwordchg:no /passwordreq:yes<br />
@echo.<br />
@echo Renaming admin account &amp; cscript /b &#8220;%netdir%admrename.vbs&#8221; &amp; echo Complete<br />
@echo.<br />
@echo Fixing password &amp; cscript /b &#8220;%netdir%pwd.vbs&#8221; &amp; echo Complete<br />
@echo.<br />
@echo Adding Dummy account &amp; et user Administrator Notreal123 /add /comment:&#8221;Bogus Admin Account&#8221; /fullname:&#8221;Bogus Admin Account&#8221; /active:no /passwordchg:no /passwordreq:yes<br />
@echo.<br />
@echo adding patch to local admins. &amp; net localgroup /add administrators patchacc</p>
<p>pause</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2008/09/server-build-automation-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting Files older than X, Forfiles.exe.</title>
		<link>http://andrewmorgan.ie/2008/02/deleting-files-older-than-x-forfilesexe/</link>
		<comments>http://andrewmorgan.ie/2008/02/deleting-files-older-than-x-forfilesexe/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 10:12:50 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://joekickass.wordpress.com/?p=31</guid>
		<description><![CDATA[As part of my recent Citrix cleanup i found the need to clear down an applications log files folder, this folder existed in the program files directory and was eating up gb&#8217;s of space with useless logs. The only difference between these files and standard logs was that sometimes recovery was neccessary so it was agreed that a 7 day retention would be kept. With the 7 day retention it made it slightly more complicated to batch, but with a [&#8230;]]]></description>
				<content:encoded><![CDATA[<p align="left"><img class="alignright" src="/wp-content/uploads/2008/07/images.jpg?w=144&amp;h=108" alt="" width="144" height="108" />As part of my recent Citrix cleanup i found the need to clear down an applications log files folder, this folder existed in the program files directory and was eating up gb&#8217;s of space with useless logs. The only difference between these files and standard logs was that sometimes recovery was neccessary so it was agreed that a 7 day retention would be kept.</p>
<p>With the 7 day retention it made it slightly more complicated to batch, but with a little searching and trial/error i present to you <a href="http://technet2.microsoft.com/windowsserver/en/library/9660fea1-65c7-48cf-b466-204ba159381e1033.mspx?mfr=true">forfiles</a>. As far as I&#8217;m aware this program comes with server 2003 tools, but could be wrong. a bit of googling will find you a copy.</p>
<p>Forfiles allows you to execute individual commands for files that meet certain criteria, in my case it was the Date index. Not only this but it allows for &amp; commands&#8230; excellent little batch tool!</p>
<blockquote><p><em>forfiles -d -8 -c &#8220;cmd /c echo Deleted: @file @fdate &gt;&gt; %apath% &amp; del @file&#8221;</em></p></blockquote>
<p>Once i had decided it was forfiles i was going to use, i had a few options. but seeing as this tool was not on all servers, and i wanted to log it centrally with the least ammount of logging, i chose to run it from central.</p>
<p>Below is a step by step of what i did.</p>
<blockquote><p>@echo off<br />
set apath=c:avyaclean.log<br />
echo. &gt;&gt; %apath%<br />
echo.Time Starting: %time% &gt;&gt; %apath%<br />
Pushd Servernamec$Program Filesapplogs<br />
forfiles -d -8 -c &#8220;cmd /c echo Deleted: @file @fdate &gt;&gt; %apath% &amp; del @file&#8221;<br />
echo. &gt;&gt; %apath%<br />
echo. Finished @ %time% &gt;&gt; %apath%<br />
popd<br />
EXIT</p></blockquote>
<p>The meat of this statement is here: forfiles -d -8 -c &#8220;cmd /c echo Deleted: @file @fdate &gt;&gt; %apath% &amp; del @file&#8221;. this basically says, any files older than 8 days (modified, not created date) run a command prompt that echos the file name and modify date to a text file specified &amp; <strong>delete</strong> the file.</p>
<p>You can do this on as many servers as you like, just change the servername and copy and paste <img src="http://andrewmorgan.ie/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2008/02/deleting-files-older-than-x-forfilesexe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handy Search Trick</title>
		<link>http://andrewmorgan.ie/2007/09/handy-search-trick/</link>
		<comments>http://andrewmorgan.ie/2007/09/handy-search-trick/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 13:53:57 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://joekickass.wordpress.com/?p=26</guid>
		<description><![CDATA[Want to run a few searches? cant be arsed with the slow console in the shell or the stupid search assitant? open a cmd prompt open the root directory (cd ) and do a Dir /s whatever*. handy for multiple searches and doesnt kill your session&#8230; try to use wildcards (*&#8217;s) as its a bit fussy]]></description>
				<content:encoded><![CDATA[<p>Want to run a few searches? cant be arsed with the slow console in the shell or the stupid search assitant?<img class="alignright" src="/wp-content/uploads/2008/07/images.jpg?w=144&amp;h=108&amp;h=108" alt="" width="144" height="108" /></p>
<p>open a cmd prompt</p>
<p>open the root directory (cd ) and do a <strong><em>Dir /s whatever*.</em></strong></p>
<p>handy for multiple searches and doesnt kill your session&#8230; try to use wildcards (*&#8217;s) as its a bit fussy <img src="http://andrewmorgan.ie/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2007/09/handy-search-trick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
