A positional parameter cannot be found that accepts argument '\' A positional parameter cannot be found that accepts argument '\' powershell powershell

A positional parameter cannot be found that accepts argument '\'


You need to do the concatenation in a subexpression:

$FileMetadata = Get-FileMetaData -folder (Get-childitem ($Folder1 + "\" + $System.Name + "\Test") -Recurse -Directory).FullName

or embed the variables in a string like this:

$FileMetadata = Get-FileMetaData -folder (Get-childitem "$Folder1\$($System.Name)\Test" -Recurse -Directory).FullName


The most robust way in Powershell to build a path when parts of the path are stored in variables is to use the cmdlet Join-Path.

This also eliminate the need to use "\".

So in your case, it would be :

$FoldersPath = Join-Path -Path $Folder1 -ChildPath "$System.Name\Test"$FileMetadata = Get-FileMetaData -folder (Get-ChildItem $FoldersPath -Recurse -Directory).FullName


If you come from the world of VBScript. With Powershell, every space is interpreted as completely separate parameter being passed to the cmdlet. You need to either place the formula in parentheses to have the formula evaluated prior to passing it as the path parameter or enclosing with quotes also works:

Wont work, Powershell thinks this is two parameters:

$Folder1 + "\" + $System.Name

Will work with brackets:

($Folder1 + "\" + $System.Name)

Will also work together when enclosed in quotes:

"$Folder1\$System.Name"

Ref.