Vidya B
Vidya B

Reputation: 1

powershell scripts for querying Active Directory

Am new to Powershell, I wanted to get the properties of the particular User, but am not able to view any result/ either error or Pass. is there any option that needs to be configured. attached to the screenshot pls help me here.

This is my code.

#Get all Ad Users
import-module ActiveDirectory
$users =Get-ADUser -Filter * -SearchBase "OU=SYDNEY,OU=RGMissions,OU=SIGNET,DC=authserver,DC=com"
$sourceUser = Get-ADUser -Identity VB -Properties MemberOf 

$sourceGroups = $sourceUser.MemberOf
[DBG]: PS C:\Users\echmsad>> $sourceUser.MemberOf

[DBG]: PS C:\Users\echmsad>> 

Upvotes: 0

Views: 415

Answers (1)

WaitingForGuacamole
WaitingForGuacamole

Reputation: 4301

Your question is a little confusing, as the text says you want the properties of a single user, but the code comment says you want to get all users. I'll skip that second part and focus on the fact that you want to get the groups that a particular user belongs to - try this command instead if you know the user's identity:

Get-ADPrincipalGroupMembership -Identity VB

If VB is the Identity as it exists in Active Directory, and to Mathias' point - if VB exists in any groups, you should get a result.

Another thing to check is that VB is actually the correct identity:

Get-ADUser -Identity VB

If that doesn't return anything, then VB doesn't match any user's SamAccountName.

Upvotes: 1

Related Questions