Link to home
Start Free TrialLog in
Avatar of CaussyR
CaussyR

asked on

Folder Ownership

I am trying to match the SAM account name with the users home folder. Some home folders are not owned by the user.  Therefore I am extracting the SAM ID and trying to match the SAM ID to the folder name and give the user Ownership permissions .

At the moment I have the following :

# Use SAM account and take ownership of user folder

$ADUser = Get-Content 'C:\Temp\SecTest\AdUsers.txt'

$HomeFolders = Get-ChildItem 'C:\temp\SecTest' | Where-Object { $_.PSIsContainer -eq $true }

foreach ($HomeFolder in $Homefolders)

{

    $User = Get-ADUser $ADUser | Select SID
    get-item $ADUser | set-owner -account $User.SID

}

When I run the above I get the following error :

 Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by parameter 'Identity'. Specified
method is not supported.

I am new to Powershell, but I think I may need to convert this to a string ??
Avatar of prashanthd
prashanthd
Flag of India image

Try the following

# Use SAM account and take ownership of user folder

$ADUsers = Get-Content 'C:\Temp\SecTest\AdUsers.txt'

#$HomeFolders = Get-ChildItem 'C:\temp\SecTest' | Where-Object { $_.PSIsContainer -eq $true }
foreach ($aduser in $adusers)
{
    $User = Get-ADUser $ADUser | Select SID
    get-item $ADUser | set-owner -account $User.SID
}
ASKER CERTIFIED SOLUTION
Avatar of CaussyR
CaussyR

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CaussyR
CaussyR

ASKER

This is working solution