1

I'm creating PS script to remove a bunch of applications from lots of devices.

The theory with the code below being it passes the path of an application to cmd.exe along with the "RD" (remove directory) command and two switches.

However all i get when running this is..

"'rd C:\Program Files\Mozilla Firefox /s /q' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Any suggestions please as to how accomplish my goal here

 if ($app_path) {

write-host "Now Removing $appname ,install directory ($app_path)"

$command = "rd $app_path /s /q"

& cmd.exe /c $command

}
1
  • 3
    Why are you running cmd.exe to Remove Directories? PowerShell can for instance Remove-Item –Path $app_path –Recurse. Commented Aug 28, 2019 at 22:04

1 Answer 1

1

The arguments need to be separate strings.

& cmd /c rd $app_path /s /q

or

$command = 'rd',$app_path,'/s','/q'
& cmd /c $command

or

cmd /c rd $app_path /s /q
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.