Posts Tagged ‘PowerShell’

A faster way to output unique objects in PowerShell

August 15, 2012 Leave a comment

Many times – mainly when writing function cmdlets for other purposes – I find that I need to output all unique objects based on one or two properties but want all the objects’ properties returned. PowerShell’s built-in Select-Object doesn’t let me do that. Apart from enumerating and collecting all objects before outputing them to the pipeline, it only return the properties that you specified.

To let all the objects flow through the pipeline as they are enumerating, I added my own Select-Unique cmdlet to my $profile a couple of years ago but wanted to share it now as a Gist.

See the comments on the gist for more information.


Fixing connection issues when is set as the default gateway

May 18, 2009 16 comments

I’ve been happily using various Windows 7 builds for a while now, including the recent release of Windows 7 RC (build 7100). There are many UI improvement that help me be productive – especially on a laptop when not connected to external monitors. The Shell has made significant performance improvements, and while I never found UAC prompts to be an issue I do like that there’s far fewer of them when I’m changing configuration settings while exploring the possibilities.

At home I decided to update our Vista SP1 Media Center to Win7 RC. Almost everything went smoothly except that on boot my machine couldn’t connect to the Internet. When I looked at the Network and Sharing Center, “Unidentified network” showed up. To check my network configuration I dropped into a command prompt and ran “ipconfig /all” only to find that I had a new default gateway address:”. Disabling and re-enabling the NIC fixed the issue until the next reboot.

Then I was pointed at KB970313. It seems there’s a race condition at startup – which also seems to have gained a boost with Win7 – where if the Apply Bonjour service starts before my NIC retrieves settings from my router, the default gateway is added. And while their web page claims, “Thanks to Bonjour technology, getting computers and smart devices to work together is as easy as connecting them”, it had quite the opposite effect for me: no connectivity to the outside world.

If you’re having issues connecting and see “Unidentified network”, fixing the issue is fairly easy: disable the service, then disable and re-enable your NIC. Alternatively you can reboot your machine.

  1. Click on Start.
  2. Type services.msc and press Enter. On Vista you may need to confirm the UAC prompt.
  3. Find the Bonjour service. This may be tricky since it’s open source and may not display the same. But you can check suspected services for the typical path “C:\Program Files\Bonjour\mdnsresponder.exe”.
  4. Right click on the service and select Properties.
  5. Change the Startup type to Disabled.
  6. Click the Stop button. You can then close the Services window.
  7. Reboot the machine.

But what installed it? A disabled service begs the question, why even have it installed?

While perhaps not as impressive as Process Monitor, I have my own set of tools I’ve been working on occasionally. The Windows Installer PowerShell Module exposes Windows Installer APIs to PowerShell. By combining a few cmdlets I can examine objects through a pipeline to find what product installed “C:\Program Files\Bonjour\mdnsresponder.exe”.

PS> get-wicomponentinfo | where { $_.path -ieq 'C:\Program Files\Bonjour\mDNSResponder.exe'} | get-wiproductinfo

ProductCode                            ProductVersion      ProductName
———–                            ————–      ———–
{D0DFF92A-492E-4C40-B862-A74A173C25C5} 3.0                 Adobe Version Cue CS3 Client

Unfortunately I can’t remove the product without breaking the Photoshop CS3, but having disabled the service I shouldn’t have to worry about not being able to connect to the Internet.