Get AD User Account Details

Anyone,

I am trying to retrieve the SID details of a user account and assign it to be a folder owner :

$NewFTPUser = "Tom"
$FTPPath = "\\dc03\c$\temp\DC01\" + $NewFTPUser

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


So, above we have a new user called 'Tom'. I am then trying to retrieve the SID, which is successful but I then get the following error message :

Set-Owner : Cannot bind parameter 'Account'. Cannot convert the "@{SID=S-1-5-21-1837162294-2467702149-2407636943-1159}" value of type
"Selected.Microsoft.ActiveDirectory.Management.ADUser" to type "Security2.IdentityReference2".
At C:\Temp\SFTP\SFTPUserAccount.ps1:27 char:40
+ get-item $FTPPath | set-owner -account $User

The 'Set-owner' is used from an imported module to change the ACL of a folder, supplied by Microsoft.
CaussyRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CaussyRAuthor Commented:
Just tried :

$FTPPath = "\\dc03\c$\temp\DC01\" + $NewFTPUser
$User = Get-ADUser $NewFTPUser | Select SAMAccountName
get-item $FTPPath | set-owner -account $User

The selects the SAMAccountName but I now get the following error :

Set-Owner : Cannot bind parameter 'Account'. Cannot convert the "@{SAMAccountName=SFTPJones}" value of type
"Selected.Microsoft.ActiveDirectory.Management.ADUser" to type "Security2.IdentityReference2".
At line:2 char:40
+ get-item $FTPPath | set-owner -account $User
0
Vasil Michev (MVP)Commented:
Not sure what the set-owner cmdlet is, but you are not passing the correct format. Try $user.sid.value
0
CaussyRAuthor Commented:
Thanks for your reply.

The 'Set-owner' command comes from the new imported module for ACL control. See the following article : http://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85

All I want to do is to retrieve the AD user account and make the data retrieved the owner of the folder.

What I am not doing as you correctly mentioned, is not passing the right content to the variable.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

CaussyRAuthor Commented:
So I tried what you suggested as follows :

$FTPPath = "\\dc03\c$\temp\DC01\" + $NewFTPUser
$User = Get-ADUser $NewFTPUser | Select SAMAccountName
get-item $FTPPath | set-owner -account $User.SAMAccountName

But I get the following error :

Cannot bind parameter 'Account'. Cannot convert value "TomJones" to type "Security2.IdentityReference2". Error: "The is neither a SID nor
a valid account name (domain\username)"
0
CaussyRAuthor Commented:
RESOLVED :

All I had to do was use $USer.SID and this resolved my issue....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CaussyRAuthor Commented:
After a few tests and different variants of the variable, $User.SID resolved the issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.