Tuesday, January 02, 2007

PowerShell - Delete files based on lastwritetime

One more PowerShell tidbit, then I'm signing off. I just love this shell. I had a need to clean up some old IIS logfiles from a SharePoint portal site, and I wanted to do it by date. I was able, with one command line, remove all 2004 logfiles from the folder with the following command line (split for clarity):

PS> gci -path c:\windows\system32\logfiles\w3svc1
>> where { [datetime]::compare($_.lastwritetime, `
>> [datetime]"1/1/2005") -lt 0 }
>> del
I know, no great shakes in terms of scripting...but there's no really good way to do this from the command shell without resorting to VBScript.

I love this shell!

I guess I'm not a plumber...

Friday morning before New Years, and I'm standing in the kitchen with the faucet lever in my hand…and the lever's no longer attached to the faucet. Crap…

After a brief conversation with the wife (who was visiting family), I picked up a new faucet at Lowe's (liked their selection better than Home Depot) and brought it home. "This'll be pretty straightforward,' I thought. Right.

The old Moen faucet inlets were two copper tubes which were so close to the nut that held the faucet to the sink that I couldn't get any sort of wrench around the nut to loosen it. I tried two different self-adjusting wrenches and a brand new basin wrench for about 40 minutes, and all I managed to do was work up a sweat and bang my hands around under the sink. OK, that's not going to work.

To give myself more room, I pulled the garbage disposal out at this point, which helped some, but I still couldn't quite get in to the nut. For some reason, it took me this long to realize that the faucet was broken anyway, so it really didn't matter if the inlet tubes were broken off or not - so I broke them off. Unfortunately, they snapped just BELOW the bolt, meaning I STILL couldn't get the basin wrench around the nut. But the smaller adjustable was able to get around the nut and after some gyrations under there, I got the damn thing out.

The new Price Pfister faucet went in (as a co-worker would say) "like buttah!". It looks nice and works well.

So, now I had to put the garbage disposal back in.

Attempt 1, Friday afternoon: Damn thing is leaking! OK, it's not seated right on the cuff. Pull it.
Attempt 2, Friday evening: Damn thing is leaking! OK, it looks like it's seated correctly, and it's not leaking as badly…hmmm. Plug the sink and see if it's leaking from the insert or if there really is a problem. Ok, it appears to be the insert, but I'm too damn tired to do this tonight….tomorrow.
Attempt 3, Saturday morning: Yank the whole unit, including the mounting insert, from the sink and start from scratch. Everything installed again and…ok…looks goo…crap! Damn thing is leaking! Maybe there really is a problem...
Attempt 4, Sunday morning: Yanked the whole shebang AGAIN and started parts. Carefully mounted the insert in the sink and took great pains to ensure that the bracket was tightened evenly. Remounted unit on bracket and reconnected everything…looks good…whew!

Three days, and I have my sink back. It looks like the initial problem was when I first remounted the unit, I pushed up on the bracket too hard, damaging the putty seal between the sink and the insert. When I completely reinstalled on Saturday, I didn't take the necessary care to ensure that the insert was evenly tightened, and I screwed up the seal again. Lesson learned. I got frustrated started rushing to get the job finished. I'd done this before and not had problems, so clearly I wasn't part of the problem this time either. Yeah, right...

Wednesday, November 01, 2006

Add SID to local group with WinNT group interface

We're in the midst of a divestiture, and we have a network set aside for testing end-user capability without access to the production environment, including Active Directory. One user moved a few machines into this test environment, expecting that his users would be able to use their cached domain credentials to do what they need to do. He discovered after the fact that he needed to add these users to the local Administrators group. The Computer Management tool won't do it, since it expects to be able to see the domain...and can't.

It turns out that you can use VBScript and the WinNT ADSI interface to do this, assuming you have the SIDs of the groups or users you want to add. Here's the basic script:

strComputer = "."
strGroup="Administrators"
'Replace the SID below with the SID you want to add
strSID = "S-1-5-21-123456789-876543210-345678901-3456"

Set objUser=GetObject("WinNT://" & strSID)
Set objGroup=GetObject("WinNT://" & strComputer & "/" & _
strGroup & "Users,group")

objGroup.Add objUser.ADsPath

Of course, you need to know the SID of the user you want to add. You can get from the local registry by looking through HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList. Or you can download User2SID (and SID2User) from here. Or (if you are adventurous) you can download source code from the author's site here.

Monday, September 04, 2006

Loosing a tooth...

My oldest daughter lost her first tooth (naturally) this week. She's been so excited because her tooth was loose, and wanted to show everyone. She especially liked pushing it so it was sticking almost perpendicular to her gums and grossing her mom out. Now that it's fallen out she has yet another gap in her smile, and it looks really cute. Of course, the tooth fairy came and took the tooth, leaving $1 behind in recompense.

I'm not sure I'm happy about it, as it is one more indication that she's getting older. Every day is exciting and precious and one day nearer the day when she's not my little girl any more. This is one more reminder to cherish and enjoy every moment with my children, because they will never be this young, innocent, and full of wonder again.

Thursday, July 27, 2006

Insanity in the world...

This is f*cking crazy. I can't understand how people who purport to be rational and compassionate aren't outraged by what is happening in Lebanon and Gaza. I can't understand how people aren't outraged by the behavior of their governments. I just don't get it.

How can a civilized people stand by and watch this happen? Are we that insensitive to the suffering of other people? Are we so Machiavellian in our thinking that nearly any means is justified?


I hear foreign ministers spouting rhetoric about the need for a ‘sustainable’ cease fire, which Israel takes as a green light for further violence. I hear Secretary of State Rice say that she is concerned about the humanitarian situation in Lebanon. I see efforts made to get our people out of harm’s way. But we’re not helping, really. Instead, we’re sending more bombs (
http://news.bbc.co.uk/2/hi/uk_news/politics/5221782.stm).

I know, Hezbollah is shooting rockets into Israel. I know, people in Israel are dying too. But look at this from CNN: (http://www.cnn.com/2006/WORLD/meast/07/27/mideast.main/index.html):


Since July 12, at least 405 people -- mostly
civilians -- have been killed in Israeli strikes, Lebanese security sources
said. The IDF said the Israeli death toll is 50 -- 19 of them civilians.
The
fighting also has wounded about 1,660 people in Lebanon and more than 300
civilians in Israel, the sources said.

That’s a death toll ratio of 1 Israeli to 8 Lebanese, and the ratio of wounded is 1 to 5. And notice that more than 50% of the Israeli fatalities have been IDF soldiers, legitimate targets in wartime.

If you aren't disturbed or outraged, take a look at this site:
*WARNING* The following site contains graphic images. If you are squeamish, don't go here. You have been warned. http://www.fromisraeltolebanon.info/

There is a petition (not that I normally endorse these things) at http://epetitions.net/julywar/index.php.

Saturday, July 15, 2006

I hate patching...

Well, another planned 6-hour server patching downtime has turned into 18-hours of pain. The automated tools which we use to apply hotfixes and service packs worked like a charm. Because we reboot servers so infrequently, though, reboots are occasionally frought with danger; and this was no exception.

One server (Win2k) failed boot, showing an error during the text-mode progress bar. The error message was "Loader Error 3", which apparently is often associated with a bad boot sector. The recommended process to address was:

  1. Backup user data (if possible)
  2. Boot to recovery console
  3. Run FIXBOOT
  4. Reboot

This (theoretically) resolves the problem - unless the system registry hive is too large to load in the first 16MB of RAM at boot time (along with the kernel and HAL and core drivers). That was the case here. I've seen this before, but normally we see a corrupted hive error.

Fortunately, we'd seen this before, so we had a base system hive (default from base build with local customizations imported from the 'big' hive) in %windir%\system32\config. Rename the old hive file, rename the new base hive file to system, and reboot. We're good to go.

The other systems are three Win2k3 servers with Citrix MetaFrame XP which all blue-screened with 0xC000021A stop codes on boot after installing SP1. This stop code

Friday, July 14, 2006

Tabula rasa

I'm not sure what I'm going to do with this as yet empty space. As usual, a blank page engenders a blank mind. Perhaps with practice, the emptiness will fill - hopefully with something meaningful.