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.t xt'
$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 .Managemen t.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 ??
At the moment I have the following :
# Use SAM account and take ownership of user folder
$ADUser = Get-Content 'C:\Temp\SecTest\AdUsers.t
$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
method is not supported.
I am new to Powershell, but I think I may need to convert this to a string ??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is working solution
# Use SAM account and take ownership of user folder
$ADUsers = Get-Content 'C:\Temp\SecTest\AdUsers.t
#$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
}