Avatar of robertarenson
robertarenson asked on

Powershell Assistance

I am trying to copy over a file in the root of C:\Citrix\Profiles.v2 to every users profile location but I keep running into errors.  Was hoping that someone might have a better way of making this work.

Thanks again


# Variables
$users= Get-Childitem "c:\users" | Select-Object -Property name

Foreach ($user in $users) {
    #Verify The profiles Directory Exists
    $path = test-path "c:\users\$user\AppData\LocalLow\Sun Java\Test"
    # If $path = True (Implied True in the below statement)
    if ($path) {
        $profiles=Get-ChildItem "c:\users\$user\AppData\LocalLow\Sun Java\Test" | select-object name

         Foreach ($ffprofile in $profiles){
            $ffox = "c:\users\$user\AppData\LocalLow\Sun Java\Test\test.txt"

            #Test the Path
            $path = Test-Path $ffox
            # If $path = True (Implied True in the below statement)
            if ($path) {
                Copy-item "C:\Citrix\Profiles.v2\Sun Java\Test\Test.txt" -Destination "c:\users\$user\AppData\LocalLow\Sun Java\Test\$ffprofile" -Force
                write-host "User: $user"
                Write-host "Profile: $ffprofile"
Windows Server 2008Powershell

Avatar of undefined
Last Comment

8/22/2022 - Mon
James Rankin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Neil Russell

And rather than just saying "I keep getting errors"
Say what the errors are. Show what efforts you have made to debug the errors. Paste a screen shot.

Although, you didn't specify the errors you were seeing, I suspect it's not working because Admins lack rights to the users' profile folders by default, Admins do not normally have access to user profile folders unless you enable this group policy setting BEFORE those folders were created:
Configuration/Policies/Administrative Templates/System/User Profiles
“Add the Administrators security group to the roaming user profile.”

So, if that's the case, it might be better to reconfigure the script to be run by the user & have it run as a logon script for all users so the file can be copied to the user's profile folder using their own creds (they would have full rights to copy files to that  folder in their roaming profile folder).  Just make sure the source file is in a location on the network that they at least have read access to.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck