We help IT Professionals succeed at work.

Powershell Assistance

55 Views
Last Modified: 2016-05-17
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

Script:

# 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"
            }
        }
    }
}
Comment
Watch Question

Media Hound
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Neil RussellTechnical Development Lead

Commented:
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.
Spike99On-Site IT Technician
CERTIFIED EXPERT

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.