Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Beginner Assistanmce

Beginner Assistanmce

Beginner Assistanmce

Hi Guys,

I've begun learning powershell and have encountered a problem that I'm trying to solve.

Basically I'm working on developing a script that will find the most recent backup file and then run a check on the integrity of this file using a proprietary command that's run from the cmd prompt.The problem I'm having is when I run the code below I encounter the following error.

cmd.exe : ' C : \ P r o g r a m ' i s n o t r e c o g n i z e d a s a n i n t e r n a l o r e x t e r n a l c o m m a n d ,
At C:\Users\user\Desktop\Scripts\VerifyBackup.ps1:27 char:16
+ CMD.exe <<<< /U /C $cmddir v $Md5Name > C:\Temp\Result.txt
+ CategoryInfo : NotSpecified: (' C : \ P r o g... o m m a n d , :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
o p e r a b l e p r o g r a m o r b a t c h f i l e .

CODE --> powershell

$CmdDir = "C:\Program Files (x86)\StorageCraft\ShadowProtect\image.exe"

$File_Location = Get-ChildItem E: | Where {$_.extension -eq '.md5'}  | Sort-object {$_.LastWriteTime} -Descending | Select-object -First 1 Fullname 

CMD.exe  /U /C $cmddir v $File_Location > C:\Temp\Result.txt 

I believe that the problem is that I'm passing variables that contains values to the cmd prompt and these variables need to be surrounded in specific quotes. However,I'm unsure which types of quotes/where to place them.

Any help would be appreciated.


RE: Beginner Assistanmce

I don't see a problem with quotes. For example I tried here a script with several ways how to execute "rexx -v" i.e. print the version number of the program and everything seems to work


cmd /c C:\"Program Files"\Regina\rexx.exe -v
cmd /c C:\'Program Files'\Regina\rexx.exe -v
&"C:\Program Files\Regina\rexx.exe" -v
&'C:\Program Files\Regina\rexx.exe' -v

$cmd_dir = "C:\Program Files\Regina\rexx.exe"
echo "cmd_dir = '$cmd_dir'"
cmd /c $cmd_dir -v

$cmd_dir = 'C:\Program Files\Regina\rexx.exe'
echo "cmd_dir = '$cmd_dir'"
cmd /c $cmd_dir -v 



C:\_mikrom\Work\PowerShell>powershell -ExecutionPolicy RemoteSigned .\exec_cmd.p
REXX-Regina_3.5 5.00 31 Dec 2009
REXX-Regina_3.5 5.00 31 Dec 2009
REXX-Regina_3.5 5.00 31 Dec 2009
REXX-Regina_3.5 5.00 31 Dec 2009
cmd_dir = 'C:\Program Files\Regina\rexx.exe'
REXX-Regina_3.5 5.00 31 Dec 2009
cmd_dir = 'C:\Program Files\Regina\rexx.exe'
REXX-Regina_3.5 5.00 31 Dec 2009 

IMO the error is in your command line. You try to execute this command:
$cmddir v $File_Location
Is that right, shouldn't it be this?:
$cmddir -v $File_Location

Check if the program C:\Program Files (x86)\StorageCraft\ShadowProtect\image.exe really exists on your machine.
Check if in the variable $File_Location has proper value.

Hovever, I have here Windows XP. Isn't it Windows 7 specific error?

RE: Beginner Assistanmce

Really, there is no reason to use cmd.exe. You can use Start-Process, Invoke-Command, Invoke-Expression or any of those variations to run a command. This allows for seamless passing of variables, errors, and objects.

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close