I want to create folders like this with variables in the path, I tried join-path and it tells me that "System.Object[]" cannot be converted to type "System.String" required by parameter "ChildPath". The specified method is not supported.
$variables\A\$variables
$variables\I
$variables\L\Cs\cz
$variables\L\Da\dk
$variables\L\Nl\nl
$variables\L\En\uk
$variables\L\En\us
$variables\M
$variables\U\Ed
I'm just new to powershell and this is my script:
$variables = Read-Host -Prompt 'Type here'
$dir = Join-Path -path $PSScriptRoot\$variables -ChildPath "A","I","L","M","U"
#-AdditionalChildPath I don't know how to properly create more childpaths,they are created at the wrong path
mkdir $dir
edit:
Considering that the L folder has many subfolders, so I tried foreach nested, which created the folders correctly, but at the same time returned a lot of An item with the specified name...already exists.
$var = Read-Host -Prompt 'Type here'
$loc = "Cs\cz","Da\dk","Nl\nl","En\uk","En\us"
$dir = foreach ($childPath in "A\$var","I","L","M","U\Ed") {
Join-Path $PSScriptRoot\$var $childPath
foreach ($additionalChildPath in $loc) {
Join-Path $PSScriptRoot\$var\L $additionalChildPath
}
}
mkdir $dir