Not getting the results I'm looking for

Welcome Forums General PowerShell Q&A Not getting the results I'm looking for

This topic contains 6 replies, has 2 voices, and was last updated by

 
Participant
2 months ago.

  • Author
    Posts
  • #114117

    Participant
    Points: 4
    Rank: Member

    Hello,
     

    I'm apologizing in advanced if I provided too much information.
    There have been times where I'll create a script and assign variables to cmdlets . Within some of my scripts I have used the variable to access properties that I select in a custom table.Most of the time I can access the variable through dot notation and the results of the cmdlets will get exported to an excel file with the custom headers.
    For some reason it's not producing the results that I'm looking for .(In my script that I created ,I'm getting the groups listed in the main AD group (Get-ADGroupmember -identity  $item.Group) and I'm getting the groups that are listed in what is called a Centrify zone by means of a powershell cmdlet (Get-CdmGroupProfile -Zone $item.DistinguishedName).

     

    At the end I'm trying to export it to an excel spreadsheet with the Groups from the AD group  as a header (AD Linux Group) and also display the groups that show up in Centrify and display them in a header in Excel (Centrify Group).

    However it seems to be constantly looping through the groups and never stops or takes a really long time.

    I have played around with the following and got it to work somewhat  ,where it would pass the results on ,but it still isn't working  like I was expecting. I would like for it to display the results for both cmdlets (Get-ADgroupmember and Get-cdmgroupprofile) in separate columns . This is for being able to compare the differences ,but for now I would like the groups to display.

    Get-CdmGroupProfile -Zone $item.DistinguishedName |%{
     
    Get-ADGroupmember -identity  $item.Group |
    

     

     

     
    For example – The script below works fine.I used the script below for the one that I'm having issues with.
    I assign the cmdlets to variables and then at the end I select them with the custom table by using what I think is actually dot notation to access the specific properties($zone.UserEnabled,$zonezpa.UserSource,etc) and displaying them in an easy to understand column.

    $list = Import-Csv C:\Users\user\Desktop\dn2.csv
    
    
    $finalzpa = Foreach($item in $list){
    
    $zonezpa = Get-CdmZpaSetting -Zone $item.DistinguishedName
    
    $zoneset = Get-CdmZone -dn $item.DistinguishedName
    
    Get-CdmZone -Dn $item.DistinguishedName | %{
    
    Get-CdmZpaSetting -Zone $item.DistinguishedName |
    
     Select-Object @{Name='Userenabled';Expression={$zonezpa.UserEnabled}},
                       @{Name='Provisioning Groups enabled';Expression={$zonezpa.GroupEnabled}},
                       @{Name='ZoneName' ;Expression={$zoneset.Name}},
                       @{Name='User Source';Expression={$zonezpa.UserSource}},
                       @{Name='Group Source';Expression={$zonezpa.GroupSource}},
                       @{Name='Distinguished Name';Expression={$item.DistinguishedName}}
    
       
     
      
                   
    }}
    
    
    
    $finalzpa | Export-Csv -Append -NoTypeInformation C:\Users\Desktop\zonesautoinfo.csv
    

    To get to the actual issue I'm having. Below is the script that I created. The csv file contains the DN name ,Zone name and Group name.There are only two entries in the file for each row. There is a TEST and PROD group which also just has the dn listed.

    When I run it, the results for the Get-CdmGroupProfile -Zone $item.DistinguishedName cmdlet show for both test and prod groups .

    However the results that I put in the custom table at the end doesn't work like it has in my previous experiences.So the Get-ADGroup $item.Group results don't get captured,

    When I run $adgroup.name , I get all of the groups for the group that is contained within the array,however the name property or any other property that is contained within the variable doesn't automatically popup when putting in the dot that I'm used to getting.

    The same thing happens for $centrifygprofile.I can type in $centrifygprofile.name or Zone and it displays that only.

    I have seen this happen before ,but I have usually been able to get it to work by starting from scratch or removing all the variables and re-creating .

    I'm not sure if this has anything to do with the scope or something else that might be obvious and I'm not seeing  or understanding it.

    If there is more information that is needed let me know.

     
    This is the script that is working partially as in ,when I run it ,it doesn't error out ,but it's not selecting the custom column names and information from for the hash table.
    None of the custom tables don't get outputted to the csv file. I have used this script for other situations where I want to grab certain data and modify the name of the column.
    None of the custom column headers that are listed are being added to the csv file.When I run $adgroup.name or $adgroup.distinguishedname by itself it shows the dn( $adgroup.distinguishedname )and groups ( $adgroup.name)when I use the commands by themselves.
     

    I'm looking for

    @{Name='ZoneName';Expression={$centrifygprofile.Zone}}, 
    @{Name=' Centrify Group';Expression{$centrifygprofile.group}}, 
    @{Name='AD Linux GROUP' ;Expression={$adgroup.name}},
    @{Name='ADDistinguishedName';Expression{$adgroup.distinguishedname}}
    
    $list = Import-Csv C:\Users\user\Desktop\Centrify\PEGA\Inputpega.csv
    
    
    $result = foreach($item in $list) {
    
    $adgroup = Get-ADGroupMember  $item.Group
    $centrifygprofile = Get-CdmGroupProfile -Zone $item.DistinguishedName 
     
    Get-ADGroup $item.Group | %{
    
    Get-CdmGroupProfile -Zone $item.DistinguishedName |Select-Object
    
     
     @{Name='ZoneName';Expression={$centrifygprofile.Zone}}, 
     @{Name=' Centrify Group';Expression={$centrifygprofile.group}}, 
     @{Name='AD Linux GROUP' ;Expression={$adgroup.name}},
     @{Name='AD DistinguishedName';Expression={$adgroup.distinguishedname}}
     
     }}
    
     $result | Export-Csv C:\Users\user\Desktop\Centrify\PEGA\results2.csv -NoTypeInformation
    

    Other information that may be needed –

    $adgroup | gm
    
    
       TypeName: Microsoft.ActiveDirectory.Management.ADPrincipal
    
    Name              MemberType            Definition                                                                                                                         
    ----              ----------            ----------                                                                                                                         
    Contains          Method                bool Contains(string propertyName)                                                                                                 
    Equals            Method                bool Equals(System.Object obj)                                                                                                     
    GetEnumerator     Method                System.Collections.IDictionaryEnumerator GetEnumerator()                                                                           
    GetHashCode       Method                int GetHashCode()                                                                                                                  
    GetType           Method                type GetType()                                                                                                                     
    ToString          Method                string ToString()                                                                                                                  
    Item              ParameterizedProperty Microsoft.ActiveDirectory.Management.ADPropertyValueCollection Item(string propertyName) {get;}                                    
    distinguishedName Property              System.String distinguishedName {get;set;}                                                                                         
    name              Property              System.String name {get;}                                                                                                          
    objectClass       Property              System.String objectClass {get;set;}                                                                                               
    objectGUID        Property              System.Nullable`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] objectGUID {get;set;}
    SamAccountName    Property              System.String SamAccountName {get;set;}                                                                                            
    SID               Property              System.Security.Principal.SecurityIdentifier SID {get;set;}
    $centrifygprofile | gm
    
    
       TypeName: Centrify.DirectControl.PowerShell.Types.CdmGroupProfile
    
    Name                 MemberType Definition                                                                
    ----                 ---------- ----------                                                                
    Equals               Method     bool Equals(System.Object obj)                                            
    GetHashCode          Method     int GetHashCode()                                                         
    GetType              Method     type GetType()                                                            
    ToString             Method     string ToString()                                                         
    CanonicalName        Property   string CanonicalName {get;}                                               
    Computer             Property   Centrify.DirectControl.PowerShell.Types.CdmManagedComputer Computer {get;}
    Domain               Property   string Domain {get;}                                                      
    Gid                  Property   System.Nullable[long] Gid {get;}                                          
    Group                Property   Centrify.DirectControl.PowerShell.Types.CdmGroup Group {get;}             
    IsHierarchical       Property   bool IsHierarchical {get;}                                                
    IsMembershipRequired Property   System.Nullable[bool] IsMembershipRequired {get;}                         
    IsOrphan             Property   bool IsOrphan {get;}                                                      
    IsSfu                Property   bool IsSfu {get;}                                                         
    Name                 Property   string Name {get;}                                                        
    PreferredServer      Property   string PreferredServer {get;}                                             
    Zone                 Property   Centrify.DirectControl.PowerShell.Types.CdmZone Zone {get;}
    
  • #114124

    Participant
    Points: 889
    Helping Hand
    Rank: Major Contributor

    From a random look, Your calculated property should be passed to Select-Object, here the calculated properties are in next line,

    $Properties = @(
     @{Name='ZoneName';Expression={$centrifygprofile.Zone}}, 
     @{Name=' Centrify Group';Expression={$centrifygprofile.group}}, 
     @{Name='AD Linux GROUP' ;Expression={$adgroup.name}},
     @{Name='AD DistinguishedName';Expression={$adgroup.distinguishedname}}
    )
    Get-CDM... | Select-Object -Property $Properties
    
    
    
    		
    	
    • #114136

      Participant
      Points: 4
      Rank: Member

      Thanks kvprasoon for the reply.

       

      Would I put the $Properties with the calculated  property after the Get commands ?

       

      Also I see you put Get-CDM(Get-CDM...|select-Object – property $properties), did you put that because the Get-cdmGroupProfile and  Get-adgroupmember should be executed first and then use the $properties variable to grab the column headers(Centrify Group, AD Group,Zonename,etc ?

      What I'm trying to get is the following(simplified below) below.

      Centrify Group AD Linux Group Zonename

      Group1 Group6 TESTERS
      Group2 Group7 TESTERS
      Group3 Group8 TESTERS ONE

       

      Get-CdmGroupProfile -Zone $item.DistinguishedName |%{
      
      Get-ADGroupmember -identity  $item.Group
      
      
      $Properties = @(
       @{Name='ZoneName';Expression={$centrifygprofile.Zone}}, 
       @{Name=' Centrify Group';Expression={$centrifygprofile.group}}, 
       @{Name='AD DistinguishedName';Expression={$adgroup.distinguishedname}} 
       ) 
      

       

       

       

       

    • #114192

      Participant
      Points: 4
      Rank: Member

      @kvprasoon

      Would I put the calculated properties that you suggested before or after the following below.

      Get-ADGroup $item.Group | %{
      
      Get-CdmGroupProfile -Zone $item.DistinguishedName
      
      

       

      Also you put  the following at the end of the calculated properties. I see you put Get-cdm... | Select-Object – property $properties .

       

      How would I grab or display the calculated properties at the end for both cmdlets .

      Get-CDM... | Select-Object -Property $Properties
      
      

       

       

      Calculated properties –

      $Properties = @(
       @{Name='ZoneName';Expression={$centrifygprofile.Zone}}, 
       @{Name=' Centrify Group';Expression={$centrifygprofile.group}}, 
       @{Name='AD Linux GROUP' ;Expression={$adgroup.name}},
       @{Name='AD DistinguishedName';Expression={$adgroup.distinguishedname}}
      )
      Get-CDM... | Select-Object -Property $Properties
      
      
      
      		
      	
  • #114195

    Participant
    Points: 889
    Helping Hand
    Rank: Major Contributor

    @greg, The correction that I asked you to do is

    $Properties = @(
     @{Name='ZoneName';Expression={$centrifygprofile.Zone}}, 
     @{Name=' Centrify Group';Expression={$centrifygprofile.group}}, 
     @{Name='AD Linux GROUP' ;Expression={$adgroup.name}},
     @{Name='AD DistinguishedName';Expression={$adgroup.distinguishedname}}
    )
    Get-CdmGroupProfile -Zone $item.DistinguishedName | Select-Object -Property $Properties
    
  • #114285

    Participant
    Points: 4
    Rank: Member

    @kvprasoon

    When I make the correction ,the script just keeps running. I didn't test for how long. So far I timed it at being 17 minutes ,I think it's because it is in a constant loop or maybe a long loop where it has 189 to 191 groups that are part of the groups and I think it is enumerating through each.

    However I removed the foreach loop from being assigned to the variable ($result) and removed the foreach variable from being piped to the Excel.

     

    I then ran the script to see what it was doing and it was showing the results below.

    I've seen this before,but can't recall why this happens.I thought this is mainly because of it being an array and iterating through the groups,however I think there probably is a more efficient and faster way to accomplish what I'm looking for.

     

    I'm just trying to combine the results of Get-cdmGroupProfile and Get-adgroupmember  and display the groups for the group profile from the Get-cdmGroupProfile and the groups from Get-adgroupmember in an excel spreadsheet.

    When looking at the properties of Get-cdmGroupProfile it looks like it accepts piped input ,but Get-Adgroupmember does.

     

     

    Results from making the change for the calculated properties –

    ZoneName             : {OU=TEST ZONE ,OU=TEST Zone One,OU=Zones,OU=TEST,DC=TEST,DC=com,OU=PROD ZONE,OU=PROD Zone One,OU=Zones,OU=PROD,DC=PROD,DC=com,
    OU=PROD ZONE,OU=PROD Zone One,OU=Zones,OU=PROD,DC=PROD,DC=com,OU=Unix,DC=PRODk,DC=com, OU=PROD ZONE,OU=PROD Zone One,OU=Zones,OU=PROD,DC=PROD,DC=com...}
     Centrify Group      : {group1@prod.com, group2@prod.com, group3@prod.com, group4@prod.com...}
    AD DistinguishedName : CN=SA-ZONE-PROD_GROUPS,OU=Zones,OU=PROD,OU=PROD,OU=PROD,DC=PROD,DC=com
    AD Linux Group       : {group6, group7, group8, group9...}
    
    
  • #114468

    Participant
    Points: 4
    Rank: Member

    @kvprasoon

    Did you get a chance to look over my last post ? Also is there another place I can post to get more answers. I know everyone volunteers here and didn't want to rely solely on you as you may be working on other items.

     

     

    Thanks,

     

     

     

You must be logged in to reply to this topic.