Copy Files to C-Drive (Admin rights)

Hello,

I created a Profile-Cleaner with different functions for the user in our company.
One of the function is to Copy Files from a folder ($sourcePath) to the C-Drive ($desinationPath)

The script works only, if you run it as admin. But 99% of the users can’t run this as admin since they don’t have permissions for that.

Do any of you know of a workaround to achieve this without having to enter my credentials in the script?

Below you can find the function, that needs to be modified.

function Copy-NetworkFoldersToC {

    $sourcePath = '\\XYZ\ProfileCleaner\CopyToCdrive\*'  #In here are the files and folder to copy
    $destinationPath = 'C:\'  
   
    if (Test-Path -Path $sourcePath -PathType Container) {
        Copy-Item -Path $sourcePath -Destination $destinationPath -Recurse -Force
    } 
}

Folders to copy go to ProgramData and Users\Public

Running it as a scheduled task would likely be the best solution.

Thanks for the fast reply.

This tool should only be running, when the applications of a user is not running well. Therefore he will run this “profile-cleaner” to delete corrupted files and copy back the the original ones…

Do you have some sort of app catalog like MECM (SCCM) you could deploy that way and it would be able to run privileged without credentials

Access is typically denied to the root folder of C:. Try creating a subfolder first and copy to there.

I’m with Tony.

Why should a user have write access to C:\? Users should only have write access to their profiles. :point_up:t3: :man_shrugging:t3: