copy one folder

you need to have all of your $destination folder tree exists for Copy-Item to work
“\$serverlist1\C$\Cosmicinst$folder1$folder2”
“\$serverlist1\C$\Cosmicinst$folder1”
“\$serverlist1\C$\Cosmicinst”

somewhere you doesnt have it
you can add -Verbose or Write-Host to check

and change exit to continue

Cosmic. Hopefully, I correctly understand what you’re trying to do.

What I think you’re trying to do.

  1. You have a folder called IX3 located under a path on the source server that has two folder names that can change (Represented in the full directory path below by the variables $Folder1 & $Folder2).

Full Source Path: D:\CosmicInst\R8$Folder1$Folder2\Products\Manualhandling\IX3

  1. If the folder IX3 exists under the above source path, on the source server, you want to check to see if the below full destination path exists. If it does, don’t do anything other than write a message to the screen letting you know that it already exists on the server. Again, the $Folder1 & $Folder2 variables can change.

Full Destination Path: \$Server\C$\Cosmicinst$Folder1$Folder2

  1. If the full source path exists, but the full destination path doesn’t, then you want to copy the IX3 folder, and all of the contents under it’s structure, to the destination path.

Full Destination Path (After the copy has been done): \$Server\C$\Cosmicinst$Folder1$Folder2\IX3\RestOfTheCopiedFolderStructure

If my understanding is correct, the following should work. I haven’t tested it and you can always dress it up with error capturing, etc…

Note: As an FYI, it’s a good idea to properly format your code so that it’s more readable to people. That way it’s easier to understand what you’re trying to do, where the issues might be, etc… Also, it’s helpful to have a detailed description of what you’re trying to do (with full examples) or what your issue is.

$RootSourcePath = "D:\CosmicInst\R8\"
$Folder1 = Read-Host "Enter folder name under $RootSourceFolder that you want to look for."
$Folder2 = Read-Host "Enter the sub-folder name under $RootSourceFolder\$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\Levtestservrar2.txt'

  ForEach ($Server in $ServerList)
  {
    $RootDestinationPath = "\\$Server\C$\Cosmicinst\"
    $Destination = "$RootDestinationFolder\$Folder1\$Folder2"

    If (Test-Path $Destination)
    {
      Write-Host "Katalogen finns redan i IX3 LEVTEST." -ForegroundColor yellow
      Exit
    }
    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
  }
}

I getting this error.

New-Item : The network path was not found.
At C:\Users\baa065sa\Powershell skript\best.ps1:60 char:9
+         New-Item -Name $Folder1 -Path $RootDestinationPath -ItemType Directory
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (\\\C$\Cosmicinst\LUL_8.1.1_09:String) [New-Item], IOExce
    + FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : The network path was not found.
At C:\Users\baa065sa\Powershell skript\best.ps1:66 char:7
+       New-Item -Name $Folder2 -Path "$RootDestinationPath\$Folder1" -ItemType Di ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (\\\C$\Cosmicins...L_8.1.1_09_005p:String) [New-Item], IO
    + FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.NewItemCommand

Copy-Item : The network path was not found.
At C:\Users\baa065sa\Powershell skript\best.ps1:72 char:7
+       Copy-Item -Path $Source -Destination $Destination -Recurse
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (\\\C$\Cosmicins...L_8.1.1_09_005p:String) [Copy-Item], I
    + FullyQualifiedErrorId : CreateDirectoryIOError,Microsoft.PowerShell.Commands.CopyItemCommand

Looks like I had some types in my code where I used a variable called $RootSourceFolder, instead of $RootSourcePath, and the same on like 13 of my above code where I used $DestinationRootFolder, instead of $DestinationRootPath, like the rest of my code was using. I’ve made the corrections below. If the below code fixes don’t help, then I would check if the path of \$Server\C$\Cosmicinst\ exists because I wrote the code (creating $Folder1 & $Folder2) assuming that it does, based on what you told us.

$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\Levtestservrar2.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
      Exit
    }
    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
  }
}
PS C:\Users\baa065sa\Powershell skript> .\best.ps1
Enter folder name under D:\CosmicInst\R8\ that you want to look for.: LUL_8.1.1_09
Katalogen finns i Server.
Enter the sub-folder name under D:\CosmicInst\R8\\LUL_8.1.1_09 that you want to look for.: LUL_8.1.1_09_005P
Katalogen finns i Server.
Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\best.ps1:40 char:9
+     If (Test-Path $Destination)
+         ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\cos-tesr-server.l...L_8.1.1_09_005P:String) [Test-Path], ArgumentExcepti
   on
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\best.ps1:54 char:14
+        If (!(Test-Path "$RootDestinationPath\$Folder1"))
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\cos-test-server.l...t\\LUL_8.1.1_09:String) [Test-Path], ArgumentExcepti
   on
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\best.ps1:60 char:9
+         New-Item -Name $Folder1 -Path $RootDestinationPath -ItemType Directory
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\cos-test-server.l...st\LUL_8.1.1_09:String) [New-Item], ArgumentExceptio
   n
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\best.ps1:66 char:7
+       New-Item -Name $Folder2 -Path "$RootDestinationPath\$Folder1" -ItemType Di ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\cos-test-server.l...L_8.1.1_09_005P:String) [New-Item], ArgumentExceptio
   n
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

Copy-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\best.ps1:72 char:7
+       Copy-Item -Path $Source -Destination $Destination -Recurse
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

Katalogen finns redan i IX3 cos-tstx-15.lul.se .

I’m running this script

$RootSourcePath = "D:\CosmicInst\R8\"


$Folder1 = Read-Host "Enter folder name under $RootSourcePath that you want to look for."

If (test-path $RootSourcePath\$folder1) {Write-Host "Katalogen finns i Server." -ForegroundColor Green}
Else {Write-Host "Katalogen INTE finns i Server." -ForegroundColor Red 
exit
}

$Folder2 = Read-Host "Enter the sub-folder name under $RootSourcePath\$folder1 that you want to look for."

If (test-path $RootSourcePath\$Folder1\$folder2) {Write-Host "Katalogen finns i Server." -ForegroundColor Green}
Else {Write-Host "Katalogen INTE finns i Server." -ForegroundColor Red 
exit
}


$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 $server ." -ForegroundColor yellow
      
      Exit
    
     }
    
     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
  
     }

}
  1. First of all, change the $RootSourcePath & $DestinationSourcePath as below(i.e. take the backslash () off the end to get rid of the double-backslash (\) you’re seeing in the $Source & $Destination variables). This isn’t the problem, but it’ll make the path look better.
$RootSourcePath = "D:\CosmicInst\R8"
$RootDestinationPath = "\\$Server\C$\Cosmicinst"

My suggested code updated.

$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\Levtestservrar2.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
      Exit
    }
    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
  }
}
  1. Why are you testing first for $RootSourcePath$Folder1 & then for $RootSourcePath$Folder1$Folder2? In the code I suggested, I test just for the later path of $RootSourcePath$Folder1$Folder2, which is stored in the $Source variable. If $RootSourcePath$Folder1$Folder2 (I.e $Source) exists, then so does $RootSourcePath$Folder1.

  2. Now for the problem at hand with the “Invalid characters in path” error.

Unfortunately, the error code doesn’t show the complete paths, so it’s hard to see what illegal characters there may be. I tried reproducing the issue as best I could with what you posted, but I couldn’t reproduce the issue. I would suggest the following:

  1. Try updating the code as I suggested at the top (i.e. taking out the backslashes () in the $SourceRootPath & $DestinationRootPath variables).
  2. If that doesn’t fix it, you might trying doing a Write-Host of the path in question just before the line where the error occurs and looking to see what illegal characters there may be.

Looks like you got the answer toe the “Invalid characters in path” error from Don Jones. My eyes glossed right over the “C$” part.

https://powershell.org/forums/topic/powershell-error/

two new Error!

Copy-Item : An item with the specified name \\servertest\C$\Cosmicinst\LUL_8.1.1_09\LUL_8.1.1_09_006P\IX3\IX3Ma
nager\scripts already exists.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:62 char:5
+     Copy-Item -Path $Source -Destination $Destination -Recurse
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceExists: (\\servertest.l...Manager\scripts:String) [Copy-Item], IOException
    + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.CopyItemCommand
Copy-Item : The network path was not found.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:62 char:5
+     Copy-Item -Path $Source -Destination $Destination -Recurse
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (IX3Manager.exe.config:FileInfo) [Copy-Item], IOException
    + FullyQualifiedErrorId : CopyDirectoryInfoItemIOError,Microsoft.PowerShell.Commands.CopyItemCommand
Test-Path : Illegal characters in path. At C:\Users\baa065sa\Powershell skript\sugest.ps1:28 char:9 + If (Test-Path $Destination) + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (\\ \C$\Cosmicin...L_8.1.1_09_006P:String) [Test-Path], ArgumentExcep ti on + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:42 char:9

  •     If (!(Test-Path "$RootDestinationPath\$Folder1"))
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (\ \C$\Cosmicinst\LUL_8.1.1_09:String) [Test-Path], ArgumentExceptio
      n
    • FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:48 char:11

  •             New-Item -Name $Folder1 -Path $RootDestinationPath -ItemType Directory
    
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (\ \C$\Cosmicinst\LUL_8.1.1_09:String) [New-Item], ArgumentException
    • FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:55 char:13

  •         New-Item -Name $Folder2 -Path "$RootDestinationPath\$Folder1" -ItemT ...
    
  •   + CategoryInfo          : InvalidArgument: (\\    \C$\Cosmicin...L_8.1.1_09_006P:String) [New-Item], ArgumentExcept
    

io n
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

Copy-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:62 char:5

  • Copy-Item -Path $Source -Destination $Destination -Recurse
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:slight_smile: [Copy-Item], ArgumentException
    • FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

            
Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:28 char:9
+     If (Test-Path $Destination)
+         ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\    \C$\Cosmicin...L_8.1.1_09_006P:String) [Test-Path], ArgumentExcep
ti    on
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:42 char:9
+         If (!(Test-Path "$RootDestinationPath\$Folder1"))
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\    \C$\Cosmicinst\LUL_8.1.1_09:String) [Test-Path], ArgumentExceptio
n
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:48 char:11
+                 New-Item -Name $Folder1 -Path $RootDestinationPath -ItemType Directory
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\    \C$\Cosmicinst\LUL_8.1.1_09:String) [New-Item], ArgumentException
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:55 char:13
+             New-Item -Name $Folder2 -Path "$RootDestinationPath\$Folder1" -ItemT ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (\\    \C$\Cosmicin...L_8.1.1_09_006P:String) [New-Item], ArgumentExcept
io    n
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

Copy-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:62 char:5
+     Copy-Item -Path $Source -Destination $Destination -Recurse
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:28 char:9

  • If (Test-Path $Destination)
    
  •     ~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (\ \C$\Cosmicin…L_8.1.1_09_006P:String) [Test-Path], ArgumentExcep
      ti on
    • FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

Test-Path : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:42 char:9

  •     If (!(Test-Path "$RootDestinationPath\$Folder1"))
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (\ \C$\Cosmicinst\LUL_8.1.1_09:String) [Test-Path], ArgumentExceptio
      n
    • FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:48 char:11

  •             New-Item -Name $Folder1 -Path $RootDestinationPath -ItemType Directory
    
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (\ \C$\Cosmicinst\LUL_8.1.1_09:String) [New-Item], ArgumentException
    • FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:55 char:13

  •         New-Item -Name $Folder2 -Path "$RootDestinationPath\$Folder1" -ItemT ...
    
  •   + CategoryInfo          : InvalidArgument: (\\    \C$\Cosmicin...L_8.1.1_09_006P:String) [New-Item], ArgumentExcept
    

io n
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

Copy-Item : Illegal characters in path.
At C:\Users\baa065sa\Powershell skript\sugest.ps1:62 char:5

  • Copy-Item -Path $Source -Destination $Destination -Recurse
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:slight_smile: [Copy-Item], ArgumentException
    • FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand

For the first error, does that “scripts” directory (C:\Cosmicinst\LUL_8.1.1_09\LUL_8.1.1_09_006P\IX3\IX3Ma
nager\scripts) exist on Servertest?

For the second error, I couldn’t find much on it. Maybe you’ll have better luck. Maybe it will work if you try again? I did some one thing similar, and they didn’t see the issue with tools called xcopy and robocopy.

What can I do for the first error! How can I write if the directory is copied again! I do not want to show this erroren!