2
我希望這是一個愚蠢的錯誤,我忽略了一些非常簡單的事情。我有一個映射網絡驅動器並將網絡驅動器的內容複製到目標的功能。最後,我返回目標路徑以供稍後重新使用。但是,它似乎正在爲目標路徑返回不同類型的對象。以下是代碼片段:是否複製項目更改PowerShell中的目標參數類型
function CopyDropFolder {
param(
[string] $dropFolder,
[string] $releaseName,
[string] $mapDrive
)
$stageDirectory= $('c:\temp\' + $releaseName + '-' + (Get-Date -Uformat %Y%m%d-%H%M).ToString() + '\')
[string]$destinationDirectory = $stageDirectory
Write-Host 'Mapping Folder ' $dropFolder ' as ' $mapDrive
MountDropFolder -mapfolder $dropFolder -mapDrive $mapDrive
$sourceDir = $mapDrive + ':' + '\'
Write-Host 'Copying from mapped drive (' $sourceDir ') to ' $stageDirectory
Copy-Item $sourceDir -Destination $stageDirectory -Recurse
Write-Host $destinationDirectory
return $destinationDirectory
}
我所說的功能如下:
$stageDirectory = CopyDropFolder -dropFolder $mapFolder -releaseName $releaseName -mapDrive $newDrive
Write-Host 'Staged to ' $stageDirectory
從與功能(寫主機$ destinationDirectory)的輸出是:
c:\temp\mycopieddirectory-20161228-1422\
然而從其中呼叫由主腳本,輸出:
Staged to Z c:\temp\mycopieddirectory-20161228-1422\
看起來返回的stageDirectory變量以某種方式映射到Z:這是在函數內映射的新驅動器。
如何實際只返回被上面的函數中打印路徑中的任何想法?
知道這很有趣。我會試試這個,讓你知道結果。 – sohail
不,上述嘗試,但結果是一樣 – sohail
另外,我很困惑,爲什麼會影響變量$ destinationDirectory當我使用$ stageDirectory作爲我的目標變量 – sohail