new-blogentry -topic "Powershell and More"

My observations about Powershell, Windows, System Center and life.

Recent comments

Tags

Don't show

    Disclaimer

    Any opinions expressed herein are completely accidental. But if one happens to slip in, it represents my own personal opinion and NO one elses. I'm also not concerned with changing anyone elses opinion, so any rants about anything presented on this site are likely to be 100% ignored.

    © Copyright 2010

    Missing 64 bit native commands in Powershell (x86)?

    For those using a x64 Windows OS, you may find that many times you still need to use the x86 version of Powershell due to snapin compatibilities. Have you ever noticed that a number of native (dos/command prompt) commands are only available as 64 bit EXEs and not immediately available from your x86 Powershell session? Some examples are nbtstat.exe, telnet.exe, tscon.exe, tsdiscon.exe, and query.exe. Somewhat annoying.

    I’m not going to go into details about all the fun of API call thunking or Windows-On-Windows (WoW), because frankly… I don’t care. I just want to run nbtstat.exe from my x86 version of Powershell!

    Fortunately, there is a way to access these elusive 64 bit EXEs. Add %systemroot%\sysnative to your PATH. Here’s a small snippet you can add to your profile.ps1 that will add this folder to the end of the path for your Powershell session.

    Version 2 Code: (see Version 1 variant below)

    if ( (Test-Path "$($env:systemroot)\sysnative") -and ($env:path -split ';' -notcontains "$($env:systemroot)\sysnative") ) { 
        $env:path = "$($env:path);$($env:systemroot)\sysnative" 
        Write-Host "Path updated to include: $($env:systemroot)\sysnative"
    } 
    

    I added in checks to make sure the sysnative exists (it won’t under a x64 process, only x86 processes) and that it’s not already in the path to avoid duplication.

    One caveat. %systemroot%\sysnative redirection only works on Vista, Windows 2008, or Windows 7. XP and 2003 are a bit in the cold on this one (although there is hotfix KB942589 to add sysnative to Windows 2003 – but I’ve not tested it).

     ** Alexandair pointed out that I used -split operator which requires Powershell v2. The following works in v1 and v2:

    if ( (Test-Path "$($env:systemroot)\sysnative") -and (($env:path).split(';') -notcontains "$($env:systemroot)\sysnative") ) {
        $env:path = "$($env:path);$($env:systemroot)\sysnative"
        Write-Host "Path updated to include: $($env:systemroot)\sysnative"
    }

    Gaurhoth


    Posted by gaurhoth on Wednesday, May 13, 2009 9:53 AM
    E-mail | Permalink | Comments (0) | Post RSSRSS comment feed

    Rant: Vista/Win2008 and it's broken 'Connect to a Network' dialog

    I've become highly annoyed with the 'Connect to a Network' dialog in Vista and Windows 2008. It seems if you have any 'extra' NICs such as a loopback, virtual adapters, etc -- it totally confuses the 'Connect to a Network' dialog. You'll notice the 'VPN to Work' is showing a 'Red X' despite the  'Network and Sharing Center' showing an active internet connection.

    If I disable the extra adapters, then the dialog works as expected. Hard to believe this wasn't fixed in SP1. I've confirmed this behavior in Vista 32bit, Vista SP1 32bit, and Windows 2008 64bit.

    The workaround of course is to open 'Network and Sharing Center' (ncpa.cpl) and connect from the entry listed there -- but that doesn't reduce my annoyance :)

     

    image

     

    gaurhoth


    Categories: rant | vista
    Posted by gaurhoth on Saturday, April 19, 2008 7:21 AM
    E-mail | Permalink | Comments (28) | Post RSSRSS comment feed