views:

83

answers:

2

I just download Powershell 2.0 and using the ISE. In general I really like it but I am looking for a workaround on a gotcha. There are a lot of legacy commands which are interactive. For example xcopy will prompt the user by default if it is told to overwrite a file.

In the Powershell ISE this appears to hang

mkdir c:\tmp
cd c:\tmp
dir > tmp.txt
mkdir sub
xcopy .\tmp.txt sub # fine

xcopy .\tmp.txt sub # "hang" here while it waits for a user response...

The second xcopy is prompting the user for permission to overwrite C:\tmp\sub\tmp.txt, but the prompt it not displayed in the ISE output window. I can run this fine from cmd.exe but then what use is ISE. How do I know when I need which one?

A: 

Why would you be using XCOPY from PowerShell ISE? Use Copy-Item instead:

Copy-Item -Path c:\tmp\tmp.txt -Destination c:\tmp\sub

It will overwrite any existing file without warning, unless the existing file is hidden, system, or read-only. If you want to overwrite those as well, you can add the -force parameter.

See the topic "Working with Files and Folders" in the PowerShell ISE help file for more info, or see all the commands at MSDN.

Ken White
+1  A: 

In a nutshell, Interactive console applications are not supported in ISE (see link below). As a workaround, you can "prevent" copy-item from overwriting a file by checking first if the file exists using test-path.

http://blogs.msdn.com/powershell/archive/2009/02/04/console-application-non-support-in-the-ise.aspx

Shay Levy

related questions