So I've been trying to make a script that copies all the files from a users "Documents", "Photos"-folders and so on to a single folder on another drive. But the script keeps saying:
Copy-Item : Cannot find drive. A drive with the name 'c' does not exist.
At C:\Users\sebbe\Downloads\Untitled1.ps1:23 char:1
+ Copy-Item -Path "c:\Users\$user\Desktop\*" -Destination D:\mapp1\$us ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (c:String) [Copy-Item], DriveNotFoundExcept
ion
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
I am running the script via Power Shell ISE as administrator, and I have tried the script on two different PCs, with the same failure.
Why can't the script find the C: disk?
Here is the whole script:
$User = Read-Host "New Username"
Function makeDir {
New-Item -Path D:\mapp1 -Name "$User" -ItemType Directory
}
Function copyDesktop {
Copy-Item -Path "C:\Users\$User\Desktop" -Destination "D:\mapp1\$User\Desktop" -Recurse
}
Function copyDocuments {
Copy-Item -Path "C:\Users\$User\Documents" -Destination "D:\mapp1\$User\Documents" -Recurse
}
Function copyPictures {
Copy-Item -Path "C:\Users\$User\Pictures" -Destination "D:\mapp1\$User\Pictures" -Recurse
}
makeDir
copyDocuments
copyPictures
copyDesktop
I've made it work, somehow.
This is how the code looks like now:
$User = Read-Host "New Username"
Function makeDir {
New-Item -Path D:\mapp1 -Name "$User" -ItemType Directory
}
Function copyDesktop {
Copy-Item -Path "C:\Users\$User\Desktop" -Destination "D:\mapp1\$User\Desktop" -Recurse
}
Function copyDocuments {
Copy-Item -Path "C:\Users\$User\Documents" -Destination "D:\mapp1\$User\Documents" -Recurse
}
Function copyPictures {
Copy-Item -Path "C:\Users\$User\Pictures" -Destination "D:\mapp1\$User\Pictures" -Recurse
}
makeDir
copyDocuments
copyPictures
copyDesktop
A big thanks to Shawn Esterman, and everyone else of course! :)