【发布时间】:2019-08-14 17:01:57
【问题描述】:
我已经asked 了解 Powershell 在 Powershell 中的返回值,但我无法理解为什么以下 New-FolderFromName 返回一个数组 - 我期望一个值(路径或字符串)作为回报:
$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
还尝试将以下内容添加到New-FolderFromPath,因为此功能似乎是问题或更改了参数:
[OutputType([string])]
param(
[string]$FolderPath
)
【问题讨论】:
标签: powershell