command line - Powershell unable to "see" dnscmd.exe

  • Ben Short

    Am at a complete loss with this one. Recently a number of my powershell scripts have started failing as they are unable to find the command dnscmd.exe.

    What has me at a loss is that the executable exists and works and I can run it just fine in the command prompt. I have tried the following in powershell to run the command:

    • dnscmd
    • & dnscmd
    • & dnscmd.exe
    • & c:\windows\system32\dnscmd.exe

    All return "The term dnscmd is not recognized as the name of a cmdlet, function,script file or operable program...."

    Can anyone enlighten me as to why powershell is completely unable to see the command, where the normal command prompt/windows explorer etc.. can? Using powershell 2.

  • Answers
  • fletcher

    This sounds like the work of the File System Redirector to me. Are you running on a 64bit OS?

    For example, when you make a call to C:\Windows\system32\dnscmd.exe on a 64bit OS using PowerShell (x86), this will be redirected to C:\Windows\SysWow64\dnscmd.exe. The redirection occurs at the point the folder is accessed so even though you are explicitly providing the path to the executable, you'll still be diverted. This can be disabled on the current thread via calls to native Windows APIs or can be avoided through the use of certain variables and aliases.

    More information here:

  • Shay Levy

    What do you get when you execute:

    Get-Command dnscmd.exe -CommandType Application

  • Taylor

    Its the File System Redirect, but you can bypass

    Instead of


    (which the redirector will grab) use

  • pete

    This is not very timely, but in Windows 8.1 I have found that it looks for it in System32 but doesn't find it. Strangely it exists on the system, but in the winsxs directory instead. Copying it to System32 allowed it to run as expected. I don't have any explanation as to why this is, but if you hit this issue it may be a workaround for you.

  • Related Question

    exchange - Simplifying powershell cmdlet
  • Jim Zajkowski

    I have a powershell cmdlet (move-IMAPMailboxToExchange) that requires a lot of repetition to enter. I want to call it with another batch/powershell script that just takes two args from the command line. I've tried every calling convention I can think of but I can't make it work.

    I want this:

    Move-IMAPMailboxToExchange -SourcePassword P@ssW0rd! -allowunsecureconnection -sourceLoginId username -sourceserver source.ser.ver -sourceidentity [email protected] targetclientaccessserver "client.access.ser.ver" -targetidentity [email protected] -verbose

    To be this:

    migrate-user username P@ssW0rd!

    I've tried $args, but that seems to expand. I've tried $args[0] which works in the bareword password and sourcelogin, but doesn't work next to the @mail.... I've tried %1, etc, from the old DOS days but that doesn't work.

    I'm a unix dork and I'm not quite grokking powershell yet.

  • Related Answers
  • sysadmin1138

    From what I remember, single-quotes is how PowerShell designates something as 'do not parse'. so...

    You might want to do something like this

    Move-IMAPMailboxToExchange [all that jazz]

    As a way to firmly declare the variables within the context of the script. If you're having trouble constructing the -sourceidentity and -targetidentity variables, you may want to pre-construct them before putting them on the move-imaptoexchange command...

  • Chad Miller

    You should be able to define a function or script file around your cmdlet, like this:

        function migrate-user
    Move-IMAPMailboxToExchange -SourcePassword $password -allowunsecureconnection -sourceLoginId $username -sourceserver 'source.ser.ver' -sourceidentity "$username`@mail.dom.ain" targetclientaccessserver 'client.access.ser.ver' -targetidentity "$username`@mail.dom.ain" -verbose