Powershell-Skript schlägt beim Befehl "Copy-Item" fehl

Sep 13 2020

Ich bin ein Powershell-Neuling. Ich habe ein .ps1-Skript geschrieben, um eine Reihe von Dingen zu erledigen, die alle perfekt ausgeführt werden, außer wenn es um einen "Copy-Item" -Befehl geht, mit dem ich Inhalte des (Windows 10) -Desktops kopiere ein anderer Ordner.

Der Bindestrich in "Copy-Item" schlägt fehl. Ich habe das Gefühl, dass mir entweder ein "*" auf einem der Pfade fehlt. oder haben Sie eine, wo es nicht sein sollte. Ich habe es mit verschiedenen Kombinationen versucht, aber keine Freude.

Zu Testzwecken habe ich 3 Elemente auf dem Desktop: 1) eine Ordnerverknüpfung, 2) eine Powershell-Skriptverknüpfung und 3) einen GodMode-Ordner.

Vielen Dank im Voraus für deine Hilfe. Es folgt eine Teilmenge des Codes:

$env:path += ";D:\PowershellScriptsFolder" # this is the location of my ps1 # (a bunch of code here, all of which runs fine) # # Desktop # Define Variables $DestinationPath = "D:\folder1\subfolder\*"
        $SourcePathRoot = 'C:\Users\Sfrn\Desktop\' # this is the location of my Win 10 desktop # Remove-Item -Recurse -Path $DestinationPath -Force

(*** Hier scheitert es: ***)

Copy-Item -Recurse -Path $SourcePathRoot -Destination $DestinationPath -Force #   this is line 32

(*** Hier ist die Fehlerausgabe - Zeichen 5 ist der Bindestrich in "Copy-Item": ***)

Copy-Item: Unzulässige Zeichen im Pfad. Unter D: \ Dropbox \ DB_AppData \ PowerShell_and_Bat \ CopyToBackup_2.ps1: 32 char: 5

  • Copy-Item -Recurse -Path $SourcePathRoot -Destination $Destinatio ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo: InvalidArgument: (D: \ Dropbox \ DB_AppData \ Desktop *: String) [Copy-Item], ArgumentException
    • FullyQualifiedErrorId: CreateDirectoryArgumentError, Microsoft.PowerShell.Commands.CopyItemCommand

Copy-Item: Unzulässige Zeichen im Pfad. Unter D: \ Dropbox \ DB_AppData \ PowerShell_and_Bat \ CopyToBackup_2.ps1: 32 char: 5

  • Copy-Item -Recurse -Path $SourcePathRoot -Destination $Destinatio ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo: InvalidArgument: (desktop.ini: FileInfo) [Copy-Item], ArgumentException
    • FullyQualifiedErrorId: CopyDirectoryInfoItemArgumentError, Microsoft.PowerShell.Commands.CopyItemCommand

Copy-Item: Unzulässige Zeichen im Pfad. Unter D: \ Dropbox \ DB_AppData \ PowerShell_and_Bat \ CopyToBackup_2.ps1: 32 char: 5

  • Copy-Item -Recurse -Path $SourcePathRoot -Destination $Destinatio ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo: InvalidArgument: (Dropbox.lnk: FileInfo) [Copy-Item], ArgumentException
    • FullyQualifiedErrorId: CopyDirectoryInfoItemArgumentError, Microsoft.PowerShell.Commands.CopyItemCommand

Copy-Item: Unzulässige Zeichen im Pfad. Unter D: \ Dropbox \ DB_AppData \ PowerShell_and_Bat \ CopyToBackup_2.ps1: 32 char: 5

  • Copy-Item -Recurse -Path $SourcePathRoot -Destination $Destinatio ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo: InvalidArgument: (OpenApps.lnk: FileInfo) [Copy-Item], ArgumentException
    • FullyQualifiedErrorId: CopyDirectoryInfoItemArgumentError, Microsoft.PowerShell.Commands.CopyItemCommand

Copy-Item: Unzulässige Zeichen im Pfad. Unter D: \ Dropbox \ DB_AppData \ PowerShell_and_Bat \ CopyToBackup_2.ps1: 32 char: 5

  • Copy-Item -Recurse -Path $SourcePathRoot -Destination $Destinatio ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo: InvalidArgument: (D: \ Dropbox \ DB_AppData \ Desktop *: String) [Copy-Item], ArgumentException
    • FullyQualifiedErrorId: CreateDirectoryArgumentError, Microsoft.PowerShell.Commands.CopyItemCommand

(*** Ende der Fehlerausgabe: ***)

(Hier läuft weiterhin eine Menge Code, was alles in Ordnung ist.)

ENDE

Antworten

2 catherinemohan Sep 13 2020 at 06:16

Sie haben ein Sternchen an der falschen Stelle. Es muss sich im Quellverzeichnispfad befinden, nicht im Ziel, wie folgt:

$SourcePathRoot = "C:\Users\Sfrn\Desktop\*" $DestinationPath = "D:\folder1\subfolder\"