$RootSourcePath = "D:\CosmicInst\R8"
$Folder1 = Read-Host "Enter folder name under $RootSourcePath that you want to look for."
$Folder2 = Read-Host "Enter the sub-folder name under $RootSourcePath\$Folder1 that you want to look for."
$Source = "$RootSourcePath\$Folder1\$Folder2\Products\Manualhandling\IX3"
If(Test-Path $Source)
{
$ServerList = Get-Content 'C:\Users\baa065sa\Powershell skript\Levtestservrar.txt'
ForEach ($Server in $ServerList)
{
$RootDestinationPath = "\\$Server\C$\Cosmicinst"
$Destination = "$RootDestinationPath\$Folder1\$Folder2"
If (Test-Path $Destination)
{
Write-Host "Katalogen finns redan i IX3 LEVTEST." -ForegroundColor yellow
}
Else
{
If (!(Test-Path "$RootDestinationPath\$Folder1"))
{
#If the parent folder of $Folder2 (i.e. $Folder1) doesn't exist under $RootDestinationPath, create it.
New-Item -Name $Folder1 -Path $RootDestinationPath -ItemType Directory
}
#Since the test of the $Destination path failed, we know the $Folder2 folder also doesn't exist, so create it under $RootDestinationPath\$Folder1.
New-Item -Name $Folder2 -Path "$RootDestinationPath\$Folder1" -ItemType Directory
}
Copy-Item -Path $Source -Destination $Destination -Recurse
}
}