Executing DOS command with Powershell

It's best that we can write all scripts in Powershell.... that will be very nice. But, sometimes, it's more "convenient" to write the DOS command.

To execute DOS command, we use "cmd /c" + the DOS command:

   cmd /c "dir d:"

We may execute the DOS command using Invoke-Expression:

   $cmd = "dir d:\temp3"
   Invoke-Expression -Command $cmd

OR, to execute the Robocopy to copy the file from one folder to another:

   $src = "d:\temp3\test"
   $dst = "d:\temp3\test2"
   $cmd = "robocopy $src $dst /S /E /COPYALL /DCOPY:T /R:10 /W:10 /NP /TEE"
   Invoke-Expression -Command $cmd

Comments

Popular posts from this blog

Scheduled task in Windows Task Scheduler - part 3

Create scheduled task in Windows Task Scheduler

Get all website entries in IIS