I have already asked about Powershell return values in Powershell, but I can simply no wrap my head around why the following New-FolderFromName
is returning an array - I expected one value(a path or a string) in return:
$ProjectName="TestProject"
function New-FolderFromPath($FolderPath){
if($FolderPath){
if (!(Test-Path -Path $FolderPath)) {
Write-Host "creating a new folder $FolderName..." -ForegroundColor Green
New-Item -Path $FolderPath -ItemType Directory
}else{
Write-Host "Folder $FolderName already exist..." -ForegroundColor Red
}
}
}
function New-FolderFromName($FolderName){
if($FolderName){
$CurrentFolder=Get-Location
$NewFolder=Join-Path $CurrentFolder -ChildPath $FolderName
New-FolderFromPath($NewFolder)
return $NewFolder
}
}
$ProjectPath=New-FolderFromName($ProjectName)
Write-Host $ProjectPath
Also tried to add the following to New-FolderFromPath
as this function seems to be the problem or altering the parameter:
[OutputType([string])]
param(
[string]$FolderPath
)