Solved

Powershell converting noteproperty curly brace member

Posted on 2016-09-21
4
60 Views
Last Modified: 2016-09-21
Hello EE,

I am creating a script to pull some active directory information as an html report for compliance reasons . I have one line of code that I have been struggling with .

[array]$ClientUserRoles = get-qaduser -SizeLimit 50000 |where { $_.accountisdisabled -match "False" -and $_.ParentContainer  -match "domain.ca/ClientAccts"  } | select memberof,name |sort memberof 

Open in new window


The issue is the "memberof" member is a curly bracket noteproperty , so when I convert this to html it reads "System.String[]" . So how would I get only the "CN=" values as a string?

ypeName: Selected.Quest.ActiveRoles.ArsPowerShellSnapIn.Data.ArsUserObject

Name        MemberType   Definition                              
----        ----------   ----------                              
Equals      Method       bool Equals(System.Object obj)          
GetHashCode Method       int GetHashCode()                       
GetType     Method       type GetType()                          
ToString    Method       string ToString()                       
MemberOf    NoteProperty System.String[] MemberOf=System.String[]
Name        NoteProperty System.String Name=Foglight             

Open in new window


MemberOf : {CN=ErnestAD,OU=Ernest,OU=ClientAccts,DC=domain,DC=ca, CN=ErnestGGTrain,OU=Ernest,OU=ClientAccts,DC=domain,DC=ca, 
           CN=ErnestGGProd,OU=Ernest,OU=ClientAccts,DC=domain,DC=ca, CN=ErnestGlobal,OU=Ernest,OU=ClientAccts,DC=domain,DC=ca}
Name     : ernest40

Open in new window

0
Comment
Question by:davesnb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 41808777
Use..
[array]$ClientUserRoles = get-qaduser -SizeLimit 50000 |where { $_.accountisdisabled -match "False" -and $_.ParentContainer  -match "domain.ca/ClientAccts"  } | select {$_.memberof},name |sort $_.memberof

Open in new window

Or
[array]$ClientUserRoles = get-qaduser -SizeLimit 50000 |where { $_.accountisdisabled -match "False" -and $_.ParentContainer  -match "domain.ca/ClientAccts"  } | select @{N="memberof";E={$_.memberof}},name |sort memberof 

Open in new window

0
 

Author Comment

by:davesnb
ID: 41808851
Ok the second block of code works but , how do I only select the " CN=" ? Ie ,  I only wish to gather the container ( group designation) ?

[array]$ClientUserRoles = get-qaduser -SizeLimit 500 |where { $_.accountisdisabled -match "False" -and $_.ParentContainer  -match "intelisys.ca/ClientAccts"  } | select @{N="memberof";E={$_.memberof}},name |sort memberof 
$ClientUserRoles = $ClientUserRoles | somestuff here to gather only the groups info

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41809098
Both should work..

To get only group names from DN,

Change..
Select @{N="memberof";E={$_.memberof}},name

Open in new window

to
Select @{N="memberof";E={($_.memberof | %{$_ -replace "(CN=)(.*?),.*",'$2'}) -join " , "}},name

Open in new window

0
 

Author Closing Comment

by:davesnb
ID: 41809155
U da man Subsan ..U da man!
0

Featured Post

Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question