Domanda

I'm trying to copy some folders and files from the user profile (desktop and favorites) to a specific folder on the user homedrive. Since the user profile and home drive can be different i don't want this to be a hard path.

I've tried to get this working with robocopy under powershell, but i keep struggling with user profile and home drive path.

$arSourceFolders = ("%userprofile%\Favorites", "%userprofile%\Desktop");
$arDestinationFolders = ("%homedrive%\Backup\Favorites", "%homedrive%\Backup\Desktop");

if($arSourceFolders.Length -ne $arDestinationFolders.Length)
{

}
else{
    for($i=0; $i -lt $arSourceFolders.Length; $i++)
    {
        robocopy $arSourceFolders[$i] $arDestinationFolders[$i] /COPYALL /E /R:0 /xo
    }
}

It's not working with %userprofile% and %homedrive%. Because the scripts goes to C:\%userprofile%\Desktop. Is there a way to set these paths?

È stato utile?

Soluzione

Use environment variable for user profile and home drive like $env:userprofile, $env:homedrive. It will work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top