CMD.exe, File Association , PowerShell

Today as a test I tried changing the file association of '.bat' files to PowerShell and it failed horribly. Then I tried to change the association back to 'CMD' and it will not run thus the machine is broken. I have two questions:

1.      I thought PowerShell can run batch files?
2.      Why didn’t changing to association to ‘CMD.EXE’ work?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
You can run .BAT files within Powershell but you have to call the process cmd.exe before the batch file can be run.

Take a look at the following link for details/examples...

KonfigurationKingAuthor Commented:
what about changing the association back to the way it was originally?
Will SzymkowskiSenior Solution ArchitectCommented:
You need to make sure that the file association and file extension is correct. Try creating a new batch file and use the above link for the syntax.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Associating .bat or .cmd with PowerShell is nonsense. Calling batch files from within PS can make sense, but should be avoided, as the results are strings, and cannot be processed as easily as cmdlet results (= objects) within PS.

You can change associations in cmd.exe with assoc and ftype:
REM view existing association:
assoc .bat
REM put the result into ftype (instead of batfile) to see what is really behind that:
ftype batfile
REM reset to default
assoc .bat=batfile

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.