0
votes

I need to create a script that asks the user to input a folder name\path $File. From that $File aquire a subfolder name e.g. $File\docs\ref\$host. Then copy $host to a new network share and create that folder name of $host and paste its contents in there.

The reason I can't just copy $host is because $host name changes as does $File but the subfolders inbetween the 2 are the same. I hope that makes sense?

This is what I have:

$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
1
Where does the $host in $file\docs\ref\$host come from? And why are you using Read-Host on it? Also, $host is an automatic variable that contains information about the host process. You're not supposed to modify it. - Ansgar Wiechers
$file = Read-Host -Prompt 'What is your folder?' will contain folder name not in $Host - DisplayName
Aah, i didn't realise that $host was a automatic variable - Jeff.M
try my script below working for me - DisplayName

1 Answers

0
votes

Assume that \Hulk\note\ref is the target you can create folder on that directory based on input host and copy the same folder to anywhere try this

    $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 –Recurse