Keywords: Build, Windows CMD, PowerShell based Building Scripts, batch, BAT

Power Shell

How to setup building environment of MSCV (VC++)


if (!(Test-Path vswhere.exe)) {
  Invoke-WebRequest -Uri "" -OutFile vswhere.exe

# setup vsdevcmd.bat
$path = .\vswhere.exe -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($path) {
  $batpath = join-path $path 'Common7\Tools\vsdevcmd.bat'
  if (test-path $batpath) {
    cmd /s /c """$batpath"" $args && set" | Where-Object { $_ -match '(\w+)=(.*)' } | ForEach-Object {
      $null = new-item -force -path "Env:\$($Matches[1])" -value $Matches[2]
  # dbghelp.dll, administrator permission needed
  $debuggerpath = join-path $path 'Common7\IDE\Extensions\TestPlatform\Extensions\Cpp\x64\dbghelp.dll'
  if (!(Test-Path 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64')) {
    New-Item 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64' -ItemType Directory -Force
    Copy-Item $debuggerpath 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll'


@echo off

set VSDEVCMD=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat
if exist "%VSDEVCMD%" (
    @REM Tell VsDevCmd.bat to set the current directory, in case [USERPROFILE]\source exists. See:
    @REM C:\Program Files (x86)\Microsoft Visual Studio\%COMPILER%\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_end.bat
     call "%VSDEVCMD%" -arch=%PROTOBUF_ARCH%
      ) else (
     echo ERROR: Cannot find Visual Studio %COMPILER%
     exit /b 2
How to replace string in text file


(Get-Content ../source/build.cs) | ForEach-Object { $_ -replace '//UserList.Add\("NeilWang"\);', 'UserList.Add("NeilWang");' } | Set-Content ../source/build.cs

//UserList.Add("NeilWang"); would be replaced as UserList.Add("NeilWang");.


If want to run powershell script from Windows batch. do follows.

powershell -Command "(Get-Content ../source/build.cs) | ForEach-Object { $_ -replace '//UserList.Add\(\"NeilWang\"\);', 'UserList.Add(\"NeilWang\");' } | Set-Content ../source/build.cs"
How to call powershell script file(.ps1) from CMD


powershell -ExecutionPolicy Bypass -File example.ps1

PowerShell says “execution of scripts is disabled on this system.”

Batch (CMD)

How to delete file if exists
IF EXIST [Filename] (
    del [Filename]
) ELSE (


if exist c:\folder\file del c:\folder\file

Origin: Delete files in batch with without error message

How to delete all fiels
::removes all files from the directory,
del /q destination\*
::recursively removes all nested directories
for /d %%x in (destination\*) do @rd /s /q "%%x"

How to delete all files and folders in a folder by cmd call

How to delete directory (folder)
if exist "c:\yourFolder\" rd /q /s "c:\yourFolder"

Delete a directory and its files using command line but don’t throw error if it doesn’t exist

How to clean all directories of current folder
for /d %%D in (../Plugins/*) do (
  if exist %~dp0..\Plugins\%%D\Binaries rd /q /s %~dp0..\Plugins\%%D\Binaries
  if exist %~dp0..\Plugins\%%D\Intermediate rd /q /s %~dp0..\Plugins\%%D\Intermediate
How to pause an exe after startup
start "" "CMD " /c myapp.exe ^& pause


How to get current directory path

%~dp0, example:




Building script of WebRTC:


Book List

The PowerShell Scripting and Toolmaking Book

“This defines entrepreneur and entrepreneurship - the entrepreneur always searches for change, responds to it, and exploits it as an opportunity.” ― Peter F. Drucker, Innovation and Entrepreneurship: Practice and Principles