Scenario 1: Calling batch file from powershell.
Note:MKDIR/RMDIR - Create and remove directories
Learn some basic batch commands.
Example
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
Example
Write-Host "Call the batch from pwoershell"
C:\test\batch.bat
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..
Example
@echo off
Powershell.exe -File C:\test\Call-batch-file-from-powershell.ps1
pause
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
Example
@echo off
Powershell.exe -File C:\test\Pass-Arguments-from-batchfile-to-powershell.ps1 Myarg1 Myarg2
pause
Example
$MyFirstArg=$args[0]
$MySecondArg=$args[1]
MKDIR c:\test\$MyFirstArg
MKDIR c:\test\$MySecondArg
Scenario 4: Passing arguments to powershell from batch. Comming soon and also we will be adding more common scenarios.