I have a script that copies a number of files from different sources to a single directory for backup. The only step of the script the errors out has a space in both the path and file names: \\server\Network Shares\Transfer\tu3\tu3 Code.mdb
I get the error copy-item : Cannot find path '\\server\Network Shares\Transfer\tu3\tu3 Code.mdb' because it does not exist.
and I'm assuming it's because of the spaces in either the path or filename. Does PowerShell allow spaces in a fully qualified path? If not, how can I get at the file?
Here's the relevant code (My$Dest
is defined as a global variable for the script):
$TU3CodeUpdatedPathname = "\\server\Network Shares\Transfer\tu3\"
$TU3CodeUpdatedFilename = "tu3 Code.mdb"
$TU3CodeUpdated = $TU3CodeUpdatedPathname + $TU3CodeUpdatedFilename
#
$Source = $TU3CodeUpdated
$Dest = $VMShareSpacePathname
#
copy-item $Source $Dest
Try being more explicit, and wrap the parameter values in quotes. Adding -Verbose might help with debugging. If it's complaining the file doesn't exist, maybe double check that the file is indeed accessible when your script runs under the account, if it's not the same as your user account.
Copy-Item -Path "$Source" -Destination "$Dest"
Just to ensure, you might have mixed up the variable names TU3/HS3?
$TU3CodeUpdatedPathname = "\\server\Network Shares\Transfer\tu3\"
$TU3CodeUpdatedFilename = "tu3 Code.mdb"
$TU3CodeUpdated = Join-Path -Path $TU3CodeUpdatedPathname -ChildPath $TU3CodeUpdatedFilename
Otherwise I can't see anything wrong with your code. Spaces are just fine within quotes as you did write it.
I would guess the running user from the script does not have access rights to the file/share. This post might help in that case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With