Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Active Directory

Reply
 
Old 12-12-2006   #1 (permalink)
Lothar


 
 

Active Directory

Hello!
I have 2 Questions:
1:
How can i get the distinguished Name of the logged on User in a variable? I
need this for our new LogonScript which will be written in Powershell.

2:
How can i get all groupmemberships of a User, including nested Groups?
If it is possible, i don't want to use the tool "ifmember.exe".


Thanks for your help!

Lothar


My System SpecsSystem Spec
Old 12-12-2006   #2 (permalink)
jorgemestre@gmail.com


 
 

Re: Active Directory

Question 1.

$root = [ADSI]"LDAP://dc=es,dc=gasnatural,dc=com"
$userWMI = Get-WmiObject win32_ComputerSystem
$user = $userWMI.UserName
$user = $user.split("\")[1] #in case you have a domain logon, just get
the name
$searchAD = new-object DirectoryServices.DirectorySearcher($root)
$searchAD.PageSize = 10000
$searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
$searchResult = $($searchAD.FindAll()).getDirectoryEntry()
$userDN = $searchResult.distinguishedName

On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> Hello!
> I have 2 Questions:
> 1:
> How can i get the distinguished Name of the logged on User in a variable? I
> need this for our new LogonScript which will be written in Powershell.
>
> 2:
> How can i get all groupmemberships of a User, including nested Groups?
> If it is possible, i don't want to use the tool "ifmember.exe".
>
> Thanks for your help!
>
> Lothar


My System SpecsSystem Spec
Old 12-12-2006   #3 (permalink)
jorgemestre@gmail.com


 
 

Re: Active Directory

Question 1.

$root = [ADSI]"LDAP://dc=my,dc=company,dc=com"
$userWMI = Get-WmiObject win32_ComputerSystem
$user = $userWMI.UserName
$user = $user.split("\")[1] #in case you have a domain logon, just get
the name
$searchAD = new-object DirectoryServices.DirectorySearcher($root)
$searchAD.PageSize = 10000
$searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
$searchResult = $($searchAD.FindAll()).getDirectoryEntry()
$userDN = $searchResult.distinguishedName

On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> Hello!
> I have 2 Questions:
> 1:
> How can i get the distinguished Name of the logged on User in a variable? I
> need this for our new LogonScript which will be written in Powershell.
>
> 2:
> How can i get all groupmemberships of a User, including nested Groups?
> If it is possible, i don't want to use the tool "ifmember.exe".
>
> Thanks for your help!
>
> Lothar


My System SpecsSystem Spec
Old 12-12-2006   #4 (permalink)
Lothar


 
 

Re: Active Directory

Thank You very much!

it works fine.


Lothar

"jorgemestre@gmail.com" wrote:

> Question 1.
>
> $root = [ADSI]"LDAP://dc=my,dc=company,dc=com"
> $userWMI = Get-WmiObject win32_ComputerSystem
> $user = $userWMI.UserName
> $user = $user.split("\")[1] #in case you have a domain logon, just get
> the name
> $searchAD = new-object DirectoryServices.DirectorySearcher($root)
> $searchAD.PageSize = 10000
> $searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
> $searchResult = $($searchAD.FindAll()).getDirectoryEntry()
> $userDN = $searchResult.distinguishedName
>
> On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> > Hello!
> > I have 2 Questions:
> > 1:
> > How can i get the distinguished Name of the logged on User in a variable? I
> > need this for our new LogonScript which will be written in Powershell.
> >
> > 2:
> > How can i get all groupmemberships of a User, including nested Groups?
> > If it is possible, i don't want to use the tool "ifmember.exe".
> >
> > Thanks for your help!
> >
> > Lothar

>
>

My System SpecsSystem Spec
Old 12-12-2006   #5 (permalink)
ydroam


 
 

Re: Active Directory

$user = $user.split("\")[-1]

jorgemestre@gmail.com wrote:
> Question 1.
>
> $root = [ADSI]"LDAP://dc=my,dc=company,dc=com"
> $userWMI = Get-WmiObject win32_ComputerSystem
> $user = $userWMI.UserName
> $user = $user.split("\")[1] #in case you have a domain logon, just get
> the name
> $searchAD = new-object DirectoryServices.DirectorySearcher($root)
> $searchAD.PageSize = 10000
> $searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
> $searchResult = $($searchAD.FindAll()).getDirectoryEntry()
> $userDN = $searchResult.distinguishedName
>
> On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> > Hello!
> > I have 2 Questions:
> > 1:
> > How can i get the distinguished Name of the logged on User in a variable? I
> > need this for our new LogonScript which will be written in Powershell.
> >
> > 2:
> > How can i get all groupmemberships of a User, including nested Groups?
> > If it is possible, i don't want to use the tool "ifmember.exe".
> >
> > Thanks for your help!
> >
> > Lothar


My System SpecsSystem Spec
Old 12-13-2006   #6 (permalink)
jorgemestre@gmail.com


 
 

Re: Active Directory

Hello!

Why -1?

DOMAIN\User
[0] \ [1]

isn't it?

On 12 dic, 23:31, "ydroam" <ydr...@gmail.com> wrote:
> $user = $user.split("\")[-1]
>
> jorgemes...@gmail.com wrote:
> > Question 1.

>
> > $root = [ADSI]"LDAP://dc=my,dc=company,dc=com"
> > $userWMI = Get-WmiObject win32_ComputerSystem
> > $user = $userWMI.UserName
> > $user = $user.split("\")[1] #in case you have a domain logon, just get
> > the name
> > $searchAD = new-object DirectoryServices.DirectorySearcher($root)
> > $searchAD.PageSize = 10000
> > $searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
> > $searchResult = $($searchAD.FindAll()).getDirectoryEntry()
> > $userDN = $searchResult.distinguishedName

>
> > On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> > > Hello!
> > > I have 2 Questions:
> > > 1:
> > > How can i get the distinguished Name of the logged on User in a variable? I
> > > need this for our new LogonScript which will be written in Powershell.

>
> > > 2:
> > > How can i get all groupmemberships of a User, including nested Groups?
> > > If it is possible, i don't want to use the tool "ifmember.exe".

>
> > > Thanks for your help!

>
> > > Lothar


My System SpecsSystem Spec
Old 12-13-2006   #7 (permalink)
ydroam


 
 

Re: Active Directory

"#in case you have a domain logon, just get the name"
#in case you don't have a domain logon, just get the name

If there is no \ in $user, split("\")[1] should give you nothing.
The -1 should give you the last array element which should be the user
name whether there is a "\" or not.


jorgemestre@gmail.com wrote:
> Hello!
>
> Why -1?
>
> DOMAIN\User
> [0] \ [1]
>
> isn't it?
>
> On 12 dic, 23:31, "ydroam" <ydr...@gmail.com> wrote:
> > $user = $user.split("\")[-1]
> >
> > jorgemes...@gmail.com wrote:
> > > Question 1.

> >
> > > $root = [ADSI]"LDAP://dc=my,dc=company,dc=com"
> > > $userWMI = Get-WmiObject win32_ComputerSystem
> > > $user = $userWMI.UserName
> > > $user = $user.split("\")[1] #in case you have a domain logon, just get
> > > the name
> > > $searchAD = new-object DirectoryServices.DirectorySearcher($root)
> > > $searchAD.PageSize = 10000
> > > $searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
> > > $searchResult = $($searchAD.FindAll()).getDirectoryEntry()
> > > $userDN = $searchResult.distinguishedName

> >
> > > On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> > > > Hello!
> > > > I have 2 Questions:
> > > > 1:
> > > > How can i get the distinguished Name of the logged on User in a variable? I
> > > > need this for our new LogonScript which will be written in Powershell.

> >
> > > > 2:
> > > > How can i get all groupmemberships of a User, including nested Groups?
> > > > If it is possible, i don't want to use the tool "ifmember.exe".

> >
> > > > Thanks for your help!

> >
> > > > Lothar


My System SpecsSystem Spec
Old 12-14-2006   #8 (permalink)
jorgemestre@gmail.com


 
 

Re: Active Directory

oh, great!
I didn't knew that, thanks!

ydroam ha escrito:

> "#in case you have a domain logon, just get the name"
> #in case you don't have a domain logon, just get the name
>
> If there is no \ in $user, split("\")[1] should give you nothing.
> The -1 should give you the last array element which should be the user
> name whether there is a "\" or not.
>
>
> jorgemestre@gmail.com wrote:
> > Hello!
> >
> > Why -1?
> >
> > DOMAIN\User
> > [0] \ [1]
> >
> > isn't it?
> >
> > On 12 dic, 23:31, "ydroam" <ydr...@gmail.com> wrote:
> > > $user = $user.split("\")[-1]
> > >
> > > jorgemes...@gmail.com wrote:
> > > > Question 1.
> > >
> > > > $root = [ADSI]"LDAP://dc=my,dc=company,dc=com"
> > > > $userWMI = Get-WmiObject win32_ComputerSystem
> > > > $user = $userWMI.UserName
> > > > $user = $user.split("\")[1] #in case you have a domain logon, just get
> > > > the name
> > > > $searchAD = new-object DirectoryServices.DirectorySearcher($root)
> > > > $searchAD.PageSize = 10000
> > > > $searchAD.Filter = "(`&(objectClass=user)(sAMAccountName=$($user)))"
> > > > $searchResult = $($searchAD.FindAll()).getDirectoryEntry()
> > > > $userDN = $searchResult.distinguishedName
> > >
> > > > On Dec 12, 10:30 am, Lothar <Lot...@discussions.microsoft.com> wrote:
> > > > > Hello!
> > > > > I have 2 Questions:
> > > > > 1:
> > > > > How can i get the distinguished Name of the logged on User in a variable? I
> > > > > need this for our new LogonScript which will be written in Powershell.
> > >
> > > > > 2:
> > > > > How can i get all groupmemberships of a User, including nested Groups?
> > > > > If it is possible, i don't want to use the tool "ifmember.exe".
> > >
> > > > > Thanks for your help!
> > >
> > > > > Lothar


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
active directory PowerShell
Active Directory Vista mail
Active Directory Vista General
Active Directory Vista networking & sharing
active directory PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46