我需要创建一个脚本,要求用户输入文件夹名称\路径$File。从该$File获取一个子文件夹名,例如$File\docs\ref\$host。然后将$host复制到新的网络共享,创建名为$host的文件夹,并将其内容粘贴到其中。
我不能直接复制$host的原因是因为$host的名称会随着$File的改变而改变,但是两者之间的子文件夹是相同的。我希望这是有意义的?
这就是我所拥有的:
$file = Read-Host -Prompt 'What is your folder?'
# This is where I'm stuck
$host = Read-Host $file\docs\ref\$host
Test-Path \\Hulk\note\$host
If false
MD \\Hulk\note\$host
Copy-Item –Path $file\docs\ref\$host\ -Destination \\Hulk\note\$host\ –Recurse发布于 2016-07-15 18:45:00
假设\Hulk\note\ref是目标,您可以根据输入主机在该目录上创建文件夹,并将相同的文件夹复制到任何位置,尝试执行以下操作
$location="\\Hulk\note\ref"
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$folderName = Read-Host -Prompt 'Input folder name'
$target = Join-Path $location $folderName
if ( -not (Test-Path '$target' -PathType Container) ) { new-item "\\Hulk\note\$foldername" -type directory }
Copy-Item –Path \\path\$foldername -Destination \\where you need –Recursehttps://stackoverflow.com/questions/38392138
复制相似问题