I'm having a few issues while copying desktop files as a part of the back up process from local folder to server.
My script automatically creates a backup folder on the server and I just realised when it creates the back up folder windows automatically creates a desktop.ini file, and as desktop.ini is a system file the script failed to write another desktop.ini from desktop to the backup folder in server.
My initial code was :
Copy-Item ("$Global:localBackupRestoreLocation\Desktop\$file") ("$Global:remoteBackupRestorePath\$nameOfbackupDirectory") ($recursive="true")
But I was to use the exclude in that line and I know exclude does not work recursively and I have to use Get-ChildItem.
Try something like this
$Exclude = #('desktop.ini')
copy-item -Path $Source -Destination $Dest -Exclude $Exclude
Related
I have created a PowerShell script to move my video files from separate folders on my hard drive to a central folder. The script looks like this:
#location of starting directory
$_sourcePath ="C:\Movies\ -recurse"
#location where files will be copied to
$_destinationPath = "C:\New\"
#Array of extension that need to move from source path
$_FileType= #("*.*mp4")
When the scrip runs, nothing happens. I get no errors, but I also don't get an of the *.mp4 files moved.
what is wrong with this script?
Try this
$_sourcePath ="C:\Movies\"
$_destinationPath = "C:\New";
$_FileType= #("*.*mp4")
Get-ChildItem -recurse ($_sourcePath) -include ($_FileType) | move-Item -Destination ($_destinationPath)`
I try to use powershell to deploy a build (Visual Studio) to multiple remote server.
The problem is, that the powershellscript does not copy the folders like I intendet to.
I use the following powershell command to copy the published website to the destinations.
Copy-Item -Path D:\Websites\$(ProjectName)\ -Recurse -Destination \\%RemoteServer%\D$\Websites\$(ProjectName)\ -Container -Exclude *.config -force
When the folder on the remoteserver does not exist, everything works fine.
But if the folder exists, all files are copied into a new subfolder instead of overwriting the existing ones.
So in the first execution the destination is corrected and looks like this:
D:\Websites\TestWebsite\ {all files}
After a second copy, the destination of the copy is:
D:\Websites\TestWebsite\Publish\ {all files}
The variables ProjectName and RemoteServer are in both executions the same.
I need to be able to copy all items within a drive and move them to a new destination using Powershell. At present, I've tried doing this with Copy-Item but am unable to do so within a drive. I've looked for solutions elsewhere but have yet to find a working fix, Any suggestions?
Copy-Item -Path 'P:' -Destination 'Destination'
If you're trying just to copy all of the items from one drive to a folder on another drive, you can use Copy-Item, like you are, with a few adjustments (-Destination path is just an example):
Copy-Item -Path C:\* -Destination F:\destinationPath -Recurse
Using the * in C:\* for the path tells the shell to get all files and directories at that folder, in this case, the C: root. -Recurse tells it to copy all files and directories recursively. Consider adding the -Force parameter if you want to use this in automation, as it will forcibly overwrite any existing files at the destination rather than prompt for input.
I want to copy a folder which contain many file and other folders to a specific folder. However I get fail by using the following code.
Copy-Item "c:\F1" "c:\Fs\F1"
or
Copy-Item "c:\F1\*" "c:\Fs\F1"
The structure of folder1:
F1
F1-1
file B
F1-2
file C
file D
file A
You are probably missing the -recurse option.
Copy-Item -Path C:\F1 -Destination c:\FsF1 –Recurse
I know how to do it with different commands but is there a way to make it so copy-item cmdlet also copies directories to the target folder for example if I wanted to copy everything in the C:\users folder including all directories and sub directories is it possible to do with the copy-item command.
You should be able to do it with:
copy-item C:\users -recurse
copy-item C:\users -destination c:\somewhereelse -recurse
The first way assumes you are currently in the destination folder, the second way is explicit.