Welcome to MSDN Blogs Sign in | Join | Help

powershell script - find orphaned C# files

I ran across a C# file that had been removed from its csproj file, but it hadn't been deleted from version control.  So I wrote a script (Chris Sidi had already written one, though) to find the .cs files that weren't in the "containing" .csproj file

 

param([string]$csproj = $(throw 'csproj file is required'))

$csproj = Resolve-Path $csproj
$dir = Split-Path $csproj

# get the files that are included in compilation
$xml = [xml](Get-Content $csproj)
$files_from_csproj = $xml.project.itemgroup | 
	%{ $_.Compile } | 
	%{ $_.Include } |
	?{ $_ } | 
	%{ Join-Path $dir $_ } |
	Sort-Object

# get the files from the dir
$files_from_dir = Get-ChildItem $dir -Recurse -Filter *.cs |
	%{ $_.FullName } |
	Sort-Object
	
Compare-Object $files_from_csproj $files_from_dir
Posted by jmanning | 3 Comments

macro to "organize usings" for a project

I won't claim this is efficient, or well-written, or whatever, but it WorksForMe and I figured I'd share.  Feel free to post better versions in the comments or on your own blog and add a link as a comment :)

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module RemoveAndSortModule
    Sub RemoveAndSortAll()
        IterateFiles()
    End Sub

    Private Sub IterateFiles()
        Dim project As Project
        Dim projectObjects As Object()
        Dim window As Window
        Dim target As Object

        window = DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
        projectObjects = DTE.ActiveSolutionProjects
        If projectObjects.Length = 0 Then
            Exit Sub
        End If
        project = DTE.ActiveSolutionProjects(0)
        RemoveAndSortFiles(project.ProjectItems())
    End Sub

    Private Sub RemoveAndSortFiles(ByVal items)
        Dim file As ProjectItem
        For Each file In items
            DTE.ExecuteCommand("View.SolutionExplorer")
            If file.Name.EndsWith(".cs") Then
                file.Open()
                file.Document.Activate()
                DTE.ExecuteCommand("View.ViewCode")

                DTE.ExecuteCommand("Edit.RemoveAndSort")

                file.Document.Save()
                file.Document.Close()
            End If
            If file.ProjectItems().Count > 0 Then
                RemoveAndSortFiles(file.ProjectItems())
            End If
        Next
    End Sub
End Module
Posted by jmanning | 1 Comments

Enterprise Edition

What's your favorite?

 

Chris Rathjen‎‎ [9:05 AM]:

i take it you want enterprise?

‎‎James Manning‎‎ [9:05 AM]:

NCC-1701 *D* please

‎‎Chris Rathjen‎‎ [9:05 AM]:

dude the E kicks the D's ass

‎‎James Manning‎‎ [9:06 AM]:

yeah, it does

but D has more sentimental value to me

‎‎Chris Rathjen‎‎ [9:06 AM]:

true true

Posted by jmanning | 1 Comments

collection and property initializers are so nice

I happened to change a piece of code over the weekend and used both.  It's a tiny piece of code, so I thought it would make a good example of just how much readable code is using them.

Before:

List<Property> p = new List<Property>(1);
Property pr = new Property();
pr.Name = "Description";
pr.Value = Description;
p.Add(pr);

After:

List<Property> properties = new List<Property>()
{
    new Property() { Name = "Description", Value = Description },
};

Ah, much nicer.  (Yes, technically the second doesn't get the list size set to 1 like the first does, but I consider that a micro-optimization in the first place).

Remember, focus on making code easier to *read*, not easier to write.  That's one of the reasons I don't use "var" above, even though it causes a DRY failure - I like not having to read past the "=" to get the type.  Also, I like not having some locals that have the type out front and some that don't.  However, that's really for a different post, so nevermind. :)

Posted by jmanning | 1 Comments

Hyper-V has shipped!

http://www.microsoft.com/hyper-v

Many people on our team (including myself, of course) have been running pre-RTM bits (the beta that came with Windows Server 2008, RC0, RC1, and their escrow build), and we've been extremely happy with it.  It's light-years ahead of Virtual PC / Virtual Server.  I've already consolidated 4 of my previous machines down to 1 physical box, including the machines I do all my day-to-day development (now a VM of 4 procs and 2GB) and testing (now a VM of 2 procs and 1GB) with.

As I've been telling my co-workers who ask whether they should use it or not: it's ridiculously good.  If you have WS08, do yourself a favor and get it, use it - LOVE IT!

Posted by jmanning | 0 Comments

THE PowerShell book (Windows PowerShell in Action, Bruce Payette's book) now on Safari!

Just noticed in an email from Bruce that his book is now available on Safari!  Yay!

Posted by jmanning | 1 Comments

Another James loss == another customer win

For those keeping score, last time it was Windows Server 2008.

For various reasons (that I won't bother reiterating here, since there's no value in doing so), I wanted to make our next release 64-bit-only.  There's a little bit of precedence in that Exchange 2007 had already done so, and the way we're currently thinking about upgrade recommendations (a post for a different time) would keep it from being painful in the majority of (but not all) situations.

Thankfully for our customers, that got shot down and our upcoming release is currently slated (plans change, nothing's nailed down, etc) to be supported on both 32-bit and 64-bit.  More work and more testing for us, yes, but good news for customers, especially those that wanted to do in-place upgrades from Orcas (on an OS of 32-bit 2k3).

Posted by jmanning | 1 Comments

HashTab - easily see the hashes for files

While wanting to verify the hash of a dd-wrt firmware I downloaded, I read about this app called HashTab that makes it a simple shell extension.  What a great idea!  The license agreement phase of the install states it simply enough:

image

I love that you have to click "I Agree" to that statement :)

Now the properties for the file included its hashes :)

image

Those are just the hashes that are enabled by default, it has many more available!  Here's the set of hashes from the same file when I turned them all on :)

CRC32: D7D7D0DE
HAVAL: FE69E1E152A34B6280F6C7F0E4ED4A07537B590DF50D6F011B60CED313CBF7A5
MD2: 458B0DCCA172D4029773A54C52BF121F
MD4: ADF1D24F7EBA0C45DD0E51322C906B4C
MD5: FEE2396286CCCE8D2FE9F276A78B9959
RIPEMD-128: 749C8EB8AA787C9BD172BB4BEE04FF6A
RIPEMD-256: 5F4354343BF96290D20576C169CDA6774A5F7663765FA48C3D8D89C25D5BC4BE
RIPEMD-320: 26C0FC8BB03AE1C7CFA10318BD9645B240D6AECE5EB279A5B5869CE043DB5FA7950593C49FC68F03
SHA-1: B3879302048EC43738DED8A186D948B73DDDB5FE
SHA-512: D6984C3CB28FFD51E2BFA612605504A0739AD651296129FA31FDB160A787BF0B6C39C226E673F0AA95024F891971C7E49ED3F8482060C2C82B6FE61CD6F1C25A
Tiger: 27EB3BAF4CA4EE25425480CCD4CD30CE9983CB5836D98C4B
Whirlpool: BBC6D5B1CD4D4427DA556B53AB7DA7F0608CEAACA1C2BD6540695ABBFADF6FC9362A821573203973B8C85EE69073419AD5F7AEE447A060F045E6FDE4E4F48DF1

Most importantly for me, of course, that matched the hash in the md5sums file:

http://www.dd-wrt.com/dd-wrtv3/dd-wrt/downloads.html

fee2396286ccce8d2fe9f276a78b9959  ./dd-wrt.v23 SP2/mini/dd-wrt.v23_mini_generic.bin
Posted by jmanning | 2 Comments

Odd Server 2008 link speed issue

Despite having a 1 Gbps Intel network card plugged into a 100Mbps switch, my Link Speed claims 10Gbps.  So, while I'm pushing 75Mbps of traffic (copying the vhd file as per previous blog post), it claims a network utilization of 0.75% instead of 75%.

image

Other co-workers (that happen to have the same kind of machine/card) have also seen this issue, so perhaps it's just an issue with that card's 2008 driver or something.

Maybe it even has to do with the virtual network I have set up for use in HyperV.  That seems far less likely, I admit.

image

Posted by jmanning | 0 Comments

Giving full trust to a network share

Tan's post reminded me that I never got around to posting this silly batch script that I use.  As you can see with Tan's example, you can call this with just a hostname, or hostname/sharename, or whatever. 

For both of us, we're ripping off Shawn's original blog post on the topic that gives more details on the command's parameters.

C:\ # gcm fulltrustserver|cat
@echo off
setlocal

pushd %Systemroot%\Microsoft.NET\Framework
for /r /d %%d IN (v*) do (
    if exist %%d\caspol.exe (
        %%d\caspol.exe -q -m -ag 1.2 -url file://%1/* FullTrust
        echo Successful caspol run in %%d
        set FOUND=1
    )
)
popd

if not defined FOUND (
    echo FAILED TO FIND CASPOL.EXE
    exit /b 1
) else (
    exit /b 0
)
C:\ #

Sorry for the total lack of creativity in the subject, copy-pasting Tan's is too easy for my lazy self. :)

Posted by jmanning | 0 Comments

Screenshot-fest: Using SCVMM 2008 Beta to convert my old Vista dev box into a Virtual Machine

While you can certainly use Vista's Complete PC Backup to generate a vhd of your machine, it doesn't make a bootable, usable virtual machine.  I didn't want to lose a bunch of things on my old dev box (I need to reinstall it with Windows Server 2008), but having "just" the vhd for mounting and copying files I forgot that I needed wasn't as nice as having my old dev box magically transform into a virtual machine that I could boot and continue to use.

SCVMM's (System Center Virtual Machine Manager) existing released version (2007) can handle doing a physical-to-virtual (p2v) conversion on most downlevel (pre-Vista) OS's, but it can't handle doing so on Vista.  However, their 2008 Beta can, so that's what I installed.

As per the System Requirements, you'll need 64-bit Server 2008 machine.  I created a 64-bit Server 2008 VPC for running SCVMM (both Server and Admin Console).  For the actual "host" (target place where the virtual machine will be created), I chose a co-worker's HyperV-running Longhorn box.  I had to do this since my own HyperV was already upgraded to RC1, but the SCVMM 2008 Beta only supports HyperV RC0, which has machine (nawien-pc) was running.  I could have run Virtual Server inside the virtual machine and made that the target, but it was faster to just use his existing server.

As a summary, here's the hosts/pieces are involved:

  • jmanning-devold: physical Vista machine, my old dev box
  • jmanning-lhs64: virtual Server 2008 machine (under my own HyperV RC1 box), includes SCVMM 2008 Beta (both Admin Console and Server)
  • nawien-pc: physical Server 2008 machine, includes HyperV RC0 (where the virtual version of jmanning-devold will be created)

Starting off: once you have SCVMM 2008 Beta installed, you can choose the "Convert physical server" action to start your conversion (note: the "server" part of that may be confusing, but it converts workstation/client OS's fine as well :)

image

This let me know that I first needed to add a host (target where the virtual machine will be created).  As mentioned above, I could have used Virtual Server as well, even inside a virtual machine, but I used Hyper-V instead.

image

So, I go to add a host:

image

I use my own credentials in order to connect to the target machine:

image

Just to give it a shot, knowing it's stated as not supported, I try my own HyperV machine which is running RC1.  It finds it fine, but when actually trying to do the conversion, it fails.  That's expected since RC1 isn't supported, but at least I know now that for this beta, you really do need RC0.

image

image

So, I remove that host and switch over instead to using my co-worker's instance.  Adding it looks much like the above, of course.  I'll spare you the additional screen shots. :)

Now, back to the "Convert physical server" action (now that I have a good host added), I select the source machine:

image

I leave myself as the owner for the new virtual machine that will be created and add a description:

image

The next screen says it needs to gather a bunch of information from the source system (my existing Vista box) and will install some software to do so.  That's fine with me, so I click the Gather System Information button:

image

Once it completes, here's the information it displays:

image

It apparently does a quick sanity check to make sure the conversion can run fine, and everything appears to pass those checks:

image

There's only one drive in the source machine, so it's nothing to really change here - I keep the defaults for the VHD-to-be-created parameters:

image .

Now it lets me select the processors and RAM for the target virtual machine.  The defaults appear to match my physical machine (2 procs, 4GB), so I'm guessing that's where they got it from (although it could be coincidence).

image

I don't need that much for this virtual machine, I just need to be able to run it once in awhile, so I knock it down to 1 proc and 0.5 GB

image

Now I select the target machine ("host") for the conversion.  Since I only have one host added at the moment, that makes it a pretty simple choice :)  I like the interfaces, though - it's pretty clear that you could manage fleets of virtual machine hosts pretty easily.

image

It lets me change where the files are written to on the target machine.  Since I'm going to move these files off of his box and onto mine, I end up putting them in a new dir called "d:\jmanning", but here's the default:

image

Now I can select the virtual network for the target VM.  The default found is fine with me:

 image

Since I'm going to 1) move this VM to my own machine and 2) only use it on occasion, I keep the default of having the VM never turn on automatically.

image

I get a chance to review the settings before the conversion kicks off:

image 

The conversion "job" kicks off in the background.  It's not clear to me what's going on, but I notice the "Jobs" button which brings up the details of this (and previous) jobs:

image

The summary makes it clear that it's cranking away (at this point in the screen shot, it has started copying the hard drive over the network)

image

The Details tab gives lots more information on the process.  I really like that:

  • it includes progress bars for each step
  • It includes start and stop times for each step
  • It shows the hierarchy of actions needed, including where you're at in the process

This is the kind of progress UI I'm hoping we can include for install of TFS in the next version :)

image

The copying of the hard drive ends up taking around 20 hours as you can see by the times for step "1.3" (which is fine with me, I just let it run overnight).  One step of the process failed (installing the VM components), but that's not strictly necessary and the overall conversion completed fine:

image

Connecting to nawien-pc with Server Manager, I see my new virtual machine!  Yay!

image

Sure enough, it starts up and I can login and use it just fine.  Yay!  Now I can move that VM over to my machine and reimage my old Vista box to Server 2008 without losing anything :)

image

Thanks SCVMM!

Posted by jmanning | 1 Comments

You can't run HyperV in a HyperV VM

I didn't think it would work, but I was trying it yesterday because of the OS requirements for SCVMM 2008 Beta.

image

Of course, you can run Virtual PC under Hyper-V (or Virtual Server, or VMWare, or whatever)

Posted by jmanning | 0 Comments

Just-In-Time sysinternals tools!

I'm a few days behind on posting this, but now you can run the current version of sysinternals tools directly from \\live.sysinternals.com\Tools!  If you're in PowerShell, you can just cd over to it, even.  If you don't want to use a UNC path (or can't for some reason), the tools are also available via http at basically the same path.

image

Invariably, my local copy of the sysinternals tools gets out of date, so this is a much better alternative than trying to keep my local "cache" of the tools up to date manually :)  Obviously, you can either add the UNC path directly to your PATH (probably not a great idea due to the latency when it needs to scan it on a typo'd command name), or create a simple alias that will invoke a tool directly from that path.

Here's an explanation straight from the path itself:

PS \\live.sysinternals.com\tools> type About_This_Site.txt
What is this?

This is a file share allowing access to all Sysinternals utilities. We have developed this to test an alternate distribution mechanism for our utilities.

This will allow you to run these tools from any computer connected to the Internet without having to navigate to a webpage, download and extract the zip file.

If you are unfamiliar with Microsoft Windows Sysinternals, it is highly recommended that you visit the website at http://technet.microsoft.com/sysinternals before using these tools.

If you have any questions or comments on this file share, please email syssite@microsoft.com

Regards,

The Microsoft Windows Sysinternals Team

Posted by jmanning | 0 Comments

Brian the Build Bunny ownz those Watership Down rabbits

Maybe I'm the only one, but that movie gave my 6-year-old self quite the nightmares.  I don't think my parents got the memo.

Unlike many animated features, the film faithfully emulated the dark and violent sophistication of the book. As a result, many reviewers took to warning parents that children might find the content highly disturbing.

Anyway, back on topic (me? digress? nevah!) ... hop on over and check out Martin's post unveiling the glory that is BtBB.  The YouTube video is well done and far less likely to cause nightmares :)

Brian is a Nabaztag smart rabbit.  He reads out details of check-ins and builds.  If a build has failed then his ears go down to show how sad he feels, but if you fix the build his ears will soon pick up again.

Posted by jmanning | 0 Comments

How does TFS 2008 pick which Reporting Services instance to use?

One of the painful parts of TFS 2008 install is that you can point (via the msiproperty.ini file) the install at the right machine for your SQL Reporting Services, but not the specific instance on that machine.  It's a bit of a long story as to why that is, but it does lead to the question of "If I have multiple RS instances on the machine I point it to, which one does it pick?"

Here's the logic used:

  • If there are no RS instances on the machine, that's an error (of course)
  • If there's 1 RS instance on the machine, we use that one (of course)
  • If there's more than 1, we look for:
    • If there's one that points to the same DB instance as TFS is being pointed to, we use that one
    • If there's one where the instance name matches the instance name of the database server you pointed to, then we use that one
      • This is useful because many times people will just install all the SQL Server services with an instance name like "TFSINSTANCE", so we Just Work in that case
    • Otherwise, we see if there's a default instance available, and if there is, we use that one
    • Otherwise, we use the first one

There's a good bit of logging in that section of code, so the logs should make it clear what it chose and why.

Posted by jmanning | 1 Comments
More Posts Next page »
 
Page view tracker