Free Space on Remote Disks

September 27, 2007

To view the list of logical disks on a remote PC, you can use the Get-WMIObject commandlet passing the Win32_LogicalDisk parameter.

I needed to get information on specific disks on a specific server, so I knew which computer name and DeviceID to look for:

$remoteserver = "remotepc.localnetwork.com"

$filter = "DeviceID='C:' or DeviceID='E:'"

get-wmiobject -computer $remoteserver -class Win32_LogicalDisk -filter $filter |

    format-table `

        @{Expression={ $_.DeviceID }; Label="Drive"; Width=8},

        @{Expression={ [Math]::Truncate($_.Size / 1gb) }; Label ="Size GB"; Width=8},

        @{Expression={ [Math]::Truncate($_.FreeSpace / 1gb) }; Label="Free GB"; Width=8},

        @{Expression={ [Math]::Truncate(100 * $_.FreeSpace / $_.Size) }; Label="% Free"; Width=8}

These few lines of code give me the drive letter, drive size and free space in gigabytes, and percentage free space.

Of course, you can find quite many different solutions, like this one, a script that you can invoke with parameters.


Add reference to your brand-new assembly in Visual Studio

September 19, 2007

Today I downloaded FreeImage, and compiled the .Net wrapper project so that I can call the library from my C# project. Instead of referencing the wrapper project, I wanted to reference the assembly that the wrapper project generates.

Two problems to be solved:

  • You can only register an assembly in the GAC if it has a strongname. To create it, either use the sn tool, or active the project setting to generate the key.
  • Even after registering using gacutil, the assembly would not show up in the Add Reference dialog.

There are at least two solutions to the second problem:

  • Create a registry key (HKLM or HKCU) to point to a directory which contains all the assemblies you need to reference (MSKB, VS reference
  • Copy your assemblies to the PublicAssemblies directory located under the VS home directory (described here, replace with actual install directory)

Managing ASP.Net connection strings with Powershell (1)

September 13, 2007

I came across a problem today while testing an ASP.Net application I am developing.

On my development machine, the web.config files reference both the development and the production database.

When I program a new feature into the application, I use the development database. However, to test a new feature against current database values, I have to manually switch the connection names in the application’s web.config file.

Well, I thought that could be solved by a small tool which would not take long to write.

Read the rest of this entry »