powershell script

I want to write a script to find a directory in a path when I write the catalogs names and if the directory is there then copy it!

Please show us what you have so far

$foldername = Read-Host “Enter folder to check”

get-childitem -path D:\inst\test -Directory -filter $folderName |
write-host $_.FullName

so if this is your dir structure

and you wanted to search for folder3a it searches through the root dir folders and all its sub folders then copies it somewhere ?

yes i want search for folder3a and then search a special folder(folder2) in folder3a then a special folder(folder1) in folder2 …
and kopy a folder to a special folder in 10 or 20 server!

$serverlist1 = Get-Content “C:\Users\baa065sa\Powershell skript\Levtestservrar.txt”

$foldername = Read-Host “Enter folder to check”
get-childitem -path D:\Inst\test -Directory -filter $folderName |
write-host Path exists on $_.FullName

$foldername = Read-Host “Enter folder to check”

get-childitem -path D:\Inst\test -recurse -Directory -filter $folderName |
write-host $_.FullName

Something like this ? Servers.txt has a list of server names in it

$Servers = Get-Content “c:\temp\servers.txt”
$Source = “C:\copied”
$Destination = “c$\Temp”
Foreach ($Server in $Servers)
{Copy-Item $Source -Destination “\$Server$Destination” -Recurse}

I’m not sure I understand your scenario, but I would suggest using the Test-Path cmdlet to verify if a specific path exists. You could use it something like the following:

$SourceFolder = 'C:\Temp'
$DestinationFolder = \\Server1\Data\
$SourceFolderExists = Test-Path -Path $SourceFolder
  Copy-Item -Path $SourceFolder -Destination $DestinationFolder -Recurse

The above will copy the C:\Temp folder, and all of the content/folders/subfolders under it, to the specified destination folder. Hope that helps.

it’s good but the folder names come and change every time!
I will write the names first and then it will check if the directory exists or not

$foldername = Read-Host “Enter folder to check”
get-childitem -path D:\CosmicInst\R8 -Directory -filter $folderName |
write-host Path exists on $_.FullName

write-host Path not exists on $_.FullName

I want to write a script to check the folder for a server, and then another folder to check it in the folder, and if this folder exists, copy that folder to the other server from that server!
For example, when we run the script, we will use the name of the first folder, then if there is a folder name that you have in that folder, and if there is one to copy it, if it does not exist, it says there is no folder.