Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Powershell Script - change folder owner based on username from a csv file

$
0
0

Hi

I've got a Powershell script which allows me to change the owner of a users home drive from it's current owner (administrators) to the user, but it only allows me to do one user at a time.
I've exported a list of users whose owner is set to administrators and put the information into a csv file. What I want to do is modify my existing script to import the csv file, and change the owner of these users home folders from administrators to the user.

Please note the folder name of the users home folder, matches the ad account name. And the csv file has the following headings: 
Share: (lists the users home folder path = \\servername\$share\userfolders\userhomefolder1, 2, 3 etc
Name: (Ad acccount name)
Owner: Builtin\Administrators

Here is my existing script which works on a per user basis:

function pathPrompt {

$tempPath = $null
$tempPath = Read-Host "\\servername\$share\userfolders\userfolder"
return $tempPath
}

$username=$Username
$domain=”domain”
$ID = new-object System.Security.Principal.NTAccount($domain, $username)

$path = "\\servername\$share\userfolders\userfolder"

write-host $path

$acl = get-acl $path
$acl.SetOwner($ID)
set-acl -path $path -aclObject $acl

Any help would be most appreciative. I've got about 1000 of these to do :)

 

Cheers Ben


Viewing all articles
Browse latest Browse all 6937

Trending Articles