Get-ServerNames.ps1

Posted on September 28th, 2007 in Active Directory, PowerShell, Server Management by Tom

Here’s the script I metioned a few days ago. I wrote this a while back (Pre-RC0, I think).

 Anyway, if you’ve got a bunch of servers that you need to perform a common task on (copy files, check event logs, etc), this is handy…however, it only works if you’ve got the Managed By field set in AD. Otherwise, you’re SOL. First, it makes sure the account name given exists in AD, then searches AD for and computer objects managed by that account. It uses write-output to return the list of servers. It outputs strings, not objects, since that’s all I needed out of it.

Syntax is: .\get-servernames.ps1 <samaccountname>
$root = new-object DirectoryServices.DirectoryEntry 'LDAP://dc=foo,dc=bar,dc=com'
$searcher = new-object DirectoryServices.DirectorySearcher
$searcher.SearchRoot = $root
$searcher.Filter = "(samaccountname=$($args[0]))"
$results = $searcher.findOne()
if ($results -eq $null) {
 write-host -fore 'blue' -back 'white' "`"$($args[0])`" not found"
 exit(1)
}
else {
 $dn = $results.GetDirectoryEntry().distinguishedname
 $searcher.Filter = "(&amp;(samaccounttype=805306369)(managedby=$($dn)))"
 $servers = $searcher.FindAll()
  if ($($servers.count) -gt 0) {
   foreach ($server in $servers) { write-output "$($server.GetDirectoryEntry().cn)" }
 }
}

As I mentioned, this is pretty handy for copying files to groups of servers, checking error logs via psloglist, doing inventory, and more.

PowerShell Script for Server Hardware Updates

Posted on September 25th, 2007 in PowerShell, Server Management by Tom

No. This script doesn’t do the updates for you, as awesome as that would be. I have a bunch of boxes that I have to do firmware updates on tonight. Apparently the Dell PERC4 has an issue on a certain firmware revision that will cause arrays of 5 or more disks in RAID 5 or 50 to fail during rebuild after replacing a failed disk (and I have a disk to replace). My array isn’t 5 disks but I’m playing it safe, as this is a production server. So, I thought “I don’t want to have to hit this from a file share tonight, or have to copy it tonight…” Go go lazy powers. I wanted to copy this to all of my DELL boxes, but not the VMs or HP machines. Enter, PowerShell.

 .\get-servernames.ps1 <samname>
  | foreach {
      if ((get-wmiobject -computer $_ win32_computersystem).manufacturer -contains “*Dell*”) {
         copy-item c:\SUU \\$_\c$\suu -recurse -force
    }
}

More on get-servernames.ps1 later. But, now my SUU is on all of the servers and waiting for me tonight. I kicked it off and went home. And excuse the formatting, the layout is a work in progress!

Moving Microsoft BizTalk Server 2006 Databases to a new SQL Server

Posted on September 6th, 2007 in SQL Server by Tom

So, for whatever reason you need to move your BizTalk databases from one SQL server to another. In my case, I was moving from a hostname to a CNAME, for DR purposes (failover server is in another DC, and not clustered).

In the event of a disaster, we could just fail over to the other database server, change the CNAME to point to the “failover” server, and we should be back up and running. The problem, I found, was changing from DC1BTSQL1 to the CNAME (we’ll call it BTSQL1). After searching for a while (maybe I’m an idiot, but all of these things were classified as “backup and restore methods” not “I’m changing server name” methods or anything like that) I found two scripts and an xml file.

Under %systemdrive%\Program Files\Microsoft Biztalk Server 2006\Schema\Restore are two VBS scripts. UpdateDatabase.vbs and UpdateRegistry.vbs. There’s also an XML file called “SampleUpdateInfo.xml.” Below is the procedure for changing the SQL server name. You can even change the names of the DBs. This procudure assumes you’ve backed up and restored, or attached, the DBs to the “new” server already.

More…

Hello World

Posted on September 4th, 2007 in Uncategorized by Tom

So, here it is. My “IT Stuff” blog. Here, I’ll pretend to be a writer AND pretend to know what I’m talking about…maybe I can help some people out along the way.

By trade, I’m a server engineer…specifically Microsoft products ranging from Server 2003, SQL Server 2005, BizTalk Server 2006, IIS, and more.

PowerShell rocks. I find myself writing scripts in Powershell just because it’s so much easier than anything else out there. I used to use a lot of VBScript (which I still find myself using from time to time, due to a scheduling platform we use at work), but once PoSH arrived, I became hooked (back when it was Monad). You’ll notice a lot of PowerShell scripts and posts…it’s probably my favorite “thing” out there right now…as far as work type stuff goes.

There is, of course, the “out of office” stuff. I’ve got 3 machines at home. Two of them are running Vista Ultimate. One is my Media Center PC and the other is my “main” machine. I built that in May…it’s mostly for gaming and surfing the web. Occasionally, I’ll get an idea in my head and do some coding/scripting. My 3rd machine is a Dell Precision (dual 1.7ghz Xeons) running Server 2003…there’s also my company laptop, which is running Vista Enterprise. Outside of computer stuff is car stuff. I’m sure I’ll squeak in some posts on the car…

Look for more very soon.