I have a batch/powershell script that I use to make a list of all my movies and tv series but have run into a small problem, I can't have spaces in my batch variables when passing them to the powershell script.
I have tried all kinds of combos of ' and " around the variables without any luck.
My batch variables
SETLOCAL enabledelayedexpansion
SET "listfolder=%CD%\ContentList\"
SET "listname1=TVSeries"
SET "RootFolder1=\\SERVER\Storage\TV Series\"
SET "Folder1Width=70"
SET ScanFolder1=TRUE
My batch code to run and pass variables to powershell
"%listfolder%Script\Powershell.exe" -executionpolicy remotesigned -File "%listfolder%Script\folder1list.ps1" %RootFolder1% %listname1% %Folder1Width%
My powershell script code to set the variables.
param([String]$RootFolder1, [String]$listname1, [int32]$Folder1Width)
This is the error I get if I have space in %RootFolder1% path, without spaces all three variables get passed to powershell just fine.
C:\Users\hflat\Desktop\Folder Content List Maker v4.5\ContentList\Script\folder1list.ps1 : Cannot process argument
transformation on parameter 'Folder1Width'. Cannot convert value "TV" to type "System.Int32". Error: "Input string was
not in a correct format."
I found the solution here How to pass in a string with spaces into PowerShell?
What did work was to use a cmd wrapper with /S to unwrap outer quotes and removing my own path to powershell.exe
cmd /S Powershell.exe -executionpolicy remotesigned -File "%listfolder%Script\folder1list.ps1" "%RootFolder1%" "%listname1%" "%Folder1Width%"