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
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\Lo calLow\Sun Java\Test"
# If $path = True (Implied True in the below statement)
if ($path) {
$profiles=Get-ChildItem "c:\users\$user\AppData\Lo calLow\Sun Java\Test" | select-object name
Foreach ($ffprofile in $profiles){
$ffox = "c:\users\$user\AppData\Lo calLow\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\Lo calLow\Sun Java\Test\$ffprofile" -Force
write-host "User: $user"
Write-host "Profile: $ffprofile"
}
}
}
}
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\Lo
# If $path = True (Implied True in the below statement)
if ($path) {
$profiles=Get-ChildItem "c:\users\$user\AppData\Lo
Foreach ($ffprofile in $profiles){
$ffox = "c:\users\$user\AppData\Lo
#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
write-host "User: $user"
Write-host "Profile: $ffprofile"
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/Adm inistrativ e 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.
Configuration/Policies/Adm
“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.
Say what the errors are. Show what efforts you have made to debug the errors. Paste a screen shot.