PowerShell Object Tutorial

Windows PowershellCreating objects in PowerShell is… strange, to put it lightly–down right awful if you want to be realistic. But even if the syntax is terrible, objects are still nice to use. Here’s a quick primer on how to create and use an object in PowerShell.

Creating a New Object

First let’s create an object using New-Object.

PS > $myObj = New-Object Object

Continue reading

How to Fix “Could not connect to the feed specified” with NuGet and TeamCity

When using NuGet 1.7 with TeamCity 7, I was receiving an error in the NuGet GUI when trying to connect to our NuGet feed. The error in Visual Studio looked like this:

Could not connect to the feed specified at '$the-server/app/nuget/v1/FeedService.svc'. Please verify the package
source (located in the Package Manager Settings) is valid and ensure your network connectivity.

The solution

This is a confirmed bug in NuGet 1.7, as seen in both this NuGet bug report (2066) and this TeamCity bug report (21011). To fix the problem you need to download a newer version of NuGet that contains the bug fix.

NuGet 1.8

As of this blog post NuGet 1.8 isn’t released, but it should be released soon; try updating your plugin to the latest stable version to see if your problem is resolved.

Update: NuGet 1.8 has been released! Upgrade using the Visual Studio Extension Manager or download it here!

Nightly builds

If the latest stable build doesn’t resolve your issue, you can download a nightly build from NuGet’s CI server.
1. Go to NuGet’s CI server
2. Click the link at the bottom to log in as a guest
3. Under the NuGet section you’ll see a couple of options (currently 1.8 and Default)
4. Mouse over the Artifacts link for whichever build you choose (I chose to download a 1.8 build), click VisualStudioAddIn and then NuGet.Tools.vsix
5. Your download should start; let it finish
6. Probably best to close any open Visual Studio instances
7. Run the vsix installer by double-clicking it

Your new NuGet extension should now be installed and your TeamCity feed URL should now work!

Enjoy NuGetting!

How to Fix Errors with the PowerShell WebAdministration Module

Windows PowershellThe PowerShell WebAdministration module can be finicky. If you’re seeing COMException error messages, here are a few things you could try.

WebAdministration Errors

If you import the module using the 32-bit version of PowerShell, you might see the following.

PS > Import-Module WebAdministration
PS > Get-Website
Get-Website : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed
  due to the following error: 80040154.
At line:1 char:12
+ Get-Website < <<<
    + CategoryInfo          : NotSpecified: (:) [Get-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetWebsite
   Command

If you import the module using the 64-bit version of PowerShell, you might see this error.

PS > Import-Module WebAdministration
PS > Get-Website
format-default : Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    + CategoryInfo          : NotSpecified: (:) [format-default], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.FormatDefaultCommand

Continue reading

Examining and Recursing Objects in PowerShell

Windows PowershellI’m still somewhat new to PowerShell and all the time I find myself wanting to examine objects to see what properties and methods they have available. The documentation on MSDN and around the web is pretty good, but there are still plenty of situations where it’s just easier or better to ask PowerShell to help you out instead. For instance, when you’re using a third-party module that’s sparsely documented you might want to just examine its objects. Or maybe you just don’t feel like going to Google. Either way, here’s a bunch of ways you can get a better look at an object in PowerShell.

Continue reading