Webtron Webtron - 1 year ago 500
PowerShell Question

Copy-Item Failing Given Paths format is not supported

This is driving me bananas. I am assuming I am missing something stupid, but I have tried about 10 different formats and nothing works.

This is the code I am running:

$today=$(Get-Date -Format o)
$destfile = "C:\SEA-FTP\toFTP\SEAInfo-$today.csv"
$srcfile = "C:\SEA-FTP\temp\QueryCSVTempMstr.csv"
Copy-Item $srcfile -Destination $destfile

This is the error message:

Copy-Item : The given path's format is not supported.
At C:\SEA-FTP\BCP_SQL_Script-v1.0.ps1:53 char:10
+ Copy-Item <<<< $srcfile -Destination $destfile
+ CategoryInfo : NotSpecified: (:) [Copy-Item], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.CopyItemCommand

I know there are a million questions with this in Google search, but it looks like I am doing what they are doing. Any thoughts on the format?

Answer Source

You can't put colons in a filename on Windows:

Picture of Windows Explorer's tooltip error message when trying to rename a file and type a colon into the name

Your date format is 2016-08-22T22:15:25.3693163+01:00 so it can't work as part of a filename.

Fix: there's no fix which keeps the name how as specified; you could -replace ':', '-', any character that makes sense to you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download