Powershell Tutorial Online

Powershell with FileSystem batch file

Scenario 1: Calling batch file from powershell.
Note:MKDIR/RMDIR - Create and remove directories Learn some basic batch commands.

    ECHO - Displays text on the screen
    @ECHO OFF - Hides the text that is normally output
    START - Run a file with it's default application
    REM - Inserts a comment line in the program
    MKDIR/RMDIR - Create and remove directories
    DEL - Deletes a file or files
    COPY - Copy a file or files
    XCOPY - Allows you to copy files with extra options
    FOR/IN/DO - This command lets you specify files

create sample file .bat or .cmd file (.bat is the old 16-bit naming convention, and .cmd is for 32-bit Windows)
        MKDIR c:\test\example1
        MKDIR c:\test\example2

Now we want to give call to this batch file from powershell.
        Write-Host "Call the batch from pwoershell"
        Write-Host "Done folders (example1, example2) should created.."

Scenario 2: Calling powershell script file from batch. 1. Create sample powershell file (powershell-to-create-directories.ps1)create 2 example1 and example2 folders like we did in earlier example. Here we will do in opposite manner..

        MKDIR c:\test\example1
        MKDIR c:\test\example2
        @echo off
        Powershell.exe -File  C:\test\Call-batch-file-from-powershell.ps1
Note: you might need permissions to execute powershell script on your machine.

Scenario 3: Passing arguments to batch to powershell. This is powershell script we are passing 2 agrument from batch file and inside powershell script we will create 2 folder with these agrument name like Myarg1 Myarg2. Batch File

    @echo off
    Powershell.exe -File  C:\test\Pass-Arguments-from-batchfile-to-powershell.ps1 Myarg1 Myarg2
Powershell File
        MKDIR c:\test\$MyFirstArg
        MKDIR c:\test\$MySecondArg

Output After double clicking or executing batch file 2 folders should get created with given name like here Myarg1 Myarg2

Scenario 4: Passing arguments to powershell from batch. Comming soon and also we will be adding more common scenarios.