Using a batch file to find and replace contents of files
0Hi All,
I will try abstain from using any toilet humour in this post (I dont know why as thats the only sort I know). But I was looking for a way of scripting a batch file that will look at the contents of files and remove a line from it. The files were htm files so the added issue would be that the file extention could be htm and html.
I knew you could not scan contents of files from the command line natively so I began a bit of googling. After a while I came across this extremely handy tool which can scan inside files.
Its called F.A.R.T (thats Find And Replace Text to you) LINK HERE
Its a small exe that you can download and add to your scripting. it allows you to find and replace text from within any file and also crucially for me to remove text from the file.
So for me the script I wrote went a little something like this:
c:
cd\
cd “%userprofile%\LOCATION”
\\SERVER\SHARE\fart.exe -V -r -Remove *.* “text to search for”
exit
Basic but it worked a treat and saved alot of manual work for a few members of the team!
Usage: FART [options] [--] <wildcard>[,...] [find_string] [replace_string]
Options:
-h --help Show this help message (ignores other options)
-q --quiet Suppress output to stdio / stderr
-V --verbose Show more information
-r --recursive Process sub-folders recursively
-c --count Only show filenames, match counts and totals
-i --ignore-case Case insensitive text comparison
-v --invert Print lines NOT containing the find string
-n --line-number Print line number before each line (1-based)
-w --word Match whole word (uses C syntax, like grep)
-f --filename Find (and replace) filename instead of contents
-B --binary Also search (and replace) in binary files (CAUTION)
-C --c-style Allow C-style extended characters (\xFF\0\t\n\r\\ etc.)
--cvs Skip cvs dirs; execute "cvs edit" before changing files
-a --adapt Adapt the case of replace_string to found string
-b --backup Make a backup of each changed file
-p --preview Do not change the files but print the changes
Local printing through MSTSC from a Citrix Xenapp 6 Fundamentals Server
0
If you have published mstsc as an application and then also wanted local printing to work you would have more than likely come across a slight issue. The issue being that no printers are mapped due to the mstsc target not knowing about the Citrix universal printing driver (CUP).
Now the CUP driver is not really a driver as such so you cannot simply locate it and install it on the mstsc target (if only it were that simple). But If you really need to use MSTSC and local printing then you need to disable CUP and manage printing in a slightly modified old skool way.
I’ve only found this method out due to my own fiddling and it works on our current set up but obviously it may be the cure for all instances of this problem or it may cure only ours, (if you read this and try it out then feedback on its result would be great).
Firstly you have to disable CUP on the xenapp server to do that open up the LGPO tool (gpedit.msc) on the xenapp server. You will notice that it has a couple of different entries than you would normally expect to see. Click on the Citrix Policies under User Configuration and click on the Settings Tab. Scroll down top Printing\Universal Printing and click Add on the Universal Printing Setting. Then edit the setting to say “use only printer model specific drivers”. I’ve blogged about setting this previously but the bare bones of the instructions still apply.
After you have set the driver usage then reboot the server for the changes to take effect. The next bit is the bit that had me scratching my head for a while.
There are 3 links in the chain for the drivers to correctly map. Client/xenapp/ts target
Firstly the client must have the driver installed (kind of obvious)
Secondly the Xenapp server must have the same driver installed, if you can get at the clients installation media then alls the better otherwise download it from the usual sources. Now the xenapp server needs to have the x64 driver installed and not the 32 bit (because server 2k8 R2 is x64 only), It does not make any difference to have both installed but I’ve found installing the x64 driver is the required bit!
The TS target also needs to have the driver installed (whatever is suitable for the targets platform be it 32/64 bit. Once all three of these are catered for then printing should map correctly and work as expected.
Now if you’ve managed TS printing for any length of time then you will be aware that for drivers to work the drivers must have the same name, so if you goto the printers and faxes control panel applet then goto file/server properties the actual name of the driver is the same across all the three steps (So do not get confused with the name of the logical printer object the servers do not need to have logical printers created for each driver you add).
Disabling Citrix Universal Print Driver in Xenapp 6 Fundamentals
0I needed to disable CUP in our environment because we use Terminal Servers for most user desktops and it was not really viable to install all the normal software the users use onto the xenapp server. Also if you publish Remote Desktop (mstsc.exe) as an application through xenapp you will more than likely find that remote printing fails to work as the TS server has no knowledge of the CUP driver and there is no way of installing it onto any server other than the xenapp server/s you have on your site.
In order to disable universal printing logon to your xenapp server and run gpedit.msc. You will now notice that there are citrix policy nodes under computer and user configuration policies.
Click on the Citrix Policies under User Configuration and click on the Settings Tab. Scroll down top Printing\Universal Printing and click Add on the Universal Printing Setting. Then edit the setting to say “use only printer model specific drivers”.
Reboot the server and you should now notice that it no longer uses CUP, although you now have the fun and games of loading printer drivers and testing them, but it is a way round printing through an MSTSC published application.
Using Powershell to install roles
0So, you’ve got your server 2k8 R2 installed as a base installation and you want to install a few roles onto it. You can use powershell to do this.
I know your asking “why when I can go through a few menus and its done”, humour me and it may save you some time.
To work with roles and powershell you will need to open powershell (duh). Before you can actually start tapping out the commands for installing services you will need to enable the modules within powershell.
So to begin with you will need to type:
import-module Servermanager
After you have completed that you can then type:
Get-windowsfeature
Which will output a rather verbose list of roles and features that can be installed onto a server 2008 R2 box (already installed roles will be documented with an [X]). For a more sensible list that you can reference I would use the command:
Get-Windowsfeature > c:\features.txt
Which would write the contents of the output into the features file on the C drive which I find easier to work with.
now the important bit installing features with powershell. You can install roles and features listed in the output given in the above command by typing add-windowsfeature “Name” where the “Name” you should replace it with the Name (note not Display Name) of the feature you wish to install.
You can test the predicted result of an installation of a role or feature by using the -whatif command for example add-Windowsfeature “Name” -whatif would run a simulated installation and produce a hopefully positive outcome, Its also quite handy for finding out if the server will need a reboot for the role so you can find out beforehand what you need to schedule in.
Now all this is fairly academic until you maybe starting thinking about multiple servers what if you were in a large organisation or just somewhere that bought a few servers, clicking through menus X amount of times suddenly seems a bit of a drag. So what you have got above is the ability to script role and feature installs in your servers. So for instance if you wrote the below in a txt file and called it something.ps1 then you could push it out to the brand new servers and have the roles auto install for you.
import-module Servermanager
Add-Windowsfeature “Name”
You could also add -restart after the role to restart the computer if it needs to after the role has installed.
You could save yourself a good bit of time when you have set this up correctly. Because its powershell you will have to allow powershell scripts to run which you can do by typing “set-executionpolicy unrestricted” which of course I would recommend you change back after the scripts you want to run have completed.
With a combination of scripts and your favourite distribution method you could shorten the time it takes to install the roles quite considerably thus giving you more time for Angry Birds which of course is always appreciated!
Free alternatives to office communicator server OCS
0Hi all,
Its no secret that I’m platform agnostic when it comes to deploying new systems and services so when we need something at work I’ll look at the open source alternatives to the standard products to see what’s about.
At the moment I’m thinking about deploying an instant messaging service as we have branch offices popping up all over the place and it would be a good way of reducing telephony bills.
Now MS obviously have their OCS system which we could use, but I have also found a couple of GPL alternatives, Both have nice easy windows installers both for the server and client.
One is Openfire which is the server element and Spark is the messenger client. The other is called OfficeSIP and the messenger client is OfficeSIP messenger.
At this stage of the trialling both install nice and easily with no issues and both integrate with active directory.
For me I think the spark client looks better and is easier to use where OfficeSIP messenger is more functional based. For example when you type out a message to someone in OfficeSIP you have to physically press the send button to send the message, call me lazy but I would like to just smash the enter key to send my message.
Both support voice/video messaging (in spark with the help of a red5 plugin), but voice/video appears hit and miss sometimes it will work in the spark client where as it seems rather solid in officesip, and whilst I dont think at this time it will be a used a great deal I dont fancy trying to fix flakey voice/video comms.
Both again have a SSO (single Sign On) element to them if you are logged into an AD account when launching the messengers.
I’m still testing the products and whilst I have no doubt that they will both just work in regards to the instant messaging its the voice/video and other bells and whistles I need to test further to ensure my support calls for the eventual winning stay at an acceptable level.
The death of IPv4
0Well, no not really but I though you may be interested in a couple of videos that I have. I was lucky enough to watch the closing ceremony live where the last 5 blocks of /8 IPv4 addresses were handed out to the respective ISP’s. The addresses are predicted to be used by the end of 2011. This means the transition to IPv6 should pick up steam. This obviously only affects public IP’s and there is no real need to worry too much about your internal IP infrastructure just yet though.
Anyway heres a few snippets of the closing ceremony and also a rather amusing song about the end of IPv4!
Resolving Xenapp 6 fundamental's installation failures
1Xenapp 6 seems to be a tricky little customer to install, when following the instructions from the administrators guide I was receiving random failures but all pointing me to helpfully look into a certain %userprofile% directory in order to view the details. The log file always contained nothing but the most generic of information that really is not of any help.
Then I discovered something. the administrators guide “lies” it says that xenapp will look for missing components and install them as needed (except .net 3.5 which was a pre-req) but it does not.
If your xenapp is on a VM, make liberal use of snapshotting ( i did this before installing any roles just to make sure). So in order to install “xenapp 6 fun” you will need to do the following:
1/ Build a clean server 2008 R2 server and DO NOT INSTALL ANY UPDATES (I included av into my fix just to make sure).
2/ Add to AD and create a xenapp service user account
3/ Add the following roles.
4/ .net 3.5 (application server)
5/ IIS 7 (web server)
6/ Remote session host and licensing server (RDP)
7/ then run the xenapp setup program as administrator, you should be able to install it without any issues. If something goes wrong revert you vm snapshot back to the point before you installed any roles (so you have basically a clean new server without having to reinstall the OS).
After the install has completed and you have set up xenapp as you would like it, create another snapshot and start installing AV and updates, check xenapp for functionality at each update to make sure nothing bad happens (if it does just revert to previous snap shot and don’t install that update).
Remotely Wiping Iphone Exchange accounts
0With the proliferation of the jesusphone and related pad, more and more people want to connect they devices to their work email accounts this can be done very simply through the apple devices. However it can be a little hard to track the spread of such devices in small companies. There is a handy little Exchange shell command you can use in order to discover what devices are connected to your exchange server.
The shell command is “Export-ActiveSyncLog” which creates a series of csv files one of which users.csv holds the data on connected devices. By default the command would look like this:
Export-ActiveSynclog –filename c:\windows\system32\logfiles\w3svc*\exYYMMDD.log –outputpath “output path req”
The above command assumes that your IIS log files are in the default location and you will need to substitute the w3svc* with whatever is relevant within your setup.
This will create 6 csv files and if you open the users.csv it will list the connected activesync devices and what they are.
Now the one problem I have with iphones etc is that there appears to be no way of totally trashing the device remotely like you can with blackberries, however you can remotely wipe the corporate email account from the device by performing the below:
1: Open the Exchange Management Console
2: Expand the Recipient Configuration node and click on the Mailbox subheading.
3: Single click the user in question and in the pane on the right hand side of the console select Manage Mobile Devices (this option is not available if the user does not have a device registered).
4: You will have two options in this screen firstly select the correct lost device (if there is more than one associated with the user) and check the “Perform a remote wipe to clear mobile device data”
5: The information in the same screen will tell you when the wipe was requested (i.e. when you pressed the button) and also when the device received the remote wipe request (Acknowledge).
6: Once the remote wipe has been performed you will need to go through the above again and select “Remove mobile device partnership” when you get to step 4 otherwise the device will be continually wiped when the user goes through setting up the account again should they find the device down the back of the sofa etc.
Setting global calendar permissions in exchange 2007
0I’m finding exchange 2007 a strange beast to work with, coming from a groupwise environment some seemingly simple tasks need a good deal of fiddling to get just so. Why NTFS permissions are not all throughout exchange 2007 I’ll never know but hey ho onwards to my point.
I was asked to set up exchange so that everyone had read only access to everyone else’s calendar. so after a bit of searching around the exchange console I discovered that it was not possible to do this from the native exchange tools (go figure)!
I cam across this tool PFDAVADMIN, which will allow among other things the global setting of calendar permissions.
Now because its christmas and I’m feeling lazy I shall not bother writing how to use it to set the permissions only point you to THIS blog which lays out the instructions rather nicely I feel.
TTFN
£99 vmware lab offer
0Hi all,
I thought i’d alert you to a deal doing the rounds at the moment which HP are running, they are offering an HP proliant microserver at £199 with £100 cashback (making the server £99). The offer can be found here and the server is supplied with a 160GB hard disk 1GB ram and an Athlon 1300 processor and gigabit networking. Now obviously its not the most highly specced out of the box, but it does come with 4 sata connections and hardware support for RAID 0,1 which means that this could be a nice little vsphere lab server with little extra work, or you could stick freenas (or your own favourite media server OS) on it and have a nice small media server.
This deal runs to near the end of this year 2010 so hurry and snap one or two up.

Recent Comments